Search in sources :

Example 31 with ConstantScoreQuery

use of org.apache.lucene.search.ConstantScoreQuery in project SearchServices by Alfresco.

the class SolrCachingPathQuery method createWeight.

/*
     * @see org.apache.lucene.search.Query#createWeight(org.apache.lucene.search.Searcher)
     */
public Weight createWeight(IndexSearcher indexSearcher, boolean requiresScore) throws IOException {
    SolrIndexSearcher searcher = null;
    if (!(indexSearcher instanceof SolrIndexSearcher)) {
        throw new IllegalStateException("Must have a SolrIndexSearcher");
    } else {
        searcher = (SolrIndexSearcher) indexSearcher;
    }
    DocSet results = (DocSet) searcher.cacheLookup(CacheConstants.ALFRESCO_PATH_CACHE, pathQuery);
    if (results == null) {
        // Cache miss: get path query results and cache them
        WrappedQuery wrapped = new WrappedQuery(pathQuery);
        wrapped.setCache(false);
        results = searcher.getDocSet(wrapped);
        searcher.cacheInsert(CacheConstants.ALFRESCO_PATH_CACHE, pathQuery, results);
    }
    return new ConstantScoreQuery(results.getTopFilter()).createWeight(searcher, false);
}
Also used : WrappedQuery(org.apache.solr.search.WrappedQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) DocSet(org.apache.solr.search.DocSet)

Example 32 with ConstantScoreQuery

use of org.apache.lucene.search.ConstantScoreQuery in project SearchServices by Alfresco.

the class SolrDenySetQuery method createWeight.

@Override
public Weight createWeight(IndexSearcher searcher, boolean requiresScore) throws IOException {
    if (!(searcher instanceof SolrIndexSearcher)) {
        throw new IllegalStateException("Must have a SolrIndexSearcher");
    }
    String[] auths = authorities.substring(1).split(authorities.substring(0, 1));
    BitsFilter denyFilter = getACLFilter(auths, QueryConstants.FIELD_DENIED, (SolrIndexSearcher) searcher);
    return new ConstantScoreQuery(denyFilter).createWeight(searcher, false);
}
Also used : ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher)

Example 33 with ConstantScoreQuery

use of org.apache.lucene.search.ConstantScoreQuery in project neo4j by neo4j.

the class FulltextIndexReader method newRangeSeekByStringQuery.

private static Query newRangeSeekByStringQuery(String propertyName, String lower, boolean includeLower, String upper, boolean includeUpper) {
    boolean includeLowerBoundary = StringUtils.EMPTY.equals(lower) || includeLower;
    boolean includeUpperBoundary = StringUtils.EMPTY.equals(upper) || includeUpper;
    TermRangeQuery termRangeQuery = TermRangeQuery.newStringRange(propertyName, lower, upper, includeLowerBoundary, includeUpperBoundary);
    if ((includeLowerBoundary != includeLower) || (includeUpperBoundary != includeUpper)) {
        BooleanQuery.Builder builder = new BooleanQuery.Builder();
        if (includeLowerBoundary != includeLower) {
            builder.add(new TermQuery(new Term(propertyName, lower)), BooleanClause.Occur.MUST_NOT);
        }
        if (includeUpperBoundary != includeUpper) {
            builder.add(new TermQuery(new Term(propertyName, upper)), BooleanClause.Occur.MUST_NOT);
        }
        builder.add(termRangeQuery, BooleanClause.Occur.FILTER);
        return new ConstantScoreQuery(builder.build());
    }
    return termRangeQuery;
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) TermQuery(org.apache.lucene.search.TermQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) Term(org.apache.lucene.index.Term)

Example 34 with ConstantScoreQuery

use of org.apache.lucene.search.ConstantScoreQuery in project neo4j by neo4j.

the class LuceneDocumentStructure method newRangeSeekByStringQuery.

