use of org.apache.lucene.search.BooleanClause in project elasticsearch by elastic.
the class Queries method applyMinimumShouldMatch.
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;
}
}
use of org.apache.lucene.search.BooleanClause in project neo4j-mobile-android by neo4j-contrib.
the class FullTxData method injectOrphans.
private Query injectOrphans(Query query) {
if (query instanceof BooleanQuery) {
BooleanQuery source = (BooleanQuery) query;
BooleanQuery result = new BooleanQuery();
for (BooleanClause clause : source.clauses()) {
result.add(injectOrphans(clause.getQuery()), clause.getOccur());
}
return result;
} else {
BooleanQuery result = new BooleanQuery();
result.add(query, Occur.SHOULD);
result.add(new TermQuery(new Term(ORPHANS_KEY, extractTermField(query))), Occur.SHOULD);
return result;
}
}
use of org.apache.lucene.search.BooleanClause in project graphdb by neo4j-attic.
the class FullTxData method injectOrphans.
private Query injectOrphans(Query query) {
if (query instanceof BooleanQuery) {
BooleanQuery source = (BooleanQuery) query;
BooleanQuery result = new BooleanQuery();
for (BooleanClause clause : source.clauses()) {
result.add(injectOrphans(clause.getQuery()), clause.getOccur());
}
return result;
} else {
Set<Term> terms = new HashSet<Term>();
query.extractTerms(terms);
// TODO Don't only use the first term
Term term = terms.iterator().next();
BooleanQuery result = new BooleanQuery();
result.add(query, Occur.SHOULD);
result.add(new TermQuery(new Term(ORPHANS_KEY, term.field())), Occur.SHOULD);
return result;
}
}
use of org.apache.lucene.search.BooleanClause in project neo4j by neo4j.
the class FullTxData method injectOrphans.
private Query injectOrphans(Query query) {
if (query instanceof BooleanQuery) {
BooleanQuery source = (BooleanQuery) query;
BooleanQuery.Builder builder = new BooleanQuery.Builder();
for (BooleanClause clause : source.clauses()) {
builder.add(injectOrphans(clause.getQuery()), clause.getOccur());
}
return builder.build();
}
String orphanField = extractTermField(query);
if (orphanField == null) {
return query;
}
return new BooleanQuery.Builder().add(query, Occur.SHOULD).add(new TermQuery(new Term(ORPHANS_KEY, orphanField)), Occur.SHOULD).build();
}
use of org.apache.lucene.search.BooleanClause in project querydsl by querydsl.
the class LuceneSerializer method notIn.
protected Query notIn(Operation<?> operation, QueryMetadata metadata, boolean ignoreCase) {
BooleanQuery bq = new BooleanQuery();
bq.add(new BooleanClause(in(operation, metadata, false), Occur.MUST_NOT));
bq.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST));
return bq;
}
Aggregations