Yes, it works much better if you help Lucene to find the sort field type with new Sort(new SortField("pubdate", SortField.STRING, true))
Thank you -----Message d'origine----- De : Otis Gospodnetic [mailto:[EMAIL PROTECTED] Envoyé : mardi 15 janvier 2008 17:19 À : java-user@lucene.apache.org Objet : Re: issue sorting results by string field Dominique, I don't have the javadoc/source in front of me, but souldn't that be new Sort(new SortField(.....)) ? I'm not sure if the underlying sort implementation is smart enough to avoid re-doing the same work when you call these constructors for *every* every search. If it's not smart enough, initialize them on domand and keep the Sort object around for reuse. Otis -- Sematext -- http://sematext.com/ -- Lucene - Solr - Nutch ----- Original Message ---- From: Dominique Béjean <[EMAIL PROTECTED]> To: java-user@lucene.apache.org Sent: Tuesday, January 15, 2008 10:05:52 AM Subject: issue sorting results by string field Hi, I need to sort my search results by descending publication date. To do this, I added a field like this in all documents doc.add(new Field("pubdate", date, Field.Store.YES, Field.Index.UN_TOKENIZED)); Where date contains string formatted in this way yyyymmddhhmmss Searches are executed like this hits = searcher.search(booleanQuery, new Sort("pubdate", true)); Here is a example of result output for the date field. We can see that the result is not sorted neither ascending, neither descending. 20080114190000 20080114225500 20080114232900 20080114235700 20080115102800 20080115100600 20080115124639 20080115124100 20080115131700 20080115131900 20080112000100 20080112001700 20080112001900 20080112074400 20080112080000 20080112082000 What can be the problem ? Where am I wrong ? Thank you by advance. dominique --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]