-->
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.  [ 2 posts ] 
Author Message
 Post subject: Filter the lucene result list by a set of values documentid?
PostPosted: Fri Sep 12, 2014 10:43 pm 
Newbie

Joined: Fri Sep 12, 2014 10:20 pm
Posts: 2
I am new to both lucene and hibernate search. I have managed to make hibernate search working in my project.

I have managed to index such a entity:
Code:
@Indexed
@Entity
@Table(name = "tb_product")
public class Product  {

        private long id;
   @Id
   @DocumentId
   public Long getId() {
      return id;
   }
       ...
}


Now I have a new requirement: a fulltext search should be happen on products within a specified set of ids(these ids are fetched by somewhere else).

Because the the query result need to be paginated, I wouldn't like to run the full query and filter out the result one by one. Now I am trying to build a Filter to let the query itself to do the filtering , but I failed build a DocIdSet corresponding to the product id because I don't know how to accept the documentid in query. Could anyone give some hint on how to access the product id in a lucene query? Or give the right direction of implement this?


Top
 Profile  
 
 Post subject: Re: Filter the lucene result list by a set of values documentid?
PostPosted: Sat Sep 20, 2014 1:28 pm 
Newbie

Joined: Fri Sep 12, 2014 10:20 pm
Posts: 2
I have manged to build a filter (see code block below) and it works, but seems that is not what I want: to build the filter I have to go through all docs to decide whether the doc's id in the provided list, that is much slower than filter after the result list is available.

Code:
fullTextQuery.setFilter(new Filter() {

    @Override
    public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
    Term term = new Term("isMarketable", "true");
    TermDocs td = reader.termDocs(term);
    OpenBitSet bs = new OpenBitSet();
    while (td.next()) {
        if (prodIds2.contains(Long.valueOf(reader.document(td.doc()).getField("id").stringValue()))) {
            bs.set(td.doc());
        }
    }
    return bs;
    }
});


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.