lucene4下用MultiFieldQueryParser同时搜索多个field时
Please read full article from lucene4下用MultiFieldQueryParser同时搜索多个field时
/**同时搜索name和descr两个field,并设定它们在搜索结果排序过程中的权重,权重越高,排名越靠前
*为了后面解释score问题的方便,这里设置相同的权重
* */
Map<String , Float> boosts =
new
HashMap<String, Float>();
boosts.put(
"name"
,
1
.0f);
boosts.put(
"descr"
,
1
.0f);
/**用MultiFieldQueryParser类实现对同一关键词的跨域搜索
* */
MultiFieldQueryParser parser =
new
MultiFieldQueryParser(Version.LUCENE_47, field,
new
StandardAnalyzer(Version.LUCENE_47),boosts);
query = parser.parse(queryStr);
System.out.println(
"QueryParser :"
+ query.toString());
TopDocs topDocs = searcher.search(query,
10000
);
No comments:
Post a Comment