我正在使用Lucene 3.5来运行查询,我需要根据三个先前条件匹配查询。例如,在对关键字进行查询之前,我为A = A,B = B,C = C执行booleanQuery。我遇到的问题是Lucene总是返回一个结果,并在列表中反复重复该结果。这是我的代码。
public List<Parts> performSearch(String A, String B, String C, String keyWord)thows IOException{
List<Parts> list = new ArrayList<Parts>();
int hitsPerPage = 5;
BooleanQuery temp = new BooleanQuery();
BooleanQuery query = new BooleanQuery();
Query aquery = new TermQuery(new Term("A", A);
Query bquery = new TermQuery(new Term("B", B);
Query cquery = new TermQuery(new Term("C", C);
Query keyquery = null;
try{
keyquery = parser.parse(keyword);
}catch(Exception e){
e.printStackTrace;
}
temp.add(aquery, Occur.MUST);
temp.add(bquery, Occur.MUST);
temp.add(cquery, Occur.MUST);
temp.add(keyquery, Occur.SHOULD);
query.add(temp, Occur.MUST);
TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage, true);
searcher.search(query, collector);
ScoreDoc[] score = collector.topDocs().scoreDocs;
for(ScoreDco scoreDoc: score){
...put into a list
}
return list;
出于某种原因,这只是获得第一个匹配的文档并将其放入列表中五次(hitsPerPage)。我需要它来返回所有相关的文档并返回它们。我做错了什么?
谢谢,