public static Query newRangeSeekByStringQuery(String lower, boolean includeLower, String upper, boolean includeUpper) {
    boolean includeLowerBoundary = StringUtils.EMPTY.equals(lower) || includeLower;
    boolean includeUpperBoundary = StringUtils.EMPTY.equals(upper) || includeUpper;
    TermRangeQuery termRangeQuery = TermRangeQuery.newStringRange(ValueEncoding.String.key(0), lower, upper, includeLowerBoundary, includeUpperBoundary);
    if ((includeLowerBoundary != includeLower) || (includeUpperBoundary != includeUpper)) {
        BooleanQuery.Builder builder = new BooleanQuery.Builder();
        if (includeLowerBoundary != includeLower) {
            builder.add(new TermQuery(new Term(ValueEncoding.String.key(0), lower)), BooleanClause.Occur.MUST_NOT);
        }
        if (includeUpperBoundary != includeUpper) {
            builder.add(new TermQuery(new Term(ValueEncoding.String.key(0), upper)), BooleanClause.Occur.MUST_NOT);
        }
        builder.add(termRangeQuery, BooleanClause.Occur.FILTER);
        return new ConstantScoreQuery(builder.build());
    }
    return termRangeQuery;
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) MultiTermQuery(org.apache.lucene.search.MultiTermQuery) TermQuery(org.apache.lucene.search.TermQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) Term(org.apache.lucene.index.Term)

Example 35 with ConstantScoreQuery

use of org.apache.lucene.search.ConstantScoreQuery in project neo4j by neo4j.

the class LuceneFulltextDocumentStructure method newCountEntityEntriesQuery.

static Query newCountEntityEntriesQuery(long nodeId, String[] propertyKeys, Value... propertyValues) {
    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    builder.add(new TermQuery(newTermForChangeOrRemove(nodeId)), BooleanClause.Occur.MUST);
    for (int i = 0; i < propertyKeys.length; i++) {
        String propertyKey = propertyKeys[i];
        Value value = propertyValues[i];
        // Only match on entries that doesn't contain fields we don't expect
        if (value.valueGroup() != ValueGroup.TEXT) {
            Query valueQuery = new ConstantScoreQuery(new WildcardQuery(new Term(propertyKey, "*")));
            builder.add(valueQuery, BooleanClause.Occur.MUST_NOT);
        }
    // Why don't we match on the TEXT values that actually should be in the index?
    // 1. The analyzer used for our index can have split the property value into several terms so we cannot
    // check that the exact property value exist in the index.
    // 2. There are some characters that analyzers will skip completely and if we have a property value with
    // only such characters there will be no reference to the field at all, so we cannot use a wildcard query either.
    }
    return builder.build();
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) TermQuery(org.apache.lucene.search.TermQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) Query(org.apache.lucene.search.Query) WildcardQuery(org.apache.lucene.search.WildcardQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) Value(org.neo4j.values.storable.Value) TextValue(org.neo4j.values.storable.TextValue) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) Term(org.apache.lucene.index.Term)

Aggregations

ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)68 BooleanQuery (org.apache.lucene.search.BooleanQuery)43 TermQuery (org.apache.lucene.search.TermQuery)42 Query (org.apache.lucene.search.Query)40 Term (org.apache.lucene.index.Term)30 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)19 BoostQuery (org.apache.lucene.search.BoostQuery)14 IndexSearcher (org.apache.lucene.search.IndexSearcher)14 ArrayList (java.util.ArrayList)13 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)13 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)12 MultiTermQuery (org.apache.lucene.search.MultiTermQuery)11 Document (org.apache.lucene.document.Document)10 Test (org.junit.Test)10 Sort (org.apache.lucene.search.Sort)9 TopDocs (org.apache.lucene.search.TopDocs)9 StringField (org.apache.lucene.document.StringField)8 BooleanClause (org.apache.lucene.search.BooleanClause)8 RegexpQuery (org.apache.lucene.search.RegexpQuery)8 SortField (org.apache.lucene.search.SortField)8