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


Java ResponseBuilder.getQuery方法代码示例

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


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

示例1: prepare

import org.apache.solr.handler.component.ResponseBuilder; //导入方法依赖的package包/类
/**
 * Add boost terms to the query if it matches a know query.
 *
 * The query string is analyzed and compared to the known query strings
 * from the XML file. If a matching (i.e. equal) query string is found,
 * the associated terms (ConstantScoreQuery) are added: the original
 * query (object, not string) is added as a MUST term in a newly created
 * BooleanQuery, whereas the new terms are added either as Occur.SHOULD
 * for positive boost, or Occur.MUST_NOT for zero or negative boost.
 *
 * prepare() might trigger a reload of the XML file if it resides in
 * the data/ directory and the reader is new.
 *
 */
@Override
public final void prepare(final ResponseBuilder rb) {
    if (disabled(rb)) {
        return;
    }
    Query query = rb.getQuery();
    String queryStr = rb.getQueryString();
    if (query == null || queryStr == null) {
        return;
    }
    IndexReader reader = rb.req.getSearcher().getIndexReader();
    List<Query> boostTerms = null;
    try {
        queryStr = getAnalyzedQuery(queryStr);
        boostTerms = getQLTBMap(reader, rb.req.getCore()).get(queryStr);
        if (boostTerms == null || boostTerms.isEmpty()) {
            return;
        }
        log.debug(
            "QLTBComponent.prepare() query: \"" + queryStr + "\" with "
            + boostTerms.size() + " boost terms"
        );
    } catch (Exception ex) {
        throw new SolrException(
            SolrException.ErrorCode.SERVER_ERROR,
            "error loading QLTB",
            ex
        );
    }
    BooleanQuery newq = new BooleanQuery(true);
    newq.add(query, BooleanClause.Occur.MUST);
    for (Query term : boostTerms) {
        if (term.getBoost() > 0.0) {
            newq.add(new BooleanClause(term, BooleanClause.Occur.SHOULD));
        } else {
            newq.add(new BooleanClause(term, BooleanClause.Occur.MUST_NOT));
        }
    }
    rb.setQuery(newq);
}
 
开发者ID:solute,项目名称:qltb,代码行数:55,代码来源:QLTBComponent.java


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