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