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


Java BoostingQuery.setBoost方法代码示例

本文整理汇总了Java中org.apache.lucene.queries.BoostingQuery.setBoost方法的典型用法代码示例。如果您正苦于以下问题:Java BoostingQuery.setBoost方法的具体用法?Java BoostingQuery.setBoost怎么用?Java BoostingQuery.setBoost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.queries.BoostingQuery的用法示例。


在下文中一共展示了BoostingQuery.setBoost方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getQuery

import org.apache.lucene.queries.BoostingQuery; //导入方法依赖的package包/类
@Override
public Query getQuery(Element e) throws ParserException {
  Element mainQueryElem = DOMUtils.getChildByTagOrFail(e, "Query");
  mainQueryElem = DOMUtils.getFirstChildOrFail(mainQueryElem);
  Query mainQuery = factory.getQuery(mainQueryElem);

  Element boostQueryElem = DOMUtils.getChildByTagOrFail(e, "BoostQuery");
  float boost = DOMUtils.getAttribute(boostQueryElem, "boost", DEFAULT_BOOST);
  boostQueryElem = DOMUtils.getFirstChildOrFail(boostQueryElem);
  Query boostQuery = factory.getQuery(boostQueryElem);

  BoostingQuery bq = new BoostingQuery(mainQuery, boostQuery, boost);

  bq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
  return bq;

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:BoostingQueryBuilder.java

示例2: parse

import org.apache.lucene.queries.BoostingQuery; //导入方法依赖的package包/类
@Override
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
    XContentParser parser = parseContext.parser();

    Query positiveQuery = null;
    boolean positiveQueryFound = false;
    Query negativeQuery = null;
    boolean negativeQueryFound = false;
    float boost = -1;
    float negativeBoost = -1;

    String currentFieldName = null;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.START_OBJECT) {
            if ("positive".equals(currentFieldName)) {
                positiveQuery = parseContext.parseInnerQuery();
                positiveQueryFound = true;
            } else if ("negative".equals(currentFieldName)) {
                negativeQuery = parseContext.parseInnerQuery();
                negativeQueryFound = true;
            } else {
                throw new QueryParsingException(parseContext, "[boosting] query does not support [" + currentFieldName + "]");
            }
        } else if (token.isValue()) {
            if ("negative_boost".equals(currentFieldName) || "negativeBoost".equals(currentFieldName)) {
                negativeBoost = parser.floatValue();
            } else if ("boost".equals(currentFieldName)) {
                boost = parser.floatValue();
            } else {
                throw new QueryParsingException(parseContext, "[boosting] query does not support [" + currentFieldName + "]");
            }
        }
    }

    if (positiveQuery == null && !positiveQueryFound) {
        throw new QueryParsingException(parseContext, "[boosting] query requires 'positive' query to be set'");
    }
    if (negativeQuery == null && !negativeQueryFound) {
        throw new QueryParsingException(parseContext, "[boosting] query requires 'negative' query to be set'");
    }
    if (negativeBoost == -1) {
        throw new QueryParsingException(parseContext, "[boosting] query requires 'negative_boost' to be set'");
    }

    // parsers returned null
    if (positiveQuery == null || negativeQuery == null) {
        return null;
    }

    BoostingQuery boostingQuery = new BoostingQuery(positiveQuery, negativeQuery, negativeBoost);
    if (boost != -1) {
        boostingQuery.setBoost(boost);
    }
    return boostingQuery;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:59,代码来源:BoostingQueryParser.java


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