本文整理汇总了Java中org.apache.lucene.search.BooleanQuery.setBoost方法的典型用法代码示例。如果您正苦于以下问题:Java BooleanQuery.setBoost方法的具体用法?Java BooleanQuery.setBoost怎么用?Java BooleanQuery.setBoost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.search.BooleanQuery
的用法示例。
在下文中一共展示了BooleanQuery.setBoost方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getQuery
import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
@Override
public Query getQuery(Element e) throws ParserException {
BooleanQuery bq = new BooleanQuery(DOMUtils.getAttribute(e, "disableCoord", false));
bq.setMinimumNumberShouldMatch(DOMUtils.getAttribute(e, "minimumNumberShouldMatch", 0));
bq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
NodeList nl = e.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node.getNodeName().equals("Clause")) {
Element clauseElem = (Element) node;
BooleanClause.Occur occurs = getOccursValue(clauseElem);
Element clauseQuery = DOMUtils.getFirstChildOrFail(clauseElem);
Query q = factory.getQuery(clauseQuery);
bq.add(new BooleanClause(q, occurs));
}
}
return bq;
}
示例2: parse
import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
@Override
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
deprecationLogger.deprecated("The [filtered] query is deprecated, please use a [bool] query instead with a [must] "
+ "clause for the query part and a [filter] clause for the filter part.");
XContentParser parser = parseContext.parser();
Query query = Queries.newMatchAllQuery();
Query filter = null;
boolean filterFound = false;
float boost = 1.0f;
String queryName = null;
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 (parseContext.isDeprecatedSetting(currentFieldName)) {
// skip
} else if (token == XContentParser.Token.START_OBJECT) {
if ("query".equals(currentFieldName)) {
query = parseContext.parseInnerQuery();
} else if ("filter".equals(currentFieldName)) {
filterFound = true;
filter = parseContext.parseInnerFilter();
} else {
throw new QueryParsingException(parseContext, "[filtered] query does not support [" + currentFieldName + "]");
}
} else if (token.isValue()) {
if ("strategy".equals(currentFieldName)) {
// ignore
} else if ("_name".equals(currentFieldName)) {
queryName = parser.text();
} else if ("boost".equals(currentFieldName)) {
boost = parser.floatValue();
} else {
throw new QueryParsingException(parseContext, "[filtered] query does not support [" + currentFieldName + "]");
}
}
}
// parsed internally, but returned null during parsing...
if (query == null) {
return null;
}
BooleanQuery filteredQuery = Queries.filtered(query, filter);
filteredQuery.setBoost(boost);
if (queryName != null) {
parseContext.addNamedQuery(queryName, filteredQuery);
}
return filteredQuery;
}