-->
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.  [ 4 posts ] 
Author Message
 Post subject: full-text search on only a subset of entities
PostPosted: Thu Oct 09, 2014 12:34 pm 
Beginner
Beginner

Joined: Mon Nov 29, 2004 11:51 am
Posts: 31
Hi, I'm using Hibernate Search 4.5.

First.. I'm new to this and setup has been a snap. I'm just having some difficulty moving beyond a simple search. I've searched and found people asking similar questions, but I can't quite get there.

Let's say I'm searching Car entities and each Car has a "type" association (@ManyToOne). The possible types are Van, Sedan, Truck, SUV, etc. Now let's say I want to do a text search on ONLY trucks and sedans. I want to do this by using the truck and sedan entity IDs.

I have no problem filtering on a single type ID as follows....

Code:
   org.apache.lucene.search.Query query1 = qb
        .keyword()   
        .fuzzy()
        .onFields("description")
        .matching(searchString)
        .createQuery()
        ;

      org.apache.lucene.search.Query query2= qb
                           .keyword()
             .onField("type.id")
             .matching("100")
             .createQuery();

      org.apache.lucene.search.Query finalQuery = qb
             .bool()
               .should( query1 )
               .must( query2 )
             .createQuery();


But how can I filter on multiple type IDs? This part cannot be fuzzy. This result MUST include only the requested types. Pseudo code illustrating what I would like to do below...

Code:
      org.apache.lucene.search.Query query2= qb
                           .keyword()
             .onField("type.id")
             .matching("100").or("200").or("300")
             .createQuery();


Any ideas? Thanks!


Top
 Profile  
 
 Post subject: Re: full-text search on only a subset of entities
PostPosted: Wed Oct 15, 2014 1:42 pm 
Beginner
Beginner

Joined: Mon Nov 29, 2004 11:51 am
Posts: 31
Is there anyone here?


Top
 Profile  
 
 Post subject: Re: full-text search on only a subset of entities
PostPosted: Fri Oct 17, 2014 7:25 am 
Beginner
Beginner

Joined: Wed Aug 06, 2014 10:53 am
Posts: 30
You can use a BooleanQuery ...
<code>
query = new BooleanQuery();
query.add(query1, Occur.SHOULD)
query.add(query2, Occur.SHOULD)
query.setMinimumNumberShouldMatch(1)
</code>


Top
 Profile  
 
 Post subject: Re: full-text search on only a subset of entities
PostPosted: Sun Oct 26, 2014 4:15 pm 
Beginner
Beginner

Joined: Mon Nov 29, 2004 11:51 am
Posts: 31
That worked. Thanks!


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