Example usage for org.apache.lucene.search MatchNoDocsQuery MatchNoDocsQuery

List of usage examples for org.apache.lucene.search MatchNoDocsQuery MatchNoDocsQuery

Introduction

In this page you can find the example usage for org.apache.lucene.search MatchNoDocsQuery MatchNoDocsQuery.

Prototype

public MatchNoDocsQuery() 

Source Link

Document

Default constructor

Usage

From source file:com.b2international.index.lucene.IndexFieldBase.java

License:Apache License

@Override
public final Query toQuery(Iterable<T> values) {
    if (values == null || Iterables.isEmpty(values)) {
        return new MatchNoDocsQuery();
    } else {/*from w w  w.j  av  a2s .  com*/
        return toSetQuery(values);
    }
}

From source file:com.vmware.dcp.services.common.LuceneDocumentIndexService.java

License:Open Source License

/**
 * Augment the query argument with the resource group query specified
 * by the operation's authorization context.
 *
 * If the operation was executed by the system user, the query argument
 * is returned unmodified./*from   w  w w . j  av a 2  s.c om*/
 *
 * If no query needs to be executed return null
 *
 * @return Augmented query.
 */
private Query updateQuery(Operation op, Query tq) {
    Query rq = null;
    AuthorizationContext ctx = op.getAuthorizationContext();

    // Allow operation if isAuthorizationEnabled is set to false
    if (!this.getHost().isAuthorizationEnabled()) {
        return tq;
    }

    if (ctx == null) {
        // Don't allow operation if no authorization context and auth is enabled
        return null;
    }

    // Allow unconditionally if this is the system user
    if (ctx.isSystemUser()) {
        return tq;
    }

    // If the resource query in the authorization context is unspecified,
    // use a Lucene query that doesn't return any documents so that every
    // result will be empty.
    if (ctx.getResourceQuery() == null) {
        rq = new MatchNoDocsQuery();
    } else {
        rq = LuceneQueryConverter.convertToLuceneQuery(ctx.getResourceQuery());
    }

    BooleanQuery bq = new BooleanQuery();
    bq.add(rq, Occur.FILTER);
    bq.add(tq, Occur.FILTER);
    return bq;
}

From source file:com.vmware.xenon.services.common.LuceneDocumentIndexService.java

License:Open Source License

/**
 * Augment the query argument with the resource group query specified
 * by the operation's authorization context.
 *
 * If the operation was executed by the system user, the query argument
 * is returned unmodified./* ww  w  .jav  a 2s .c  om*/
 *
 * If no query needs to be executed return null
 *
 * @return Augmented query.
 */
private Query updateQuery(Operation op, Query tq) {
    Query rq = null;
    AuthorizationContext ctx = op.getAuthorizationContext();

    // Allow operation if isAuthorizationEnabled is set to false
    if (!this.getHost().isAuthorizationEnabled()) {
        return tq;
    }

    if (ctx == null) {
        // Don't allow operation if no authorization context and auth is enabled
        return null;
    }

    // Allow unconditionally if this is the system user
    if (ctx.isSystemUser()) {
        return tq;
    }

    // If the resource query in the authorization context is unspecified,
    // use a Lucene query that doesn't return any documents so that every
    // result will be empty.
    if (ctx.getResourceQuery(Action.GET) == null) {
        rq = new MatchNoDocsQuery();
    } else {
        rq = LuceneQueryConverter.convertToLuceneQuery(ctx.getResourceQuery(Action.GET));
    }

    BooleanQuery.Builder builder = new BooleanQuery.Builder().add(rq, Occur.FILTER).add(tq, Occur.FILTER);
    return builder.build();
}

From source file:jp.scaleout.elasticsearch.plugins.queryparser.classic.MapperQueryParser.java

License:Apache License

@Override
public Query parse(String query) throws ParseException {
    if (query.trim().isEmpty()) {
        // if the query string is empty we return no docs / empty result
        // the behavior is simple to change in the client if all docs is required
        // or a default query
        return new MatchNoDocsQuery();
    }/*from ww  w .j  a v a2s .com*/
    return super.parse(query);
}

From source file:org.apache.solr.handler.AnalyticsHandler.java

License:Apache License

/**
 * Get the documents returned by the query and filter queries included in the request.
 * /*  w w w .j  a  v  a 2 s . c  om*/
 * @param req the request sent to the handler
 * @return the set of documents matching the query
 * @throws SyntaxError if there is a syntax error in the queries
 * @throws IOException if an error occurs while searching the index
 */
private DocSet getDocuments(SolrQueryRequest req) throws SyntaxError, IOException {
    SolrParams params = req.getParams();
    ArrayList<Query> queries = new ArrayList<>();

    // Query Param
    String queryString = params.get(CommonParams.Q);

    String defType = params.get(QueryParsing.DEFTYPE, QParserPlugin.DEFAULT_QTYPE);

    QParser parser = QParser.getParser(queryString, defType, req);
    Query query = parser.getQuery();
    if (query == null) {
        // normalize a null query to a query that matches nothing
        query = new MatchNoDocsQuery();
    }
    queries.add(query);

    // Filter Params
    String[] fqs = req.getParams().getParams(CommonParams.FQ);
    if (fqs != null) {
        for (String fq : fqs) {
            if (fq != null && fq.trim().length() != 0) {
                QParser fqp = QParser.getParser(fq, req);
                queries.add(fqp.getQuery());
            }
        }
    }
    return req.getSearcher().getDocSet(queries);
}

