Java Code Examples for org.elasticsearch.common.lucene.search.Queries

The following examples show how to use org.elasticsearch.common.lucene.search.Queries. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Elasticsearch   Source File: LuceneQueryBuilder.java    License: Apache License 2.0 6 votes vote down vote up
public Context convert(WhereClause whereClause,
                       MapperService mapperService,
                       IndexFieldDataService indexFieldDataService,
                       IndexCache indexCache) throws UnsupportedFeatureException {
    Context ctx = new Context(inputSymbolVisitor, mapperService, indexFieldDataService, indexCache);
    if (whereClause.noMatch()) {
        ctx.query = Queries.newMatchNoDocsQuery();
    } else if (!whereClause.hasQuery()) {
        ctx.query = Queries.newMatchAllQuery();
    } else {
        ctx.query = VISITOR.process(whereClause.query(), ctx);
    }
    if (LOGGER.isTraceEnabled()) {
        if (whereClause.hasQuery()) {
            LOGGER.trace("WHERE CLAUSE [{}] -> LUCENE QUERY [{}] ", SymbolPrinter.INSTANCE.printSimple(whereClause.query()), ctx.query);
        }
    }
    return ctx;
}
 
Example 2
Source Project: Elasticsearch   Source File: QueryCollector.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void collect(int doc) throws IOException {
    final Query query = getQuery(doc);
    if (query == null) {
        // log???
        return;
    }
    Query existsQuery = query;
    if (isNestedDoc) {
        existsQuery = new BooleanQuery.Builder()
            .add(existsQuery, Occur.MUST)
            .add(Queries.newNonNestedFilter(), Occur.FILTER)
            .build();
    }
    // run the query
    try {
        if (Lucene.exists(searcher, existsQuery)) {
            topDocsLeafCollector.collect(doc);
            postMatch(doc);
        }
    } catch (IOException e) {
        logger.warn("[" + current.utf8ToString() + "] failed to execute query", e);
    }
}
 
Example 3
Source Project: Elasticsearch   Source File: QueryCollector.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void collect(int doc) throws IOException {
    final Query query = getQuery(doc);
    if (query == null) {
        // log???
        return;
    }
    Query existsQuery = query;
    if (isNestedDoc) {
        existsQuery = new BooleanQuery.Builder()
            .add(existsQuery, Occur.MUST)
            .add(Queries.newNonNestedFilter(), Occur.FILTER)
            .build();
    }
    // run the query
    try {
        if (Lucene.exists(searcher, existsQuery)) {
            counter++;
            postMatch(doc);
        }
    } catch (IOException e) {
        logger.warn("[" + current.utf8ToString() + "] failed to execute query", e);
    }
}
 
Example 4
Source Project: Elasticsearch   Source File: PercolatorService.java    License: Apache License 2.0 6 votes vote down vote up
private void queryBasedPercolating(Engine.Searcher percolatorSearcher, PercolateContext context, QueryCollector percolateCollector) throws IOException {
    Query percolatorTypeFilter = context.indexService().mapperService().documentMapper(TYPE_NAME).typeFilter();

    final Query filter;
    if (context.aliasFilter() != null) {
        BooleanQuery.Builder booleanFilter = new BooleanQuery.Builder();
        booleanFilter.add(context.aliasFilter(), BooleanClause.Occur.MUST);
        booleanFilter.add(percolatorTypeFilter, BooleanClause.Occur.MUST);
        filter = booleanFilter.build();
    } else {
        filter = percolatorTypeFilter;
    }

    Query query = Queries.filtered(context.percolateQuery(), filter);
    percolatorSearcher.searcher().search(query, percolateCollector);
    percolateCollector.aggregatorCollector.postCollection();
    if (context.aggregations() != null) {
        aggregationPhase.execute(context);
    }
}
 
