public interface QueryBuilder
QueryBuilder
is a service for building Queries
searching the Java Content Repository and which are easily extensible. The
individual constraints of a Query
are expressed as Predicates
, which are pluggable through OSGi mechanisms, ie. one can easily
define a new PredicateEvaluator
that maps some higher-level search constraint
to an explicit JCR XPath expression, can filter the search result for
constraints that cannot be expressed via XPath and automatically provide
Facets
based on the search results.
This service allows to create queries with several convenience methods, for example directly from a request using a fixed convention for the structure of request parameters that make up the predicates. In addition, it allows to store queries in the repository and load them again.
queryBuilder
is available as an OSGi
SCR reference.
Session session = request.getResourceResolver().adaptTo(Session.class); Query query = queryBuilder.createQuery(PredicateGroup.create(request.getParameterMap()), session); SearchResult result = query.getResult(); ...
Mapmap = new HashMap (); map.put("path", "/content"); map.put("type", "nt:file"); Query query = builder.createQuery(PredicateGroup.create(map), session); SearchResult result = query.getResult(); ...
PredicateGroup group = new PredicateGroup(); group.add(new Predicate("mypath", "path").set("path", "/content")); group.add(new Predicate("mytype", "type").set("type", "nt:file")); Query query = builder.createQuery(group, session); SearchResult result = query.getResult(); ...
Modifier and Type | Method and Description |
---|---|
void |
clearFacetCache()
Invalidates the facet cache, removing all currently
cached facets and forcing a new facet extraction on
future queries.
|
Query |
createQuery(PredicateGroup predicates,
Session session)
Creates a query with the given predicate group as root group.
|
Query |
createQuery(Session session)
Creates an "empty" query, ie.
|
Query |
loadQuery(java.lang.String path,
Session session)
Loads a saved query from the given repository path.
|
void |
storeQuery(Query query,
java.lang.String path,
boolean createFile,
Session session)
Saves a query at the given repository path.
|
Query createQuery(Session session)
Query.getPredicates()
to get the root predicate group in order to
add predicates via PredicateGroup.add(Predicate)
.session
- the JCR session for the queryQuery createQuery(PredicateGroup predicates, Session session)
predicates
- a predicate group used as the root groupsession
- the JCR session for the queryQuery loadQuery(java.lang.String path, Session session) throws RepositoryException, java.io.IOException
nt:file
node that
contains the query as a text file (ie. in the
jcr:content/jcr:data
property). In both cases, the query
definition is expected as a multi-line string in the java properties file
format, based on the map reader
PredicateConverter.createPredicates(java.util.Map)
.
To store a query, use
storeQuery(Query, String, boolean, Session)
.
path
- location of the saved querysession
- the JCR session to access the repositorynull
if the query could not be foundjava.io.IOException
- if reading from the binary stream failedRepositoryException
- if something went wrong in the repositoryvoid storeQuery(Query query, java.lang.String path, boolean createFile, Session session) throws RepositoryException, java.io.IOException
nt:file
containing the query as
a text file, depending on the 'createFile' flag. In both cases, the query
definition will be stored as a multi-line string in the java properties
file format, based on the map created from
PredicateConverter.createMap(PredicateGroup)
. If the full path to
that property does not exist yet, it will be created using
nt:unstructured
nodes.
To load this query again, use loadQuery(String, Session)
.
query
- the query to savepath
- target locationcreateFile
- if true
, an nt:file
will be created
under that path with the query as file contents; otherwise, if
the value is false
, a simple string property will
be created at the given locationsession
- the JCR session to access the repositoryjava.io.IOException
- if writing to the binary stream failedRepositoryException
- if something went wrong in the repositoryvoid clearFacetCache()
Copyright © 2010 - 2020 Adobe. All Rights Reserved