<分区>
我已经在 Lucene 中创建了文档索引。其中一个字段名为 title
,我想搜索 title
包含 word
的所有文档。不幸的是,我只得到了准确的结果 - 我得到了标题为 word
的文档(但不是例如 my word
)。
代码:
String field = "title";
String value = "word";
List<MyDoc> myDocList = new ArrayList<MyDoc>();
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_45);
QueryParser parser = new QueryParser(Version.LUCENE_45, field, analyzer);
try {
Query query = new TermQuery(new Term(field, value));
int numResults = 100;
ScoreDoc[] hits = indexSearcher.search(query,numResults).scoreDocs;
for (int i = 0; i < hits.length; i++) {
Document doc = indexSearcher.doc(hits[i].doc);
myDocList .add(getMyDoc(doc));
}
} catch (IOException e) {
e.printStackTrace();
}
return myDocList ;