Example 5
Source Project: elasticsearch-image   Source File: ImageHashLimitQuery.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Weight createWeight(IndexSearcher searcher) throws IOException {
    IndexSearcher indexSearcher = new IndexSearcher(searcher.getIndexReader());
    indexSearcher.setSimilarity(new SimpleSimilarity());

    BooleanQuery booleanQuery = new BooleanQuery();
    for (int h : hashes) {
        booleanQuery.add(new BooleanClause(new TermQuery(new Term(hashFieldName, Integer.toString(h))), BooleanClause.Occur.SHOULD));
    }
    TopDocs topDocs = indexSearcher.search(booleanQuery, maxResult);

    if (topDocs.scoreDocs.length == 0) {  // no result find
        return Queries.newMatchNoDocsQuery().createWeight(searcher);
    }

    BitSet bitSet = new BitSet(topDocs.scoreDocs.length);
    for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
        bitSet.set(scoreDoc.doc);
    }

    return new ImageHashLimitWeight(searcher, bitSet);
}
 
Example 6
Source Project: crate   Source File: NumberFieldMapper.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Query termsQuery(String field, List<Object> values) {
    int[] v = new int[values.size()];
    int upTo = 0;

    for (int i = 0; i < values.size(); i++) {
        Object value = values.get(i);
        if (!hasDecimalPart(value)) {
            v[upTo++] = parse(value, true);
        }
    }

    if (upTo == 0) {
        return Queries.newMatchNoDocsQuery("All values have a decimal part");
    }
    if (upTo != v.length) {
        v = Arrays.copyOf(v, upTo);
    }
    return IntPoint.newSetQuery(field, v);
}
 
Example 7
Source Project: crate   Source File: NumberFieldMapper.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Query termsQuery(String field, List<Object> values) {
    long[] v = new long[values.size()];
    int upTo = 0;

    for (int i = 0; i < values.size(); i++) {
        Object value = values.get(i);
        if (!hasDecimalPart(value)) {
            v[upTo++] = parse(value, true);
        }
    }

    if (upTo == 0) {
        return Queries.newMatchNoDocsQuery("All values have a decimal part");
    }
    if (upTo != v.length) {
        v = Arrays.copyOf(v, upTo);
    }
    return LongPoint.newSetQuery(field, v);
}
 
Example 8
Source Project: crate   Source File: LuceneQueryBuilder.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Query visitLiteral(Literal literal, Context context) {
    Object value = literal.value();
    if (value == null) {
        return Queries.newMatchNoDocsQuery("WHERE null -> no match");
    }
    try {
        return (boolean) value
            ? Queries.newMatchAllQuery()
            : Queries.newMatchNoDocsQuery("WHERE false -> no match");
    } catch (ClassCastException e) {
        // Throw a nice error if the top-level literal doesn't have a boolean type
        // (This is currently caught earlier, so this code is just a safe-guard)
        return visitSymbol(literal, context);
    }
}
 
Example 9
Source Project: crate   Source File: AnyNeqQuery.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Query literalMatchesAnyArrayRef(Literal candidate, Reference array, LuceneQueryBuilder.Context context) throws IOException {
    // 1 != any ( col ) -->  gt 1 or lt 1
    String columnName = array.column().fqn();
    Object value = candidate.value();

    MappedFieldType fieldType = context.getFieldTypeOrNull(columnName);
    if (fieldType == null) {
        return Queries.newMatchNoDocsQuery("column does not exist in this index");
    }
    BooleanQuery.Builder query = new BooleanQuery.Builder();
    query.setMinimumNumberShouldMatch(1);
    query.add(
        fieldType.rangeQuery(value, null, false, false, null, null, context.queryShardContext),
        BooleanClause.Occur.SHOULD
    );
    query.add(
        fieldType.rangeQuery(null, value, false, false, null, null, context.queryShardContext),
        BooleanClause.Occur.SHOULD
    );
    return query.build();
}
 
