I'm pretty sure your problem is that you're sorting as a Float. The three
values you use all are evaluated (according to the Sort doc) by
Float.valueOf. which is 1.20500099E12 for all three values you use.

Why are you using Float as your sortField? If your DATE fields are
normalized, string sorting would work just fine.......

Best
Erick

P.S. Sorry if this comes through multiple times, but my connection is being
wonky

On Sat, Mar 8, 2008 at 1:57 PM, legrand thomas <[EMAIL PROTECTED]>
wrote:

> Dear all,
>
> I'm trying to sort query results using a date criteria. My dates are
> stored as "long" in the database (I cannot change this) and indexed as
> untokenized. The sorted resuIts I get aren't consistent. This problem does
> not occur if the number are "smaller".
>
> Am I doing something wrong ? Is it possible to sort using "long" type ?
> What else should I do ?
>
> Regards & thanks in advance,
> Tom
>
>
> public void testDateSort(){
>        System.out.println("[testDateSort][begin]");
>
>        IndexWriter mAdIndexWriter=null;
>        Directory adIndexDir=null;
>
>         Document doc0 = new Document();
>         doc0.add(new Field("ID","doc0", Field.Store.YES,
> Field.Index.TOKENIZED));
>         doc0.add(new Field("DATE","1205000950000", Field.Store.YES,
> Field.Index.UN_TOKENIZED));
>
>         Document doc1= new Document();
>         doc1.add(new Field("ID","doc1", Field.Store.YES,
> Field.Index.TOKENIZED));
>         doc1.add(new Field("DATE","1205000950001", Field.Store.YES,
> Field.Index.UN_TOKENIZED));
>
>         Document doc2 = new Document();
>         doc2.add(new Field("ID","doc2", Field.Store.YES,
> Field.Index.TOKENIZED));
>         doc2.add(new Field("DATE","1205000950002", Field.Store.YES,
> Field.Index.UN_TOKENIZED));
>
>        Analyzer analyser = new SimpleAnalyzer();
>        try{
>            adIndexDir=FSDirectory.getDirectory
> ("C:\\YourFavoriteDirectory");
>            mAdIndexWriter = new IndexWriter(adIndexDir, analyser, true);
>
>            mAdIndexWriter. addDocument(doc0);
>            mAdIndexWriter. addDocument(doc2);
>            mAdIndexWriter. addDocument(doc1);
>
>            mAdIndexWriter.optimize();
>            mAdIndexWriter.close();
>
>            IndexReader mAdIndexReader= IndexReader.open(adIndexDir);
>            IndexSearcher searcher = new IndexSearcher(mAdIndexReader);
>
>            Query  query=new FuzzyQuery(new Term("ID","doc"),
> Float.parseFloat("0.8"));
>            Sort timeSorter=new Sort(new SortField("DATE",SortField.FLOAT,
> false));
>            Hits allTheHits=searcher.search(query,timeSorter);
>
>            for(int i = 0; i <allTheHits.length(); i++){
>                System.out.println("Date n°" + i + " = "
> +allTheHits.doc(i).get("DATE"));
>            }
>
>            mAdIndexReader.close();
>        }catch(Exception ex){
>            ex.printStackTrace();
>            fail();
>        }
>        System.out.println("[testDateSort][end]");
>    }
>
>
>
> ---------------------------------
>  Envoyé avec Yahoo! Mail.
> Une boite mail plus intelligente.
>

Reply via email to