1
我在Lucene中创建了一个文档索引。其中一个字段名为title
,我想搜索title
包含word
的所有文档。不幸的是我只能得到确切的结果 - 我得到的文档标题为word
(但不是例如my word
)。为什么Lucene结果仅包含完全匹配?
代码:
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 ;
是的,我用了StringField。不知道这可能是一个问题。谢谢 – latata