我在lucene上遇到了一些问题。我正在查询数据库。 据我所知索引是好的(我用lukeall-4.4.0检查)。 Query构造如下:
Q = Query.split(" ");
booleanQuery = new BooleanQuery();
//Query[] Queryy = new Query[5 + 5 * Q.length];
Query[] Queryy = new Query[3 + 3*Q.length];
//USING THE ALL TEXT
Queryy[0] = new TermQuery(new Term("DESIGNACAO", Query));
Queryy[1] = new TermQuery(new Term("DESCRICAO", Query));
Queryy[2] = new TermQuery(new Term("TAG", Query));
//USING THE SEPARETED VALUES
for (int i = 3, j = 0; j < Q.length; i++, j++) {
Queryy[i] = new TermQuery(new Term("DESIGNACAO", Q[j]));
Queryy[++i] = new TermQuery(new Term("DESCRICAO", Q[j]));
Queryy[++i] = new TermQuery(new Term("TAG", Q[j]));
}
for (int i = 0; i < Queryy.length; i++) {
booleanQuery.add(Queryy[i], BooleanClause.Occur.MUST);
}
查询没问题。对于搜索“not or”,查询(booleanQuery)将如下所示:
+DESIGNACAO:not or +DESCRICAO:not or +TAG:not or +DESIGNACAO:not +DESCRICAO:not +TAG:not +DESIGNACAO:or +DESCRICAO:or +TAG:or
我正在使用SimpleAnalyser,因此不会删除或不会删除。问题是我无法获得点击率。如果我使用lukeall-4.4.0进行搜索但我的代码不能搜索,我只能点击。我的搜索方法如下:
IndexReader reader = IndexReader.open(directory1);
TopScoreDocCollector collector = TopScoreDocCollector.create(50, true);
searcher = new IndexSearcher(reader);
searcher.search(booleanQuery, collector);
hits = collector.topDocs().scoreDocs;
int total = collector.getTotalHits();
displayResults();
收集数据有什么不妥吗?
亲切的问候
答案 0 :(得分:2)
一块蛋糕。问题在于构建查询:
for (int i = 0; i < Queryy.length; i++) {
booleanQuery.add(Queryy[i], BooleanClause.Occur.MUST);
}
BooleanClause.Occur.MUST
表示必须存在。因此,我添加到booleanquery的所有术语必须存在(term1 AND term2 AND term3)。正确的是:
booleanQuery.add(Queryy[i], BooleanClause.Occur.SHOULD);
这样我可以说必须存在我添加的术语之一(term1或term2或term3)。
亲切的问候