public interface Query
Query
represents a JCR repository query that can be created
programmatically, with a list of so-called Predicates
.
These act as constraints on the query, meaning they either add predicates to
the underlying XPath query or filter the result, and there can be any number
of predicates.
Each predicate has a type (Predicate.getType()
) for which a
PredicateEvaluator
must exist, that can eg. translate the predicate
in question into an XPath predicate. It is possible to register custom
PredicateEvaluators
by using the proper OSGi
component factory name.
To create queries, use the QueryBuilder
interface. To execute it,
simply call getResult()
to get the SearchResult
, which will
contain the hits, metadata about paging and access to facets.
Modifier and Type | Method and Description |
---|---|
boolean |
getExcerpt()
Returns whether the query will return plain nodes or an excerpt.
|
long |
getHitsPerPage()
Returns the number of hits to include per
ResultPage , ie. |
PredicateGroup |
getPredicates()
Returns the list of predicates that define this query.
|
SearchResult |
getResult()
Executes the query and returns the result.
|
long |
getStart()
Returns the offset in the actual search results to start from.
|
Query |
refine(Bucket bucket)
This will return a new query that includes the given bucket from a
previous search.
|
void |
registerPredicateEvaluator(java.lang.String type,
PredicateEvaluator evaluator)
This is an alternate way of providing a custom evaluator for predicates.
|
void |
setExcerpt(boolean excerpt)
Whether the query should return plain nodes or an excerpt.
|
void |
setHitsPerPage(long hitsPerPage)
Sets the number of hits to include on a
ResultPage . |
void |
setStart(long start)
This sets an offset for the actual search results, ie.
|
SearchResult getResult()
Query
only runs once. This also
means that adding or
removing predicates is no
longer possible after calling getResult().PredicateGroup getPredicates()
getResult()
has been
called.void registerPredicateEvaluator(java.lang.String type, PredicateEvaluator evaluator)
PredicateEvaluator
), but in some cases it is simpler to inline
them, for example to provide a custom facet extraction inside a JSP. A
notable difference is that this mechanism is only valid for the current
Query
, whereas the OSGi component way of registration makes the
evaluator available for all queries.
To register, a type
must be specified. This evaluator will
be used for all predicates with that type. Evaluators registered this way
will have precedence over evaluators provided as OSGi component
factories. The type should not start with a "_", as it would be ignored
for queries created from requests (see
PredicateConverter.createPredicates(java.util.Map)
.
type
- the predicate type to register the evaluator forevaluator
- a custom predicate evaluatorQuery refine(Bucket bucket)
Bucket.getPredicate()
) and add it to the new query so that both
the existing predicate group and this new predicate are required
to match.bucket
- a bucket (typically from the facets of this queries search
result)void setExcerpt(boolean excerpt)
false
.excerpt
- true
if an excerpt should be returned,
false
if notboolean getExcerpt()
false
.true
if an excerpt should be returned,
false
if notvoid setStart(long start)
start
) items of the underlying result. By default
this is 0, ie. right from the very beginning.start
- the offset in the actual search results to start fromlong getStart()
setStart(long)
.void setHitsPerPage(long hitsPerPage)
ResultPage
. Since only
the first page is returned directly and typically fully read by clients,
this can also be seen as "limit" for the search result. Further results
can be accessed either by retrieving the
next result page
or by running a new
query and setting the start
parameter (often also
called "offset"). For unlimited results on a single page, use 0. Default
value is 10.hitsPerPage
- the number of hits to include on a result page (0 for
unlimited results).long getHitsPerPage()
ResultPage
, ie. the
limit. See setHitsPerPage(long)
.Copyright © 2010 - 2020 Adobe. All Rights Reserved