Hi,

I am using Lucene 3.6.2 (I cannot upgrade due to 3rd party dependencies).

I have written the following code below to illustrate the problem. I create
a single document, add three fields, put it into the index. When I attempt
to find the document using exact matches I can find the document 2 out of 3
times. I have read the documentation and google'd but I am currently
drawing a blank as to where my mistake is. Any pointers would be gratefully
received.

Regards
Kiwicoder


public static void main(String[] args) throws CorruptIndexException,
LockObtainFailedException, IOException {
        RAMDirectory directory = new RAMDirectory();

        IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_36,
new StandardAnalyzer(Version.LUCENE_36));
        IndexWriter writer = new IndexWriter(directory, config);

        Document doc = new Document();

        doc.add(new Field("id", "c71fa7f8-32c2-4cb3-97d8-4728322079db",
Field.Store.YES, Field.Index.NOT_ANALYZED));
        doc.add(new Field("type", "data", Field.Store.NO,
Field.Index.ANALYZED));
        doc.add(new Field("name", "Name1", Field.Store.NO,
Field.Index.ANALYZED));

        writer.addDocument(doc);

        writer.close();

        // -------------------------------------------
        IndexReader reader = IndexReader.open(directory);

        IndexSearcher search = new IndexSearcher(reader);
        System.out.println("ID:   " + search.search(new TermQuery(new
Term("id", "c71fa7f8-32c2-4cb3-97d8-4728322079db")), 100).totalHits); // 1
document found
        System.out.println("TYPE: " + search.search(new TermQuery(new
Term("type", "data")), 100).totalHits); // 1 document found
        System.out.println("NAME: " + search.search(new TermQuery(new
Term("name", "Name1")), 100).totalHits); // 0 document found
        search.close();
    }

Reply via email to