It seems that whenever I update an existing document in the index (the same behavior for delete / add), it cannot be found with TermQuery. Here is a short snippet:
iw = new IndexWriter (directory, config);
Document doc = new Document(); doc.add(new StringField("string", "a", Store.YES)); doc.add(new IntField("int", 1, Store.YES)); iw.addDocument(doc); Query query = new TermQuery(new Term("string","a")); Document[] hits = search(query); doc = hits[0]; print(doc); doc.removeField("int"); doc.add(new IntField("int", 2, Store.YES)); iw.updateDocument(new Term("string","a"), doc); hits = search(query); System.out.println(hits.length); System.out.println("_________________"); for(Document hit : search(new MatchAllDocsQuery())){ print(hit); }
The result is the following console output:
stored,indexed,tokenized,omitNorms,indexOptions=DOCS_ONLY<string:a> stored<int:1> ________________ 0 _________________ stored,indexed,tokenized,omitNorms,indexOptions=DOCS_ONLY<string:a> stored<int:2> ________________
It seems that after updating the document (but rather a new document) is indexed and returned in MatchAllDocsQuery, but TermQuery cannot be found.
A complete sample code is available at http://pastebin.com/sP2Vav9v
Furthermore, this only happens (the second search does not work) when the StringField value contains special characters (for example, file: / F: /).
java lucene
Michael
source share