【发布时间】:2013-11-02 17:35:03
【问题描述】:
我在 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 ;
【问题讨论】: