-->
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.  [ 6 posts ] 
Author Message
 Post subject: Query more than one object type
PostPosted: Tue Dec 08, 2009 12:35 pm 
Regular
Regular

Joined: Thu Nov 26, 2009 8:45 am
Posts: 78
Hi there,

i got a bunch of indexed classes and now tryin to figure out how to query the index. As i have seen, i have to determine the class type which i am searching for, but i wanna enable my users to search simultaneously over all indexed objects. Do i have to build a query like:

object1:foo OR object2:foo OR object3:foo OR object4:foo ... OR object1337:foo

or is there a more efficient way to build a query that will search the index the way i want it to?


Top
 Profile  
 
 Post subject: Re: Query more than one object type
PostPosted: Tue Dec 08, 2009 12:41 pm 
Regular
Regular

Joined: Thu Nov 26, 2009 8:45 am
Posts: 78
grmpf, didnt see that there is a multifieldqueryparser, seems that this is the one thing i was looking for.


Top
 Profile  
 
 Post subject: Re: Query more than one object type
PostPosted: Tue Dec 08, 2009 2:26 pm 
Hibernate Team
Hibernate Team

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

if you are only interested in filtering on Class type, then you can use FulltextSession.createFullTextQuery((org.apache.lucene.search.Query luceneQuery, Class<?>... entities)

If you don't provide any class parameter for this method all indexes are searched. If you provide one or more entity types the result will be limited to these types.
This is in-depended of MultiFieldQueryParser. You use this parser if you want to search across different indexed fields.

--Hardy


Top
 Profile  
 
 Post subject: Re: Query more than one object type
PostPosted: Wed Dec 09, 2009 12:25 pm 
Regular
Regular

Joined: Thu Nov 26, 2009 8:45 am
Posts: 78
ok, after working through the multifieldqueryparser in the book, i realised, that this one just do the search over different classes. The org.hibernate.search.FulltextQuery still needs an specific class in its arguments, thats not the way i want it.

I just wanna enable my user, to enter a search term, which is applys to all my indexed classes and then i wanna return a list of all possible results to him, not depending on which type of class they are. Is this possible?


Top
 Profile  
 
 Post subject: Re: Query more than one object type
PostPosted: Wed Dec 09, 2009 1:46 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Quote:
ok, after working through the multifieldqueryparser in the book, i realised, that this one just do the search over different classes. The org.hibernate.search.FulltextQuery still needs an specific class in its arguments, thats not the way i want it.


Where do you have to specify a class in FullTextQuery?
The way to filter on classes is at construction time of the query:
Code:
FullTextSession.createFullTextQuery(org.apache.lucene.search.Query luceneQuery, java.lang.Class<?>... entities)

where entities is a vararg parameter, meaning you don't have to specify any class at all which is equivalent to searching over all indexed entities.

--Hardy


Top
 Profile  
 
 Post subject: Re: Query more than one object type
PostPosted: Thu Dec 10, 2009 4:07 am 
Regular
Regular

Joined: Thu Nov 26, 2009 8:45 am
Posts: 78
Thx for your reply, all my fault, didnt see the method call with just the query as its arguments. Problem solved.


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