-->
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: [hbernate searh] sorting on field only work half !!
PostPosted: Wed Jun 18, 2008 5:34 am 
Beginner
Beginner

Joined: Mon Dec 17, 2007 11:08 pm
Posts: 47
hi,

i had class that is

Code:
@Index
public class User
{
   @Fields({@Field(index=Index.TOKENIZED),
      @Field(index=Index.UN_TOKENIZED, name="email_sort", store=Store.YES)})
   private String email;
// other .....
}


and i got a Query to sort the field base on multiple field (in a JUnit test case)

Code:
MultiFieldQueryParser parser = new MultiFieldQueryParser(
            new String[]{
                  "email", "fax"}, new StandardAnalyzer());
      Query query = parser.parse( "u*" );
      hibQuery = fullTextSession.createFullTextQuery( query, User.class );
      Sort sort = new Sort(new SortField("email", false));
      hibQuery.setSort(sort);
      List<User> result = hibQuery.list();


note that the SortField could be true or false base on user input.

My problem is something when i run the test case, SOMETIMES I got this exception :

Code:
java.lang.RuntimeException: there are more terms than documents in field "email", but it's impossible to sort on tokenized fields
   at org.apache.lucene.search.FieldCacheImpl$10.createValue(FieldCacheImpl.java:379)
   at org.apache.lucene.search.FieldCacheImpl$Cache.get(FieldCacheImpl.java:72)
   ....


but something is working ok.

any idea ?

kiwi

_________________
happy hacking !


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 18, 2008 6:31 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hello,
your problem is exactly what your exception is telling:
you can't sort on Tokenized fields.
Your model is fixed already as I see there are two fields, you just have to sort on the Untokenized one:
Code:
Sort sort = new Sort(new SortField("email_sort", false));

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 18, 2008 6:43 am 
Beginner
Beginner

Joined: Mon Dec 17, 2007 11:08 pm
Posts: 47
hi, thx for reply.

I had try this code below

Code:
hibQuery = fullTextSession.createFullTextQuery( query, User.class );
Sort sort = new Sort(new SortField("email_sort", true ));
hibQuery.setSort(sort);
List<User> result = hibQuery.list();


but I get this exception :

Code:
java.lang.RuntimeException: field "email_sort" does not appear to be indexed
   at org.apache.lucene.search.ExtendedFieldCacheImpl$5.createValue(ExtendedFieldCacheImpl.java:156)
   at org.apache.lucene.search.FieldCacheImpl$Cache.get(FieldCacheImpl.java:72)
   at org.apache.lucene.search.ExtendedFieldCacheImpl.getAuto(ExtendedFieldCacheImpl.java:110)


all code is remain unchange accept the SortField.

please advice.

kiwi

_________________
happy hacking !


Top
 Profile  
 
 Post subject: problem solved
PostPosted: Wed Jun 18, 2008 7:00 am 
Beginner
Beginner

Joined: Mon Dec 17, 2007 11:08 pm
Posts: 47
hi, problem had solved.

i had use User.class as a embedded to ParentClass.

Code:
MultiFieldQueryParser parser = new MultiFieldQueryParser(
            new String[]{
                  "parentClass.email", "fax"}, new StandardAnalyzer());
      Query query = parser.parse( "u*" );
      hibQuery = fullTextSession.createFullTextQuery( query, User.class );
      Sort sort = new Sort(new SortField("parentClass.email_sort", false));
      hibQuery.setSort(sort);
      List<User> result = hibQuery.list();


now is working as it is.

Thx a lot !!!

kiwi

_________________
happy hacking !


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.