本文整理匯總了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;
}