• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java BoostingQuery类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



BoostingQuery类属于org.apache.lucene.queries包,在下文中一共展示了BoostingQuery类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: doAssertLuceneQuery

import org.apache.lucene.queries.BoostingQuery; //导入依赖的package包/类
@Override
protected void doAssertLuceneQuery(BoostingQueryBuilder queryBuilder, Query query, SearchContext context) throws IOException {
    Query positive = queryBuilder.positiveQuery().toQuery(context.getQueryShardContext());
    Query negative = queryBuilder.negativeQuery().toQuery(context.getQueryShardContext());
    if (positive == null || negative == null) {
        assertThat(query, nullValue());
    } else {
        assertThat(query, instanceOf(BoostingQuery.class));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:BoostingQueryBuilderTests.java


示例3: flatten

import org.apache.lucene.queries.BoostingQuery; //导入依赖的package包/类
@Override
void flatten(Query sourceQuery, IndexReader reader, Collection<Query> flatQueries, float boost) throws IOException {
    if (sourceQuery instanceof BoostQuery) {
        BoostQuery bq = (BoostQuery) sourceQuery;
        sourceQuery = bq.getQuery();
        boost *= bq.getBoost();
        flatten(sourceQuery, reader, flatQueries, boost);
    } else if (sourceQuery instanceof SpanTermQuery) {
        super.flatten(new TermQuery(((SpanTermQuery) sourceQuery).getTerm()), reader, flatQueries, boost);
    } else if (sourceQuery instanceof ConstantScoreQuery) {
        flatten(((ConstantScoreQuery) sourceQuery).getQuery(), reader, flatQueries, boost);
    } else if (sourceQuery instanceof FunctionScoreQuery) {
        flatten(((FunctionScoreQuery) sourceQuery).getSubQuery(), reader, flatQueries, boost);
    } else if (sourceQuery instanceof MultiPhrasePrefixQuery) {
        flatten(sourceQuery.rewrite(reader), reader, flatQueries, boost);
    } else if (sourceQuery instanceof FiltersFunctionScoreQuery) {
        flatten(((FiltersFunctionScoreQuery) sourceQuery).getSubQuery(), reader, flatQueries, boost);
    } else if (sourceQuery instanceof MultiPhraseQuery) {
        MultiPhraseQuery q = ((MultiPhraseQuery) sourceQuery);
        convertMultiPhraseQuery(0, new int[q.getTermArrays().length], q, q.getTermArrays(), q.getPositions(), reader, flatQueries);
    } else if (sourceQuery instanceof BlendedTermQuery) {
        final BlendedTermQuery blendedTermQuery = (BlendedTermQuery) sourceQuery;
        flatten(blendedTermQuery.rewrite(reader), reader, flatQueries, boost);
    } else if (sourceQuery instanceof ESToParentBlockJoinQuery) {
        ESToParentBlockJoinQuery blockJoinQuery = (ESToParentBlockJoinQuery) sourceQuery;
        flatten(blockJoinQuery.getChildQuery(), reader, flatQueries, boost);
    } else if (sourceQuery instanceof BoostingQuery) {
        BoostingQuery boostingQuery = (BoostingQuery) sourceQuery;
        //flatten positive query with query boost
        flatten(boostingQuery.getMatch(), reader, flatQueries, boost);
        //flatten negative query with negative boost
        flatten(boostingQuery.getContext(), reader, flatQueries, boostingQuery.getBoost());
    } else if (sourceQuery instanceof SynonymQuery) {
        // SynonymQuery should be handled by the parent class directly.
        // This statement should be removed when https://issues.apache.org/jira/browse/LUCENE-7484 is merged.
        SynonymQuery synQuery = (SynonymQuery) sourceQuery;
        for (Term term : synQuery.getTerms()) {
            flatten(new TermQuery(term), reader, flatQueries, boost);
        }
    } else {
        super.flatten(sourceQuery, reader, flatQueries, boost);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:44,代码来源:CustomFieldQuery.java


示例4: doToQuery

import org.apache.lucene.queries.BoostingQuery; //导入依赖的package包/类
@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
    Query positive = positiveQuery.toQuery(context);
    Query negative = negativeQuery.toQuery(context);
    return new BoostingQuery(positive, negative, negativeBoost);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:7,代码来源:BoostingQueryBuilder.java


示例5: 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类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CrossStateTransition类代码示例发布时间:2022-05-23
下一篇:
Java BOBYQAOptimizer类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap