Hi,

I had a test case that added two documents, each with one untokenized field, and sorted them. The data in each document was

char(1) + "First"
char(0xffff) + "Last"

With Lucene 2.1 the documents are sorted correctly, but with Lucene 2.3.1, they are not. Looking at the index with Luke shows that the document with "Last" has not been handled correctly, i.e. the text for the "subject" field is empty.

The test case below shows the problem.

Regards
Antony


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.IOException;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class LastSubjectTest
{
    /**
     *  Set up a number of documents with 1 duplicate ContentId
     *  @throws Exception
     */
    @Before
    public void setUp() throws Exception
    {
IndexWriter writer = new IndexWriter("TestDir/", new StandardAnalyzer(), true);
        Document doc = new Document();
String subject = new StringBuffer(1).append((char)0xffff).toString() + "Last"; Field f = new Field("subject", subject, Field.Store.YES, Field.Index.NO_NORMS);
        doc.add(f);
        writer.addDocument(doc);
        doc = new Document();
        subject = new StringBuffer(1).append((char)0x1).toString() + "First";
        f = new Field("subject", subject, Field.Store.YES, 
Field.Index.NO_NORMS);
        doc.add(f);
        writer.addDocument(doc);
        writer.close();
    }

    /**
     *  @throws Exception
     */
    @After
    public void tearDown() throws Exception
    {
    }

    /**
     *  Tests that the last is after first document, sorted by subject
     *  @throws IOException
     */
    @Test
    public void testSortDateAscending()
           throws IOException
    {
        IndexSearcher searcher = new IndexSearcher("TestDir/");
        Query q = new MatchAllDocsQuery();
        Sort sort = new Sort(new SortField("subject"));
        Hits hits = searcher.search(q, sort);
assertEquals("Hits should match all documents", searcher.getIndexReader().maxDoc(), hits.length());

        Document fd = hits.doc(0);
        Document ld = hits.doc(1);
        String fs = fd.get("subject");
        String ls = ld.get("subject");

        for (int i = 0; i < hits.length(); i++)
        {
            Document doc = hits.doc(i);
            String subject = doc.get("subject");
            System.out.println("Subject:" + subject);
        }
        assertTrue("Subjects have been sorted incorrectly", fs.compareTo(ls) < 
0);
    }

}


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to