我在lucene 4.8和代碼中有一個下面的數據索引。Lucene搜索結果
Finance expense
Admin expenses
Transaction expense
Salary expenses
索引:
try {
writer = createWriter(ramDirectory);
for(String line : readFile(FILE_PATH)) {
String[] split = line.split(",");
Document doc = new Document();
doc.add(new TextField("id", split[0].trim(), Field.Store.YES));
doc.add(new TextField("name", split[1].trim(), Field.Store.YES));
writer.addDocument(doc);
}
writer.commit();
} finally {
if(writer != null) {
writer.close();
}
}
搜索
IndexSearcher searcher = new IndexSearcher(DirectoryReader.open(ramDirectory));
QueryParser nameQParser = new QueryParser(Version.LUCENE_48, "name", new StandardAnalyzer(Version.LUCENE_48));
Query query = nameQParser.parse("expense");
TopDocs queryResults = searcher.search(query, 10);
以上觀點僅供參考下面兩個結果代碼的回報。它不會返回最後有's'的結果。
當前結果:
Finance expense
Transaction expense
預期的結果:
Finance expense
Admin expenses
Transaction expense
Salary expenses
請所說的其實是錯誤的,我的代碼。