当前位置: 首页>>代码示例>>Java>>正文


Java FuzzyQuery.setBoost方法代码示例

本文整理汇总了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);
	}
}
 
开发者ID:XMBomb,项目名称:InComb,代码行数:30,代码来源:QueryUtil.java

示例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;
}
 
开发者ID:KleeGroup,项目名称:vertigo-labs,代码行数:34,代码来源:LuceneIndexPlugin.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-blur,代码行数:14,代码来源:FuzzyQueryWritable.java


注:本文中的org.apache.lucene.search.FuzzyQuery.setBoost方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。