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