Example 10
Source Project: crate   Source File: AnyEqQuery.java    License: Apache License 2.0 6 votes vote down vote up
private static Query literalMatchesAnyArrayRef(Function any,
                                               Literal candidate,
                                               Reference array,
                                               LuceneQueryBuilder.Context context) {
    MappedFieldType fieldType = context.getFieldTypeOrNull(array.column().fqn());
    if (fieldType == null) {
        if (ArrayType.unnest(array.valueType()).id() == ObjectType.ID) {
            return genericFunctionFilter(any, context); // {x=10} = any(objects)
        }
        return Queries.newMatchNoDocsQuery("column doesn't exist in this index");
    }
    if (DataTypes.isArray(candidate.valueType())) {
        return arrayLiteralEqAnyArray(any, fieldType, candidate.value(), context);
    }
    return fieldType.termQuery(candidate.value(), context.queryShardContext());
}
 
Example 11
Source Project: Elasticsearch   Source File: MatchQueryBuilder.java    License: Apache License 2.0 5 votes vote down vote up
protected Query singleQueryAndApply(MatchQuery.Type type,
                                    String fieldName,
                                    BytesRef queryString,
                                    Float boost) {
    Query query = singleQuery(type, fieldName, queryString);
    if (query instanceof BooleanQuery) {
        Queries.applyMinimumShouldMatch((BooleanQuery) query, options.minimumShouldMatch());
    }
    if (boost != null && query != null) {
        query.setBoost(boost);
    }
    return query;
}
 
Example 12
Source Project: Elasticsearch   Source File: LuceneQueryBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Query applyArrayLiteral(Reference reference, Literal arrayLiteral, Context context) throws IOException {
    //  col != ANY ([1,2,3]) --> not(col=1 and col=2 and col=3)
    String columnName = reference.info().ident().columnIdent().fqn();
    QueryBuilderHelper helper = QueryBuilderHelper.forType(reference.valueType());

    BooleanQuery.Builder andBuilder = new BooleanQuery.Builder();
    for (Object value : toIterable(arrayLiteral.value())) {
        andBuilder.add(helper.eq(columnName, value), BooleanClause.Occur.MUST);
    }
    return Queries.not(andBuilder.build());
}
 
Example 13
Source Project: Elasticsearch   Source File: LuceneQueryBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Query applyArrayLiteral(Reference reference, Literal arrayLiteral, Context context) throws IOException {
    // col not like ANY (['a', 'b']) --> not(and(like(col, 'a'), like(col, 'b')))
    String columnName = reference.ident().columnIdent().fqn();
    QueryBuilderHelper builder = QueryBuilderHelper.forType(reference.valueType());

    BooleanQuery.Builder andLikeQueries = new BooleanQuery.Builder();
    for (Object value : toIterable(arrayLiteral.value())) {
        andLikeQueries.add(builder.like(columnName, value, context.indexCache.query()), BooleanClause.Occur.MUST);
    }
    return Queries.not(andLikeQueries.build());
}
 
Example 14
Source Project: Elasticsearch   Source File: LuceneQueryBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Query apply(Function parent, Function inner, Context context) throws IOException {
    FunctionLiteralPair outerPair = new FunctionLiteralPair(parent);
    if (!outerPair.isValid()) {
        return null;
    }
    Query query = getQuery(inner, context);
    if (query == null) return null;
    Boolean negate = !(Boolean) outerPair.input().value();
    if (negate) {
        return Queries.not(query);
    } else {
        return query;
    }
}
 
Example 15
Source Project: Elasticsearch   Source File: QueryBuilderHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Query eq(String columnName, Object value) {
    if (value == null) {
        return Queries.newMatchNoDocsQuery();
    }
    return new TermQuery(new Term(columnName, (boolean)value ? "T" : "F"));
}
 
Example 16
Source Project: Elasticsearch   Source File: QueryBuilderHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Query eq(String columnName, Object value) {
    if (value == null) {
        return Queries.newMatchNoDocsQuery();
    }
    return new TermQuery(new Term(columnName, valueForSearch(value)));
}
 
