-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: topdocs in hibernate search
PostPosted: Thu Oct 20, 2011 1:02 pm 
Newbie

Joined: Thu Feb 03, 2011 4:09 pm
Posts: 8
Can anyone tell me how to access topdocs using Hibernate Search?

I really just want to be able to take the top docs and scores before Hibernate retrieves the documents. That way I can run them through an additional algorithm to determine what docs to load.

Thanks,
Mason


Top
 Profile  
 
 Post subject: Re: topdocs in hibernate search
PostPosted: Fri Oct 21, 2011 5:24 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

what exactly do you want to achieve? Once the search is executed there is no way to change which documents/entities get loaded. What's about using a Filter?

FYI, the TopDocs are getting calculated in the org.hibernate.search.query.engine.impl.QueryHits. To do what you want we would need to make it possible for users to plug in a custom TopDocs collector. Would that help you?

--Hardy


Top
 Profile  
 
 Post subject: Re: topdocs in hibernate search
PostPosted: Fri Oct 21, 2011 12:56 pm 
Newbie

Joined: Thu Feb 03, 2011 4:09 pm
Posts: 8
Hardy, thanks for your help with this.

Here is a better explanation of what I would like to do, on a slightly silly example. Let's say I want to search, adding randomness to the results. For this I might want to have a formula that multiplies the document score by a random number from 0 to 1, then returns the top 10 documents. (Randomness would not be my actual criteria, but a more complex algorithm that takes user history into account to prioritize the results)

I have used filters with OpenBitMaps, but that only ends up filtering out unwanted docs based on binary results.

Lucene In Action has a very similar type problem of returning near by results geographically (6.1.3 Accessing values used in custom sorting). This however uses TopFieldDocs, a subclass of TopDocs.

Thanks,
Mason


Top
 Profile  
 
 Post subject: Re: topdocs in hibernate search
PostPosted: Tue Oct 25, 2011 12:11 pm 
Newbie

Joined: Thu Feb 03, 2011 4:09 pm
Posts: 8
Hardy, did my description make any sense to you?

Thanks,
Mason


Top
 Profile  
 
 Post subject: Re: topdocs in hibernate search
PostPosted: Tue Oct 25, 2011 12:58 pm 
Newbie

Joined: Thu Feb 03, 2011 4:09 pm
Posts: 8
I just tried a simple filter, with the following code:

Code:
public class RandomizeOrderFilter extends Filter{

   private static final long serialVersionUID = 1L;

   @Override
   public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
      TermDocs termDocs = reader.termDocs(null);
      Random random = new Random();
      while (termDocs.next()) {
         reader.document(termDocs.doc()).setBoost(random.nextFloat());
      }
      
      OpenBitSet bitSet = new OpenBitSet( reader.maxDoc() );
      bitSet.flip(0, reader.maxDoc());
      return bitSet;
   }

}


it iterated over all documents, not just the ones I am searching for. Also, changing the Boost at filter time doesn't seem to have any effect on the order of results returned by Hibernate Search/Lucene.

Any other thoughts on how this can be done in Hibernate Search?

Thanks,
Mason


Top
 Profile  
 
 Post subject: Re: topdocs in hibernate search
PostPosted: Tue Oct 25, 2011 1:36 pm 
Newbie

Joined: Thu Feb 03, 2011 4:09 pm
Posts: 8
I think I found a way to do this. http://stackoverflow.com/questions/8179 ... g-function

Using a FieldComparator seems to work just fine!

Thanks,
Mason


Top
 Profile  
 
 Post subject: Re: topdocs in hibernate search
PostPosted: Thu Oct 27, 2011 4:07 pm 
Newbie

Joined: Thu Feb 03, 2011 4:09 pm
Posts: 8
hardy.ferentschik wrote:
Hi,

what exactly do you want to achieve? Once the search is executed there is no way to change which documents/entities get loaded. What's about using a Filter?

FYI, the TopDocs are getting calculated in the org.hibernate.search.query.engine.impl.QueryHits. To do what you want we would need to make it possible for users to plug in a custom TopDocs collector. Would that help you?

--Hardy

Hardy...I've realized that using a FieldComparator doesn't give me access to the scores. I can override public void setScorer(Scorer scorer), and add "scorer.score(topScoreDocCollector);", but then only 1 result is ever returned.

Is there any known way to insert a functioning custom ScoreDocs or TopDocs collector?

Also, I've been looking through org.hibernate.search.query.engine.impl.QueryHits, but I cannot figure out what code initializes it, or how to access or override it.

Please help!
Thank you,
Mason


Top
 Profile  
 
 Post subject: Re: topdocs in hibernate search
PostPosted: Sun Jul 08, 2012 11:46 am 
Newbie

Joined: Sun Jul 08, 2012 11:36 am
Posts: 1
hardy.ferentschik wrote:
Hi,

what exactly do you want to achieve? Once the search is executed there is no way to change which documents/entities get loaded. What's about using a Filter?

FYI, the TopDocs are getting calculated in the org.hibernate.search.query.engine.impl.QueryHits. To do what you want we would need to make it possible for users to plug in a custom TopDocs collector. Would that help you?

--Hardy


Hi Hardy,
Is there any plan to support pluggable custom collector in Hibernate Search? Is there a plan to support lucene grouping in Hibernate Search? I have a use case which would be a lot easier to handle if Hibernate Search supports grouping.

Scenario:
I have a relational database which holds my products info. However, for each product, there are more than one version available. When user search my database, I want to:
1) for each product, the total hit count only counts on regardless how many version it has -- the hit count is the # of top groups;
2) display only one version for each product;
3) display how many versions are available for each product;
2) apply additional algorithm select a version for each product (among all different versions). The algorithm could be user's preset preferences (such as color, size), the creation of each version, etc.

Could you advise a practical solution with the current hibernate search? thanks a lot.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.