Search in sources :

Example 16 with BooleanClause

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;
    }
}
Also used : BooleanClause(org.apache.lucene.search.BooleanClause) BooleanQuery(org.apache.lucene.search.BooleanQuery)

Example 17 with BooleanClause

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;
    }
}
Also used : BooleanClause(org.apache.lucene.search.BooleanClause) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermQuery(org.apache.lucene.search.TermQuery) Term(org.apache.lucene.index.Term)

Example 18 with BooleanClause

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;
    }
}
Also used : BooleanClause(org.apache.lucene.search.BooleanClause) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermQuery(org.apache.lucene.search.TermQuery) Term(org.apache.lucene.index.Term) HashSet(java.util.HashSet)

Example 19 with BooleanClause

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();
}
Also used : BooleanClause(org.apache.lucene.search.BooleanClause) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermQuery(org.apache.lucene.search.TermQuery) Term(org.apache.lucene.index.Term)

Example 20 with BooleanClause

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;
}
Also used : BooleanClause(org.apache.lucene.search.BooleanClause) BooleanQuery(org.apache.lucene.search.BooleanQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery)

Aggregations

BooleanClause (org.apache.lucene.search.BooleanClause)102 BooleanQuery (org.apache.lucene.search.BooleanQuery)92 Query (org.apache.lucene.search.Query)56 TermQuery (org.apache.lucene.search.TermQuery)46 Term (org.apache.lucene.index.Term)44 BoostQuery (org.apache.lucene.search.BoostQuery)33 ArrayList (java.util.ArrayList)23 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)21 PhraseQuery (org.apache.lucene.search.PhraseQuery)20 DisjunctionMaxQuery (org.apache.lucene.search.DisjunctionMaxQuery)19 SynonymQuery (org.apache.lucene.search.SynonymQuery)18 SpanOrQuery (org.apache.lucene.search.spans.SpanOrQuery)18 SpanNearQuery (org.apache.lucene.search.spans.SpanNearQuery)17 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)16 SpanQuery (org.apache.lucene.search.spans.SpanQuery)15 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)14 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)14 WildcardQuery (org.apache.lucene.search.WildcardQuery)14 MultiPhraseQuery (org.apache.lucene.search.MultiPhraseQuery)13 PrefixQuery (org.apache.lucene.search.PrefixQuery)13