Example 17
Source Project: Elasticsearch   Source File: QueryBuilderHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Query eq(String columnName, Object value) {
    if (value == null) {
        return Queries.newMatchNoDocsQuery();
    }
    return new TermQuery(new Term(columnName, (BytesRef)value));
}
 
Example 18
Source Project: Elasticsearch   Source File: QueryCollector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void collect(int doc) throws IOException {
    final Query query = getQuery(doc);
    if (query == null) {
        // log???
        return;
    }
    Query existsQuery = query;
    if (isNestedDoc) {
        existsQuery = new BooleanQuery.Builder()
            .add(existsQuery, Occur.MUST)
            .add(Queries.newNonNestedFilter(), Occur.FILTER)
            .build();
    }
    // run the query
    try {
        if (context.highlight() != null) {
            context.parsedQuery(new ParsedQuery(query));
            context.hitContext().cache().clear();
        }

        if (Lucene.exists(searcher, existsQuery)) {
            if (!limit || counter < size) {
                matches.add(BytesRef.deepCopyOf(current));
                if (context.highlight() != null) {
                    highlightPhase.hitExecute(context, context.hitContext());
                    hls.add(context.hitContext().hit().getHighlightFields());
                }
            }
            counter++;
            postMatch(doc);
        }
    } catch (IOException e) {
        logger.warn("[" + current.utf8ToString() + "] failed to execute query", e);
    }
}
 
Example 19
Source Project: Elasticsearch   Source File: QueryCollector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void collect(int doc) throws IOException {
    final Query query = getQuery(doc);
    if (query == null) {
        // log???
        return;
    }
    Query existsQuery = query;
    if (isNestedDoc) {
        existsQuery = new BooleanQuery.Builder()
            .add(existsQuery, Occur.MUST)
            .add(Queries.newNonNestedFilter(), Occur.FILTER)
            .build();
    }
    // run the query
    try {
        if (context.highlight() != null) {
            context.parsedQuery(new ParsedQuery(query));
            context.hitContext().cache().clear();
        }
        if (Lucene.exists(searcher, existsQuery)) {
            if (!limit || counter < size) {
                matches.add(BytesRef.deepCopyOf(current));
                scores.add(scorer.score());
                if (context.highlight() != null) {
                    highlightPhase.hitExecute(context, context.hitContext());
                    hls.add(context.hitContext().hit().getHighlightFields());
                }
            }
            counter++;
            postMatch(doc);
        }
    } catch (IOException e) {
        logger.warn("[" + current.utf8ToString() + "] failed to execute query", e);
    }
}
 
Example 20
Source Project: Elasticsearch   Source File: ReverseNestedAggregator.java    License: Apache License 2.0 5 votes vote down vote up
public ReverseNestedAggregator(String name, AggregatorFactories factories, ObjectMapper objectMapper,
        AggregationContext aggregationContext, Aggregator parent, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData)
        throws IOException {
    super(name, factories, aggregationContext, parent, pipelineAggregators, metaData);
    if (objectMapper == null) {
        parentFilter = Queries.newNonNestedFilter();
    } else {
        parentFilter = objectMapper.nestedTypeFilter();
    }
    parentBitsetProducer = context.searchContext().bitsetFilterCache().getBitSetProducer(parentFilter);
}
 
Example 21
Source Project: Elasticsearch   Source File: FetchPhase.java    License: Apache License 2.0 5 votes vote down vote up
private int findRootDocumentIfNested(SearchContext context, LeafReaderContext subReaderContext, int subDocId) throws IOException {
    if (context.mapperService().hasNested()) {
        BitSet bits = context.bitsetFilterCache().getBitSetProducer(Queries.newNonNestedFilter()).getBitSet(subReaderContext);
        if (!bits.get(subDocId)) {
            return bits.nextSetBit(subDocId);
        }
    }
    return -1;
}
 