From source file:org.apache.solr.schema.NumericFieldType.java

License:Apache License

public static Query numericDocValuesRangeQuery(String field, Number lowerValue, Number upperValue,
        boolean lowerInclusive, boolean upperInclusive) {

    long actualLowerValue = Long.MIN_VALUE;
    if (lowerValue != null) {
        actualLowerValue = lowerValue.longValue();
        if (lowerInclusive == false) {
            if (actualLowerValue == Long.MAX_VALUE) {
                return new MatchNoDocsQuery();
            }/*from   w  w w. j a  v  a 2s  .c om*/
            ++actualLowerValue;
        }
    }

    long actualUpperValue = Long.MAX_VALUE;
    if (upperValue != null) {
        actualUpperValue = upperValue.longValue();
        if (upperInclusive == false) {
            if (actualUpperValue == Long.MIN_VALUE) {
                return new MatchNoDocsQuery();
            }
            --actualUpperValue;
        }
    }
    return NumericDocValuesField.newRangeQuery(field, actualLowerValue, actualUpperValue);
}

From source file:org.apache.solr.search.GoodbyeQueryBuilder.java

License:Apache License

public Query getQuery(Element e) throws ParserException {
    return new MatchNoDocsQuery();
}

From source file:org.apache.solr.search.GraphTermsQParserPlugin.java

License:Apache License

@Override
public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
    return new QParser(qstr, localParams, params, req) {
        @Override/*w ww  . j av  a2 s.c om*/
        public Query parse() throws SyntaxError {
            String fname = localParams.get(QueryParsing.F);
            FieldType ft = req.getSchema().getFieldTypeNoEx(fname);
            int maxDocFreq = localParams.getInt("maxDocFreq", Integer.MAX_VALUE);
            String qstr = localParams.get(QueryParsing.V);//never null

            if (qstr.length() == 0) {
                return new MatchNoDocsQuery();
            }

            final String[] splitVals = qstr.split(",");

            Term[] terms = new Term[splitVals.length];
            BytesRefBuilder term = new BytesRefBuilder();
            for (int i = 0; i < splitVals.length; i++) {
                String stringVal = splitVals[i].trim();
                if (ft != null) {
                    ft.readableToIndexed(stringVal, term);
                } else {
                    term.copyChars(stringVal);
                }
                BytesRef ref = term.toBytesRef();
                terms[i] = new Term(fname, ref);
            }

            ArrayUtil.timSort(terms);
            return new ConstantScoreQuery(new GraphTermsQuery(fname, terms, maxDocFreq));
        }
    };
}

From source file:org.codelibs.elasticsearch.common.lucene.all.AllTermQuery.java

License:Apache License

@Override
public Query rewrite(IndexReader reader) throws IOException {
    Query rewritten = super.rewrite(reader);
    if (rewritten != this) {
        return rewritten;
    }/*from w  w w .java 2  s.c  om*/
    boolean fieldExists = false;
    boolean hasPayloads = false;
    for (LeafReaderContext context : reader.leaves()) {
        final Terms terms = context.reader().terms(term.field());
        if (terms != null) {
            fieldExists = true;
            if (terms.hasPayloads()) {
                hasPayloads = true;
                break;
            }
        }
    }
    if (fieldExists == false) {
        return new MatchNoDocsQuery();
    }
    if (hasPayloads == false) {
        return new TermQuery(term);
    }
    return this;
}

From source file:org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery.java

License:Apache License

@Override
public Query rewrite(IndexReader reader) throws IOException {
    Query rewritten = super.rewrite(reader);
    if (rewritten != this) {
        return rewritten;
    }/*w  w w. j  a  va  2s  .c o  m*/
    if (termArrays.isEmpty()) {
        return new MatchNoDocsQuery();
    }
    MultiPhraseQuery.Builder query = new MultiPhraseQuery.Builder();
    query.setSlop(slop);
    int sizeMinus1 = termArrays.size() - 1;
    for (int i = 0; i < sizeMinus1; i++) {
        query.add(termArrays.get(i), positions.get(i));
    }
    Term[] suffixTerms = termArrays.get(sizeMinus1);
    int position = positions.get(sizeMinus1);
    ObjectHashSet<Term> terms = new ObjectHashSet<>();
    for (Term term : suffixTerms) {
        getPrefixTerms(terms, term, reader);
        if (terms.size() > maxExpansions) {
            break;
        }
    }
    if (terms.isEmpty()) {
        return Queries.newMatchNoDocsQuery("No terms supplied for " + MultiPhrasePrefixQuery.class.getName());
    }
    query.add(terms.toArray(Term.class), position);
    return query.build();
}