當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。