use of org.apache.lucene.search.BooleanClause 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;
}
use of org.apache.lucene.search.BooleanClause in project zm-mailbox by Zimbra.
the class LuceneQueryOperation method fixMustNotOnly.
/**
* It is not possible to search for queries that only consist of a MUST_NOT clause. Combining with MatchAllDocsQuery
* works in general, but we generate more than one documents per item for multipart messages. If we match including
* non top level parts, negative queries will end up matching everything. Therefore we only match the top level part
* for negative queries.
*/
private void fixMustNotOnly(BooleanQuery query) {
for (BooleanClause clause : query.clauses()) {
if (clause.getQuery() instanceof BooleanQuery) {
fixMustNotOnly((BooleanQuery) clause.getQuery());
}
if (clause.getOccur() != BooleanClause.Occur.MUST_NOT) {
return;
}
}
query.add(new TermQuery(new Term(LuceneFields.L_PARTNAME, LuceneFields.L_PARTNAME_TOP)), BooleanClause.Occur.SHOULD);
Set<MailItem.Type> types = context.getParams().getTypes();
if (types.contains(MailItem.Type.CONTACT)) {
query.add(new TermQuery(new Term(LuceneFields.L_PARTNAME, LuceneFields.L_PARTNAME_CONTACT)), BooleanClause.Occur.SHOULD);
}
if (types.contains(MailItem.Type.NOTE)) {
query.add(new TermQuery(new Term(LuceneFields.L_PARTNAME, LuceneFields.L_PARTNAME_NOTE)), BooleanClause.Occur.SHOULD);
}
}
use of org.apache.lucene.search.BooleanClause in project zm-mailbox by Zimbra.
the class LuceneQueryOperation method combineOps.
@Override
protected QueryOperation combineOps(QueryOperation other, boolean union) {
assert (!haveRunSearch);
if (union) {
if (other.hasNoResults()) {
queryInfo.addAll(other.getResultInfo());
// a query for (other OR nothing) == other
return this;
}
} else {
if (other.hasAllResults()) {
if (other.hasSpamTrashSetting()) {
forceHasSpamTrashSetting();
}
queryInfo.addAll(other.getResultInfo());
// we match all results. (other AND anything) == other
return this;
}
}
if (other instanceof LuceneQueryOperation) {
LuceneQueryOperation otherLucene = (LuceneQueryOperation) other;
if (union) {
queryString = '(' + queryString + ") OR (" + otherLucene.queryString + ')';
} else {
queryString = '(' + queryString + ") AND (" + otherLucene.queryString + ')';
}
BooleanQuery top = new BooleanQuery();
if (union) {
if (luceneQuery instanceof BooleanQuery) {
orCopy((BooleanQuery) luceneQuery, top);
} else {
top.add(new BooleanClause(luceneQuery, Occur.SHOULD));
}
if (otherLucene.luceneQuery instanceof BooleanQuery) {
orCopy((BooleanQuery) otherLucene.luceneQuery, top);
} else {
top.add(new BooleanClause(otherLucene.luceneQuery, Occur.SHOULD));
}
} else {
if (luceneQuery instanceof BooleanQuery) {
andCopy((BooleanQuery) luceneQuery, top);
} else {
top.add(new BooleanClause(luceneQuery, Occur.MUST));
}
if (otherLucene.luceneQuery instanceof BooleanQuery) {
andCopy((BooleanQuery) otherLucene.luceneQuery, top);
} else {
top.add(new BooleanClause(otherLucene.luceneQuery, Occur.MUST));
}
}
luceneQuery = top;
queryInfo.addAll(other.getResultInfo());
if (other.hasSpamTrashSetting()) {
forceHasSpamTrashSetting();
}
return this;
}
return null;
}
use of org.apache.lucene.search.BooleanClause in project incubator-atlas by apache.
the class BooleanQueryExpression method processAndClauses.
private Collection<Pipe> processAndClauses(Map<BooleanClause.Occur, Collection<BooleanClause>> groupedClauses) {
Collection<BooleanClause> andClauses = groupedClauses.get(BooleanClause.Occur.MUST);
Collection<Pipe> andPipes = new ArrayList<>();
if (andClauses != null) {
for (BooleanClause andClause : andClauses) {
QueryExpression queryExpression = queryFactory.create(andClause.getQuery(), resourceDefinition);
properties.addAll(queryExpression.getProperties());
andPipes.add(queryExpression.asPipe());
}
}
return andPipes;
}
use of org.apache.lucene.search.BooleanClause in project incubator-atlas by apache.
the class BooleanQueryExpression method processNotClauses.
private Collection<Pipe> processNotClauses(Map<BooleanClause.Occur, Collection<BooleanClause>> groupedClauses) {
Collection<BooleanClause> notClauses = groupedClauses.get(BooleanClause.Occur.MUST_NOT);
Collection<Pipe> notPipes = new ArrayList<>();
if (notClauses != null) {
for (BooleanClause notClause : notClauses) {
QueryExpression queryExpression = queryFactory.create(notClause.getQuery(), resourceDefinition);
queryExpression.setNegate();
properties.addAll(queryExpression.getProperties());
notPipes.add(queryExpression.asPipe());
}
}
return notPipes;
}
Aggregations