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);
}
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);
}
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;
}
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;
}
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();
}
Aggregations