Search in sources :

Example 1 with LuceneQueryOperation

use of com.zimbra.cs.index.LuceneQueryOperation in project zm-mailbox by Zimbra.

the class DomainQuery method compile.

@Override
public QueryOperation compile(Mailbox mbox, boolean bool) {
    LuceneQueryOperation op = new LuceneQueryOperation();
    op.addClause(toQueryString(field, term), new TermQuery(new Term(field, term)), evalBool(bool));
    return op;
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) LuceneQueryOperation(com.zimbra.cs.index.LuceneQueryOperation) Term(org.apache.lucene.index.Term)

Example 2 with LuceneQueryOperation

use of com.zimbra.cs.index.LuceneQueryOperation in project zm-mailbox by Zimbra.

the class TextQuery method compile.

@Override
public QueryOperation compile(Mailbox mbox, boolean bool) throws ServiceException {
    if (quick || text.endsWith("*")) {
        // wildcard, must look at original text here b/c analyzer strips *'s
        // only the last token is allowed to have a wildcard in it
        String last = tokens.isEmpty() ? text : tokens.remove(tokens.size() - 1);
        LuceneQueryOperation.LazyMultiPhraseQuery query = new LuceneQueryOperation.LazyMultiPhraseQuery();
        for (String token : tokens) {
            query.add(new Term(field, token));
        }
        // expand later
        query.expand(new Term(field, CharMatcher.is('*').trimTrailingFrom(last)));
        LuceneQueryOperation op = new LuceneQueryOperation();
        op.addClause(toQueryString(field, text), query, evalBool(bool));
        return op;
    } else if (tokens.isEmpty()) {
        // a stop word like "a" or "an" or "the".
        return new NoTermQueryOperation();
    } else if (tokens.size() == 1) {
        LuceneQueryOperation op = new LuceneQueryOperation();
        op.addClause(toQueryString(field, text), new TermQuery(new Term(field, tokens.get(0))), evalBool(bool));
        return op;
    } else {
        assert tokens.size() > 1 : tokens.size();
        PhraseQuery query = new PhraseQuery();
        for (String token : tokens) {
            query.add(new Term(field, token));
        }
        LuceneQueryOperation op = new LuceneQueryOperation();
        op.addClause(toQueryString(field, text), query, evalBool(bool));
        return op;
    }
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) PhraseQuery(org.apache.lucene.search.PhraseQuery) LuceneQueryOperation(com.zimbra.cs.index.LuceneQueryOperation) Term(org.apache.lucene.index.Term) NoTermQueryOperation(com.zimbra.cs.index.NoTermQueryOperation)

Example 3 with LuceneQueryOperation

use of com.zimbra.cs.index.LuceneQueryOperation in project zm-mailbox by Zimbra.

the class LuceneQuery method compile.

@Override
public QueryOperation compile(Mailbox mbox, boolean bool) {
    LuceneQueryOperation op = new LuceneQueryOperation();
    op.addClause(queryField + term, new TermQuery(new Term(luceneField, term)), evalBool(bool));
    return op;
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) LuceneQueryOperation(com.zimbra.cs.index.LuceneQueryOperation) Term(org.apache.lucene.index.Term)

Aggregations

LuceneQueryOperation (com.zimbra.cs.index.LuceneQueryOperation)3 Term (org.apache.lucene.index.Term)3 TermQuery (org.apache.lucene.search.TermQuery)3 NoTermQueryOperation (com.zimbra.cs.index.NoTermQueryOperation)1 PhraseQuery (org.apache.lucene.search.PhraseQuery)1