-->
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.  [ 3 posts ] 
Author Message
 Post subject: [Hibernate Search] Sort in multiseach
PostPosted: Wed Aug 01, 2007 4:07 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
Hello,

I don't know if it's possible, I make a search on 2 classes (for example Class1 and Class2), so I have :
Code:
fullTextSession.createFullTextQuery(luceneQuery,Class1.class, Class2.class);


Then, I want to made a
Code:
fullTextQuery.setSort(new Sort("field"));


I have 2 records in Class1 :
field=a
field=c

and 2 records in Class2 :
field=b
field=d

and I want the result is :
field=a (Class1)
field=b (Class2)
field=c (Class1)
field=d (Class2)

I see in Lucene javadoc that we could Sort by 2 fields, but it's like in SQL, the first field is more important that the second.

Is it possible to do that ?

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 01, 2007 9:21 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
I am not sure if I understand your use case completely, but I think it should be possible.

If I understand correctly you have two classes Class1 and Class2 (and hence two indices /usr/lucene/indexes/Class1 and /usr/lucene/indexes/Class2). Both classes have a property called 'field'.

if this is correct
Code:
fullTextQuery.setSort(new Sort("field"));

should do what you want. HSearch opens a MultiReader under the hood towards each of the indices and then executes the search against both indices. Provided that the field names match you should get a list of mixed types (Class1 and Class2) from fullTextQuery.list().

I recommend to use Luke http://www.getopt.org/luke/ to inspect your indices. This helps to understand what's happening under the hoods.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 01, 2007 10:55 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
Thank you very much ! It works very well with the same field name ;).


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