本文整理汇总了Java中org.apache.lucene.search.TermQuery.setBoost方法的典型用法代码示例。如果您正苦于以下问题:Java TermQuery.setBoost方法的具体用法?Java TermQuery.setBoost怎么用?Java TermQuery.setBoost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.search.TermQuery
的用法示例。
在下文中一共展示了TermQuery.setBoost方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addSearchTermQueries
import org.apache.lucene.search.TermQuery; //导入方法依赖的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: getQuery
import org.apache.lucene.search.TermQuery; //导入方法依赖的package包/类
@Override
public Query getQuery(Element e) throws ParserException {
String field = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
String value = DOMUtils.getNonBlankTextOrFail(e);
TermQuery tq = new TermQuery(new Term(field, value));
tq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
return tq;
}