这就是我所做的,我只有150个平均文件大小为2KB的文件。
BooleanQuery.Builder builder = new BooleanQuery.Builder();
// filename : prefix search
BooleanQuery.Builder filenameBuilder = new BooleanQuery.Builder();
for (String s : queryStr.trim().split("\\s+")) {
PrefixQuery filenameQuery1 = new PrefixQuery(new Term(Indexer.FIELD_NAME_FILENAME, s));
filenameBuilder.add(filenameQuery1, BooleanClause.Occur.SHOULD);
}
// content : prefix search
BooleanQuery.Builder contentBuilder = new BooleanQuery.Builder();
for (String s : queryStr.trim().split("\\s+")) {
PrefixQuery contentQuery1 = new PrefixQuery(new Term(Indexer.FIELD_NAME_CONTENT, s));
contentBuilder.add(contentQuery1, BooleanClause.Occur.MUST);
}
// Set filename and content with different weights.
Query filenameQuery = filenameBuilder.build();
Query contentQuery = contentBuilder.build();
filenameQuery.setBoost(4.0f);
contentQuery.setBoost(1.0f);
// Merge filename and content queries : filename OR content
builder.add(filenameQuery, BooleanClause.Occur.SHOULD);
builder.add(contentQuery, BooleanClause.Occur.SHOULD);
Query query = builder.build();
注意:如果我仅搜索filename
,它似乎要快得多,但filename
+ content
会超过10秒!
此外,我已尝试将PrefixQuery
上的content
更改为TermQuery
(我的意思是进行精确搜索),但仍然无法做出任何改进。