本文整理汇总了Java中org.apache.lucene.search.PrefixQuery.setBoost方法的典型用法代码示例。如果您正苦于以下问题:Java PrefixQuery.setBoost方法的具体用法?Java PrefixQuery.setBoost怎么用?Java PrefixQuery.setBoost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.search.PrefixQuery
的用法示例。
在下文中一共展示了PrefixQuery.setBoost方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addSearchTermQueries
import org.apache.lucene.search.PrefixQuery; //导入方法依赖的package包/类
/**
* Adds for every field in {@link IIndexTypeConf} a {@link TermQuery}, {@link PrefixQuery} and
* a {@link FuzzyQuery} with a suitable boost relative to the given base boost.
*
* @param indexType the type in which should be searched.
* @param search the search text.
* @param subQuery the {@link BooleanQuery} to add the sub queries.
* @param baseBoost highest possible boost of the query. The more the match is exact
* than a bigger boost will be used.
*/
private static void addSearchTermQueries(final IIndexTypeConf indexType, final String search,
final BooleanQuery subQuery, final float baseBoost) {
for(final IIndexFieldConf<?> field : indexType.getFields()) {
final Term term = new Term(field.getName(), search);
final TermQuery exactQuery = new TermQuery(term);
exactQuery.setBoost(baseBoost);
subQuery.add(exactQuery, Occur.SHOULD);
final PrefixQuery pfQuery = new PrefixQuery(term);
pfQuery.setBoost(0.7f*baseBoost);
subQuery.add(pfQuery, Occur.SHOULD);
final FuzzyQuery fuzzyQuery = new FuzzyQuery(term);
fuzzyQuery.setBoost(0.5f*baseBoost);
subQuery.add(fuzzyQuery, Occur.SHOULD);
}
}
示例2: newPrefixQuery
import org.apache.lucene.search.PrefixQuery; //导入方法依赖的package包/类
/**
* Factory method to generate a prefix query.
*/
protected Query newPrefixQuery(String text) {
BooleanQuery bq = new BooleanQuery(true);
for (Map.Entry<String,Float> entry : weights.entrySet()) {
PrefixQuery prefix = new PrefixQuery(new Term(entry.getKey(), text));
prefix.setBoost(entry.getValue());
bq.add(prefix, BooleanClause.Occur.SHOULD);
}
return simplify(bq);
}