我已经将文件内容索引为Luence(4.9)中的字符串,以下是一些在Lucene中编入索引的示例数据。
Info Object
{
String ID;
String infoData;
}
ID
infoData
1
Distance so far travelled 10KM
2
Distance travelled 5Miles
3
distance covered 100 Meter
doc.add(new TextField("id", info.getID(), Field.Store.YES));
doc.add(new TextField("pdata", infoData.toString().replaceAll("(?m)^\\s", ""), Field.Store.NO));
writer.addDocument(doc);
我正在尝试搜索以下术语并期望输出第一条记录,但我没有得到任何东西:
Term query - Distance KM
Expected output - ID = 1
SpanNearQuery query = new SpanNearQuery(new SpanQuery[] { new SpanTermQuery(new Term("pdata", "Distance")),
new SpanTermQuery(new Term("pdata", "KM")) }, 3, true);
TopDocs hits = searcher.search(query, 20);
ScoreDoc[] scoreDocs = hits.scoreDocs;
System.out.println("Results :" + hits.totalHits);
for (ScoreDoc match : scoreDocs)
{
Document doc = searcher.doc(match.doc);
System.out.println(doc.get("id"));
}
我有什么遗失的吗?