Example 22
Source Project: Elasticsearch   Source File: InnerHitsContext.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TopDocs topDocs(SearchContext context, FetchSubPhase.HitContext hitContext) throws IOException {
    Query rawParentFilter;
    if (parentObjectMapper == null) {
        rawParentFilter = Queries.newNonNestedFilter();
    } else {
        rawParentFilter = parentObjectMapper.nestedTypeFilter();
    }
    BitSetProducer parentFilter = context.bitsetFilterCache().getBitSetProducer(rawParentFilter);
    Query childFilter = childObjectMapper.nestedTypeFilter();
    Query q = Queries.filtered(query.query(), new NestedChildrenQuery(parentFilter, childFilter, hitContext));

    if (size() == 0) {
        return new TopDocs(context.searcher().count(q), Lucene.EMPTY_SCORE_DOCS, 0);
    } else {
        int topN = Math.min(from() + size(), context.searcher().getIndexReader().maxDoc());
        TopDocsCollector topDocsCollector;
        if (sort() != null) {
            try {
                topDocsCollector = TopFieldCollector.create(sort(), topN, true, trackScores(), trackScores());
            } catch (IOException e) {
                throw ExceptionsHelper.convertToElastic(e);
            }
        } else {
            topDocsCollector = TopScoreDocCollector.create(topN);
        }
        try {
            context.searcher().search(q, topDocsCollector);
        } finally {
            clearReleasables(Lifetime.COLLECTION);
        }
        return topDocsCollector.topDocs(from(), size());
    }
}
 
Example 23
Source Project: Elasticsearch   Source File: MatchAllQueryParser.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
    XContentParser parser = parseContext.parser();

    float boost = 1.0f;
    String currentFieldName = null;

    XContentParser.Token token;
    while (((token = parser.nextToken()) != XContentParser.Token.END_OBJECT && token != XContentParser.Token.END_ARRAY)) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token.isValue()) {
            if ("boost".equals(currentFieldName)) {
                boost = parser.floatValue();
            } else {
                throw new QueryParsingException(parseContext, "[match_all] query does not support [" + currentFieldName + "]");
            }
        }
    }

    if (boost == 1.0f) {
        return Queries.newMatchAllQuery();
    }

    MatchAllDocsQuery query = new MatchAllDocsQuery();
    query.setBoost(boost);
    return query;
}
 
Example 24
private void setPathLevel() {
    ObjectMapper objectMapper = parseContext.nestedScope().getObjectMapper();
    if (objectMapper == null) {
        parentFilter = parseContext.bitsetFilter(Queries.newNonNestedFilter());
    } else {
        parentFilter = parseContext.bitsetFilter(objectMapper.nestedTypeFilter());
    }
    childFilter = nestedObjectMapper.nestedTypeFilter();
    parentObjectMapper = parseContext.nestedScope().nextLevel(nestedObjectMapper);
}
 
Example 25
Source Project: Elasticsearch   Source File: LimitQueryParser.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
    deprecationLogger.deprecated("The [limit] query is deprecated, please use the [terminate_after] parameter of the search API instead.");

    XContentParser parser = parseContext.parser();

    int limit = -1;
    String currentFieldName = null;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token.isValue()) {
            if ("value".equals(currentFieldName)) {
                limit = parser.intValue();
            } else {
                throw new QueryParsingException(parseContext, "[limit] query does not support [" + currentFieldName + "]");
            }
        }
    }

    if (limit == -1) {
        throw new QueryParsingException(parseContext, "No value specified for limit query");
    }

    // this filter is deprecated and parses to a filter that matches everything
    return Queries.newMatchAllQuery();
}
 
Example 26
Source Project: Elasticsearch   Source File: IndexQueryParserService.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
public Query parseInnerQuery(QueryParseContext parseContext) throws IOException {
    parseContext.parseFieldMatcher(parseFieldMatcher);
    Query query = parseContext.parseInnerQuery();
    if (query == null) {
        query = Queries.newMatchNoDocsQuery();
    }
    return query;
}
 
