當前位置: 首頁>>代碼示例>>Java>>正文


Java Query.setBoost方法代碼示例

本文整理匯總了Java中org.apache.lucene.search.Query.setBoost方法的典型用法代碼示例。如果您正苦於以下問題:Java Query.setBoost方法的具體用法?Java Query.setBoost怎麽用?Java Query.setBoost使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.lucene.search.Query的用法示例。


在下文中一共展示了Query.setBoost方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: build

import org.apache.lucene.search.Query; //導入方法依賴的package包/類
@Override
public Query build(QueryNode queryNode) throws QueryNodeException {
  BoostQueryNode boostNode = (BoostQueryNode) queryNode;
  QueryNode child = boostNode.getChild();

  if (child == null) {
    return null;
  }

  Query query = (Query) child
      .getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
  query.setBoost(boostNode.getValue());

  return query;

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:17,代碼來源:BoostQueryNodeBuilder.java

示例2: getQuery

import org.apache.lucene.search.Query; //導入方法依賴的package包/類
@Override
public Query getQuery(Element e) throws ParserException {
  String text = DOMUtils.getText(e);
  try {
    Query q = null;
    if (unSafeParser != null) {
      //synchronize on unsafe parser
      synchronized (unSafeParser) {
        q = unSafeParser.parse(text);
      }
    } else {
      String fieldName = DOMUtils.getAttribute(e, "fieldName", defaultField);
      //Create new parser
      QueryParser parser = createQueryParser(fieldName, analyzer);
      q = parser.parse(text);
    }
    q.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
    return q;
  } catch (ParseException e1) {
    throw new ParserException(e1.getMessage());
  }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:UserInputQueryBuilder.java

示例3: rewrite

import org.apache.lucene.search.Query; //導入方法依賴的package包/類
@Override
public Query rewrite(IndexReader reader) throws IOException {
    IndexReaderContext context = reader.getContext();
    TermContext[] ctx = new TermContext[terms.length];
    int[] docFreqs = new int[ctx.length];
    for (int i = 0; i < terms.length; i++) {
        ctx[i] = TermContext.build(context, terms[i]);
        docFreqs[i] = ctx[i].docFreq();
    }

    final int maxDoc = reader.maxDoc();
    blend(ctx, maxDoc, reader);
    Query query = topLevelQuery(terms, ctx, docFreqs, maxDoc);
    query.setBoost(getBoost());
    return query;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:17,代碼來源:BlendedTermQuery.java

示例4: rewrite

import org.apache.lucene.search.Query; //導入方法依賴的package包/類
@Override
public Query rewrite(IndexReader reader) throws IOException {
  final Query q = query.rewrite(reader);
  if (!(q instanceof SpanQuery))
    throw new UnsupportedOperationException("You can only use SpanMultiTermQueryWrapper with a suitable SpanRewriteMethod.");
  q.setBoost(q.getBoost() * getBoost()); // multiply boost
  return q;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:9,代碼來源:SpanMultiTermQueryWrapper.java

示例5: getQuery

import org.apache.lucene.search.Query; //導入方法依賴的package包/類
@Override
public Query getQuery(Element e) throws ParserException {
  Element filterElem = DOMUtils.getFirstChildOrFail(e);

  Query q = new ConstantScoreQuery(filterFactory.getFilter(filterElem));
  q.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
  return q;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:9,代碼來源:ConstantScoreQueryBuilder.java

示例6: newDefaultQuery

import org.apache.lucene.search.Query; //導入方法依賴的package包/類
/**
 * Factory method to generate a standard query (no phrase or prefix operators).
 */
protected Query newDefaultQuery(String text) {
  BooleanQuery bq = new BooleanQuery(true);
  for (Map.Entry<String,Float> entry : weights.entrySet()) {
    Query q = createBooleanQuery(entry.getKey(), text, defaultOperator);
    if (q != null) {
      q.setBoost(entry.getValue());
      bq.add(q, BooleanClause.Occur.SHOULD);
    }
  }
  return simplify(bq);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:15,代碼來源:SimpleQueryParser.java

示例7: newFuzzyQuery

import org.apache.lucene.search.Query; //導入方法依賴的package包/類
/**
 * Factory method to generate a fuzzy query.
 */
protected Query newFuzzyQuery(String text, int fuzziness) {
  BooleanQuery bq = new BooleanQuery(true);
  for (Map.Entry<String,Float> entry : weights.entrySet()) {
    Query q = new FuzzyQuery(new Term(entry.getKey(), text), fuzziness);
    if (q != null) {
      q.setBoost(entry.getValue());
      bq.add(q, BooleanClause.Occur.SHOULD);
    }
  }
  return simplify(bq);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:15,代碼來源:SimpleQueryParser.java

示例8: newPhraseQuery

import org.apache.lucene.search.Query; //導入方法依賴的package包/類
/**
 * Factory method to generate a phrase query with slop.
 */
protected Query newPhraseQuery(String text, int slop) {
  BooleanQuery bq = new BooleanQuery(true);
  for (Map.Entry<String,Float> entry : weights.entrySet()) {
    Query q = createPhraseQuery(entry.getKey(), text, slop);
    if (q != null) {
      q.setBoost(entry.getValue());
      bq.add(q, BooleanClause.Occur.SHOULD);
    }
  }
  return simplify(bq);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:15,代碼來源:SimpleQueryParser.java

示例9: makeLuceneQueryField

import org.apache.lucene.search.Query; //導入方法依賴的package包/類
public Query makeLuceneQueryField(String fieldName, BasicQueryFactory qf){
  Query q = makeLuceneQueryFieldNoBoost(fieldName, qf);
  if (isWeighted()) {
    q.setBoost(getWeight() * q.getBoost()); /* weight may be at any level in a SrndQuery */
  }
  return q;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:8,代碼來源:SrndQuery.java

示例10: parseAndApply

import org.apache.lucene.search.Query; //導入方法依賴的package包/類
private Query parseAndApply(Type type, String fieldName, Object value, String minimumShouldMatch, Float boostValue) throws IOException {
    Query query = parse(type, fieldName, value);
    // If the coordination factor is disabled on a boolean query we don't apply the minimum should match.
    // This is done to make sure that the minimum_should_match doesn't get applied when there is only one word
    // and multiple variations of the same word in the query (synonyms for instance).
    if (query instanceof BooleanQuery && !((BooleanQuery) query).isCoordDisabled()) {
        query = Queries.applyMinimumShouldMatch((BooleanQuery) query, minimumShouldMatch);
    }
    if (boostValue != null && query != null) {
        query.setBoost(boostValue);
    }
    return query;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:14,代碼來源:MultiMatchQuery.java

示例11: rewrite

import org.apache.lucene.search.Query; //導入方法依賴的package包/類
@Override
public Query rewrite(IndexReader reader) throws IOException {
    final Query childRewritten = childQuery.rewrite(reader);
    if (childRewritten != childQuery) {
        Query rewritten = new ChildrenQuery(ifd, parentType, childType, parentFilter, childRewritten, scoreType, minChildren, maxChildren, shortCircuitParentDocSet, nonNestedDocsFilter);
        rewritten.setBoost(getBoost());
        return rewritten;
    }
    return super.rewrite(reader);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:11,代碼來源:ChildrenQuery.java

示例12: rewrite

import org.apache.lucene.search.Query; //導入方法依賴的package包/類
@Override
public Query rewrite(IndexReader reader) throws IOException {
    Query parentRewritten = parentQuery.rewrite(reader);
    if (parentRewritten != parentQuery) {
        Query rewritten = new ParentQuery(parentChildIndexFieldData, parentRewritten, parentType, childrenFilter);
        rewritten.setBoost(getBoost());
        return rewritten;
    }
    return super.rewrite(reader);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:11,代碼來源:ParentQuery.java

示例13: rewrite

import org.apache.lucene.search.Query; //導入方法依賴的package包/類
@Override
public Query rewrite(IndexReader reader) throws IOException {
    Query parentRewritten = parentQuery.rewrite(reader);
    if (parentRewritten != parentQuery) {
        Query rewritten = new ParentConstantScoreQuery(parentChildIndexFieldData, parentRewritten, parentType, childrenFilter);
        rewritten.setBoost(getBoost());
        return rewritten;
    }
    return super.rewrite(reader);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:11,代碼來源:ParentConstantScoreQuery.java

示例14: applyBoost

import org.apache.lucene.search.Query; //導入方法依賴的package包/類
private void applyBoost(String field, Query q) {
    if (settings.boosts() != null) {
        float boost = settings.boosts().getOrDefault(field, 1f);
        q.setBoost(boost);
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:7,代碼來源:MapperQueryParser.java


注:本文中的org.apache.lucene.search.Query.setBoost方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。