本文整理汇总了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);
}