Example 27
Source Project: Elasticsearch   Source File: IndexQueryParserService.java    License: Apache License 2.0 5 votes vote down vote up
private ParsedQuery innerParse(QueryParseContext parseContext, XContentParser parser) throws IOException, QueryParsingException {
    parseContext.reset(parser);
    try {
        parseContext.parseFieldMatcher(parseFieldMatcher);
        Query query = parseContext.parseInnerQuery();
        if (query == null) {
            query = Queries.newMatchNoDocsQuery();
        }
        return new ParsedQuery(query, parseContext.copyNamedQueries());
    } finally {
        parseContext.reset(null);
    }
}
 
Example 28
Source Project: Elasticsearch   Source File: MultiMatchQuery.java    License: Apache License 2.0 5 votes vote down vote up
private Query parseAndApply(Type type, String fieldName, Object value, String minimumShouldMatch, Float boostValue) throws IOException {
    Query query = parse(type, fieldName, value);
    // If the coordination factor is disabled on a boolean query we don't apply the minimum should match.
    // This is done to make sure that the minimum_should_match doesn't get applied when there is only one word
    // and multiple variations of the same word in the query (synonyms for instance).
    if (query instanceof BooleanQuery && !((BooleanQuery) query).isCoordDisabled()) {
        query = Queries.applyMinimumShouldMatch((BooleanQuery) query, minimumShouldMatch);
    }
    if (boostValue != null && query != null) {
        query.setBoost(boostValue);
    }
    return query;
}
 
Example 29
Source Project: Elasticsearch   Source File: TranslogRecoveryPerformer.java    License: Apache License 2.0 5 votes vote down vote up
private static Engine.DeleteByQuery prepareDeleteByQuery(IndexQueryParserService queryParserService, MapperService mapperService, IndexAliasesService indexAliasesService, IndexCache indexCache, BytesReference source, @Nullable String[] filteringAliases, Engine.Operation.Origin origin, String... types) {
    long startTime = System.nanoTime();
    if (types == null) {
        types = Strings.EMPTY_ARRAY;
    }
    Query query;
    try {
        query = queryParserService.parseQuery(source).query();
    } catch (QueryParsingException ex) {
        // for BWC we try to parse directly the query since pre 1.0.0.Beta2 we didn't require a top level query field
        if (queryParserService.getIndexCreatedVersion().onOrBefore(Version.V_1_0_0_Beta2)) {
            try {
                XContentParser parser = XContentHelper.createParser(source);
                ParsedQuery parse = queryParserService.parse(parser);
                query = parse.query();
            } catch (Throwable t) {
                ex.addSuppressed(t);
                throw ex;
            }
        } else {
            throw ex;
        }
    }
    Query searchFilter = mapperService.searchFilter(types);
    if (searchFilter != null) {
        query = Queries.filtered(query, searchFilter);
    }

    Query aliasFilter = indexAliasesService.aliasFilter(filteringAliases);
    BitSetProducer parentFilter = mapperService.hasNested() ? indexCache.bitsetFilterCache().getBitSetProducer(Queries.newNonNestedFilter()) : null;
    return new Engine.DeleteByQuery(query, source, filteringAliases, aliasFilter, parentFilter, origin, startTime, types);
}
 
Example 30
Source Project: Elasticsearch   Source File: IndexFieldMapper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This termQuery impl looks at the context to determine the index that
 * is being queried and then returns a MATCH_ALL_QUERY or MATCH_NO_QUERY
 * if the value matches this index. This can be useful if aliases or
 * wildcards are used but the aim is to restrict the query to specific
 * indices
 */
@Override
public Query termQuery(Object value, @Nullable QueryParseContext context) {
    if (context == null) {
        return super.termQuery(value, context);
    }
    if (isSameIndex(value, context.index().getName())) {
        return Queries.newMatchAllQuery();
    } else {
        return Queries.newMatchNoDocsQuery();
    }
}