本文整理匯總了Java中org.apache.lucene.search.BooleanClause.getOccur方法的典型用法代碼示例。如果您正苦於以下問題:Java BooleanClause.getOccur方法的具體用法?Java BooleanClause.getOccur怎麽用?Java BooleanClause.getOccur使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.lucene.search.BooleanClause
的用法示例。
在下文中一共展示了BooleanClause.getOccur方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: applyMinimumShouldMatch
import org.apache.lucene.search.BooleanClause; //導入方法依賴的package包/類
public static Query applyMinimumShouldMatch(BooleanQuery query, @Nullable String minimumShouldMatch) {
if (minimumShouldMatch == null) {
return query;
}
int optionalClauses = 0;
for (BooleanClause c : query.clauses()) {
if (c.getOccur() == BooleanClause.Occur.SHOULD) {
optionalClauses++;
}
}
int msm = calculateMinShouldMatch(optionalClauses, minimumShouldMatch);
if (0 < msm) {
BooleanQuery.Builder builder = new BooleanQuery.Builder();
builder.setDisableCoord(query.isCoordDisabled());
for (BooleanClause clause : query) {
builder.add(clause);
}
builder.setMinimumNumberShouldMatch(msm);
return builder.build();
} else {
return query;
}
}
示例2: shouldClauses
import org.apache.lucene.search.BooleanClause; //導入方法依賴的package包/類
private static int shouldClauses(BooleanQuery query) {
int result = 0;
for (BooleanClause c : query.clauses()) {
if (c.getOccur() == BooleanClause.Occur.SHOULD) {
result++;
}
}
return result;
}
示例3: rewriteQuery
import org.apache.lucene.search.BooleanClause; //導入方法依賴的package包/類
/**
* @param q parsed Lucene query string query
* @return a rewritten query with nested queries for custom properties (when in nested mode)
*/
private static QueryBuilder rewriteQuery(Query q, int depth) throws IllegalAccessException {
if (depth > MAX_QUERY_DEPTH) {
throw new IllegalArgumentException("`Query depth exceeded! Max depth: " + MAX_QUERY_DEPTH);
}
QueryBuilder qb = null;
if (q instanceof BooleanQuery) {
qb = boolQuery();
for (BooleanClause clause : ((BooleanQuery) q).clauses()) {
switch (clause.getOccur()) {
case MUST:
((BoolQueryBuilder) qb).must(rewriteQuery(clause.getQuery(), depth++));
break;
case MUST_NOT:
((BoolQueryBuilder) qb).mustNot(rewriteQuery(clause.getQuery(), depth++));
break;
case FILTER:
((BoolQueryBuilder) qb).filter(rewriteQuery(clause.getQuery(), depth++));
break;
case SHOULD:
default:
((BoolQueryBuilder) qb).should(rewriteQuery(clause.getQuery(), depth++));
}
}
} else if (q instanceof TermRangeQuery) {
qb = termRange(q);
} else if (q instanceof BoostQuery) {
qb = rewriteQuery(((BoostQuery) q).getQuery(), depth++).boost(((BoostQuery) q).getBoost());
} else if (q instanceof TermQuery) {
qb = term(q);
} else if (q instanceof FuzzyQuery) {
qb = fuzzy(q);
} else if (q instanceof PrefixQuery) {
qb = prefix(q);
} else if (q instanceof WildcardQuery) {
qb = wildcard(q);
} else {
logger.warn("Unknown query type in nested mode query syntax: {}", q.getClass());
}
return (qb == null) ? matchAllQuery() : qb;
}