-->
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: [Hibernate Search] Problem when sorting results
PostPosted: Wed Jun 27, 2007 11:17 am 
Regular
Regular

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

I have a field :
Quote:
@Field(index=Index.TOKENIZED, store=Store.YES)
private String titre;


I have an error :
Quote:
java.lang.RuntimeException: there are more terms than documents in field "titre", but it's impossible to sort on tokenized fields
org.apache.lucene.search.FieldCacheImpl$6.createValue(FieldCacheImpl.java:287)
org.apache.lucene.search.FieldCacheImpl$Cache.get(FieldCacheImpl.java:72)
...


When I insert 2 documents with the field "titre" = "un truc" and the other "un machin".

When I want to Sort the results by "titre" field, the error appears.

I tried to use Index.UN_TOKENIZED but I can't search for tokens like "un" or "truc" :S

Do you have an idea ?

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 28, 2007 3:19 am 
Regular
Regular

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


Top
 Profile  
 
 Post subject: Sorting requires indexed un-tokenized field
PostPosted: Thu Jun 28, 2007 6:09 pm 
Hibernate Team
Hibernate Team

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

To be able to sort on a field in Lucene the field has to be indexed un-tokenized. This is a restriction by lucene. If you think about it it makes quite a bit of sense.

If you want to tokenize the field, but also sort on it you can insert the value twice - once tokenized and once un-tokenized. Search against the tokenized field and sort by the untokenized one. This approach should work quite well.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 29, 2007 1:34 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
Thank you very much. It works fine.

I added :
Code:
@Field(index=Index.UN_TOKENIZED, store=Store.YES)
@Transient
@SuppressWarnings("unused")
private String titreSort;


and in the "titre" setter, I have :
Code:
public void setTitre(String titre) {
   this.titre = titre;
   this.titreSort = titre;
}


And i made a sort by titleSort :
Code:
fullTextQuery.setSort(new Sort("titreSort", true));


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.