public abstract class QueryProcessor<T> extends Object
Instances are one-time-use. Other singleton classes should inject a Provider rather than holding on to a single instance.
Modifier and Type | Class and Description |
---|---|
protected static class |
QueryProcessor.Metrics |
Modifier and Type | Field and Description |
---|---|
protected int |
start |
Modifier | Constructor and Description |
---|---|
protected |
QueryProcessor(com.google.gerrit.metrics.MetricMaker metricMaker,
SchemaDefinitions<T> schemaDef,
IndexConfig indexConfig,
IndexCollection<?,T,? extends Index<?,T>> indexes,
IndexRewriter<T> rewriter,
String limitField,
IntSupplier permittedLimit) |
Modifier and Type | Method and Description |
---|---|
protected QueryOptions |
createOptions(IndexConfig indexConfig,
int start,
int limit,
Set<String> requestedFields) |
QueryProcessor<T> |
enforceVisibility(boolean enforce)
Specify whether to enforce visibility by filtering out results that are not visible to the
user.
|
protected abstract Predicate<T> |
enforceVisibility(Predicate<T> pred)
Invoked after the query was rewritten.
|
protected abstract String |
formatForLogging(T t) |
boolean |
isDisabled()
Check whether querying should be disabled.
|
List<QueryResult<T>> |
query(List<Predicate<T>> queries)
Perform multiple queries in parallel.
|
QueryResult<T> |
query(Predicate<T> query)
Query for entities that match a structured query.
|
QueryProcessor<T> |
setNoLimit(boolean isNoLimit) |
QueryProcessor<T> |
setRequestedFields(Set<String> fields) |
QueryProcessor<T> |
setStart(int n) |
QueryProcessor<T> |
setUserProvidedLimit(int n)
Set an end-user-provided limit on the number of results returned.
|
protected QueryProcessor(com.google.gerrit.metrics.MetricMaker metricMaker, SchemaDefinitions<T> schemaDef, IndexConfig indexConfig, IndexCollection<?,T,? extends Index<?,T>> indexes, IndexRewriter<T> rewriter, String limitField, IntSupplier permittedLimit)
public QueryProcessor<T> setStart(int n)
public QueryProcessor<T> enforceVisibility(boolean enforce)
Enforcing visibility may have performance consequences, as the index system may need to post-filter a large number of results to fill even a modest limit.
If visibility is enforced, the user's queryLimit
global capability is also used to
bound the total number of results. If this capability is non-positive, this results in the
entire query processor being disabled
.
enforce
- whether to enforce visibility.public QueryProcessor<T> setUserProvidedLimit(int n)
Since this limit is provided by an end user, it may exceed the limit that they are authorized to use. This is allowed; the processor will take multiple possible limits into account and choose the one that makes the most sense.
n
- limit; zero or negative means no limit.public QueryProcessor<T> setNoLimit(boolean isNoLimit)
public QueryProcessor<T> setRequestedFields(Set<String> fields)
public QueryResult<T> query(Predicate<T> query) throws QueryParseException
query
- the query.QueryParseException
query(List)
public List<QueryResult<T>> query(List<Predicate<T>> queries) throws QueryParseException
If querying is disabled, short-circuits the index and returns empty results. Callers that
wish to distinguish this case from a query returning no results from the index may call isDisabled()
themselves.
queries
- list of queries.QueryParseException
protected QueryOptions createOptions(IndexConfig indexConfig, int start, int limit, Set<String> requestedFields)
protected abstract Predicate<T> enforceVisibility(Predicate<T> pred)
pred
- the querypublic boolean isDisabled()
Currently, the only condition that can disable the whole query processor is if both visibility is enforced
and the user has a non-positive maximum
value for the queryLimit
capability.
If querying is disabled, all calls to query(Predicate)
and query(List)
will return empty results. This method can be used if callers wish to distinguish this case
from a query returning no results from the index.