Search in sources :

Example 26 with BooleanQuery

use of org.apache.lucene.search.BooleanQuery 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 27 with BooleanQuery

use of org.apache.lucene.search.BooleanQuery in project querydsl by querydsl.

the class LuceneSerializer method toTwoHandSidedQuery.

private Query toTwoHandSidedQuery(Operation<?> operation, Occur occur, QueryMetadata metadata) {
    Query lhs = toQuery(operation.getArg(0), metadata);
    Query rhs = toQuery(operation.getArg(1), metadata);
    BooleanQuery bq = new BooleanQuery();
    bq.add(createBooleanClause(lhs, occur));
    bq.add(createBooleanClause(rhs, occur));
    return bq;
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) Query(org.apache.lucene.search.Query) NumericRangeQuery(org.apache.lucene.search.NumericRangeQuery) PhraseQuery(org.apache.lucene.search.PhraseQuery) PrefixQuery(org.apache.lucene.search.PrefixQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery)

Example 28 with BooleanQuery

use of org.apache.lucene.search.BooleanQuery 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)

Example 29 with BooleanQuery

use of org.apache.lucene.search.BooleanQuery in project querydsl by querydsl.

the class LuceneSerializer method ne.

protected Query ne(Operation<?> operation, QueryMetadata metadata, boolean ignoreCase) {
    BooleanQuery bq = new BooleanQuery();
    bq.add(new BooleanClause(eq(operation, metadata, ignoreCase), 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)

Example 30 with BooleanQuery

use of org.apache.lucene.search.BooleanQuery in project querydsl by querydsl.

the class LuceneSerializer method endsWith.

protected Query endsWith(Operation<?> operation, QueryMetadata metadata, boolean ignoreCase) {
    verifyArguments(operation);
    Path<?> path = getPath(operation.getArg(0));
    String field = toField(path);
    String[] terms = convertEscaped(path, operation.getArg(1), metadata);
    if (terms.length > 1) {
        BooleanQuery bq = new BooleanQuery();
        for (int i = 0; i < terms.length; ++i) {
            String s = i == terms.length - 1 ? "*" + terms[i] : "*" + terms[i] + "*";
            bq.add(new WildcardQuery(new Term(field, s)), Occur.MUST);
        }
        return bq;
    }
    return new WildcardQuery(new Term(field, "*" + terms[0]));
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) Term(org.apache.lucene.index.Term)

Aggregations

BooleanQuery (org.apache.lucene.search.BooleanQuery)218 TermQuery (org.apache.lucene.search.TermQuery)132 Term (org.apache.lucene.index.Term)114 Query (org.apache.lucene.search.Query)91 BooleanClause (org.apache.lucene.search.BooleanClause)59 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)52 BoostQuery (org.apache.lucene.search.BoostQuery)49 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)45 PhraseQuery (org.apache.lucene.search.PhraseQuery)43 PrefixQuery (org.apache.lucene.search.PrefixQuery)39 TopDocs (org.apache.lucene.search.TopDocs)38 IndexReader (org.apache.lucene.index.IndexReader)37 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)34 IndexSearcher (org.apache.lucene.search.IndexSearcher)33 WildcardQuery (org.apache.lucene.search.WildcardQuery)32 Document (org.apache.lucene.document.Document)30 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)28 ArrayList (java.util.ArrayList)27 SpanNearQuery (org.apache.lucene.search.spans.SpanNearQuery)27 DisjunctionMaxQuery (org.apache.lucene.search.DisjunctionMaxQuery)26