本文整理汇总了Java中org.apache.lucene.search.FuzzyQuery.setBoost方法的典型用法代码示例。如果您正苦于以下问题:Java FuzzyQuery.setBoost方法的具体用法?Java FuzzyQuery.setBoost怎么用?Java FuzzyQuery.setBoost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.search.FuzzyQuery
的用法示例。
在下文中一共展示了FuzzyQuery.setBoost方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addSearchTermQueries
import org.apache.lucene.search.FuzzyQuery; //导入方法依赖的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: createWordQuery
import org.apache.lucene.search.FuzzyQuery; //导入方法依赖的package包/类
private BooleanQuery createWordQuery(final Analyzer currentQueryAnalyser, final String fieldName, final String tokenizedKeyword) throws IOException {
final BooleanQuery wordQuery = new BooleanQuery();
final Reader reader = new StringReader(tokenizedKeyword);
try (final TokenStream tokenStream = currentQueryAnalyser.tokenStream(fieldName, reader)) {
tokenStream.reset();
try {
final CharTermAttribute termAttribute = tokenStream.getAttribute(CharTermAttribute.class);
//final List<SpanQuery> clauses = new ArrayList<>();
while (tokenStream.incrementToken()) {
final BooleanQuery fuzzyTermQuery = new BooleanQuery();
final String term = new String(termAttribute.buffer(), 0, termAttribute.length());
final PrefixQuery termQuery = new PrefixQuery(new Term(fieldName, term));
fuzzyTermQuery.add(termQuery, BooleanClause.Occur.SHOULD);
final FuzzyQuery fuzzyQuery = new FuzzyQuery(new Term(fieldName, term), 1, 0, 50, true);
fuzzyTermQuery.add(fuzzyQuery, BooleanClause.Occur.SHOULD);
fuzzyQuery.setBoost(0.8f);
wordQuery.add(fuzzyTermQuery, BooleanClause.Occur.SHOULD);
//clauses.add(new SpanMultiTermQueryWrapper(termQuery));
//clauses.add(new SpanMultiTermQueryWrapper(fuzzyQuery));
}
//Pour l'instant slop � 0, essayer d'autre chose apr�s
//3e param inOrder � true car on veut que les mots soient en ordre
//final SpanNearQuery spanNearQuery = new SpanNearQuery(clauses.toArray(new SpanQuery[clauses.size()]), 0, true);
//query.add(spanNearQuery, BooleanClause.Occur.MUST);
} finally {
reader.reset();
tokenStream.end();
}
}
return wordQuery;
}
示例3: readFields
import org.apache.lucene.search.FuzzyQuery; //导入方法依赖的package包/类
@Override
public void readFields(DataInput in) throws IOException {
float boost = in.readFloat();
TermWritable termWritable = new TermWritable();
termWritable.readFields(in);
Term term = termWritable.getTerm();
int maxEdits = in.readInt();
int prefixLength = in.readInt();
int maxExpansions = in.readInt();
boolean transpositions = in.readBoolean();
query = new FuzzyQuery(term, maxEdits, prefixLength, maxExpansions, transpositions);
query.setBoost(boost);
}