lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dragon Fly <dragon-fly...@hotmail.com>
Subject Sort by date with Lucene 2.2.0 ...
Date Thu, 18 Oct 2007 19:35:28 GMT

Hi,

I'm am trying to sort a date field in my index but I'm seeing strange results.  I have searched
the Lucene user mail archive for Datetools but still couldn't figure out the problem.

The date field is indexed as follows (i.e. DateTools is used, date field is stored and untokenized):

String dateString = DateTools.dateToString (myDateObject, DateTools.Resolution.SECOND);
Field field = new Field (DATE_FIELD, dateString, Field.Store.YES, Field.Index.UN_TOKENIZED);
field.setOmitNorms (true);
document.add (field);

=====

I executed the search with a reverse sort on the DATE_FIELD:

QueryParser queryParser = new QueryParser ("field1", new StandardAnalyzer ());
Query query = queryParser.parse ("txt:\"sum\"");
IndexSearcher searcher = new IndexSearcher (indexDirectory);
TopFieldDocs topFieldDocs = searcher.search (query, null, 10000, new Sort (DATE_FIELD, true));

for (int i = 0; i < topFieldDocs.totalHits; i++)
{
  Document document = searcher.doc (topFieldDocs.scoreDocs[i].doc);
  String date = document.get (DATE_FIELD);

  System.out.println (date);
}

====

As you can see, the output below is not sorted correctly (e.g. 20070902233024 comes before
20070902233048).  Does anyone know what the problem is? Thank you.


20070905140251
20070902233024
20070902233048
20070902234113
20070901040321
20070901040751
20070901040922
20070901042706
20070901042603
20070901050936
20070901050935
20070901050935
20070901080218


_________________________________________________________________
Windows Live Hotmail and Microsoft Office Outlook – together at last.  Get it now.
http://office.microsoft.com/en-us/outlook/HA102225181033.aspx?pid=CL100626971033
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message