com.day.cq.search.impl.builder
Class QueryImpl

java.lang.Object
  extended by com.day.cq.search.impl.builder.QueryImpl
All Implemented Interfaces:
Query

public class QueryImpl
extends Object
implements Query

QueryImpl implements the Query interface.

Its implementation builds the SearchResult and hold various references to things such as the ResourceResolver. For managing the predicates and building the XPath expression that is executed, it relies on a simple RootEvaluator, which is an extended PredicateGroupEvaluator that is able create a complete XPath expression (and not only the [@x = y ...] predicateEvaluator part).


Constructor Summary
QueryImpl(PredicateGroup rootPredicate, Session session, QueryBuilderImpl queryBuilder)
           
 
Method Summary
protected  SearchResultImpl execute()
           
 Map<String,Facet> extractFacets()
           
 boolean getExcerpt()
          Returns whether the query will return plain nodes or an excerpt.
 Set<String> getExcerptPropertyNames()
           
 String getFilteringPredicates()
           
 long getHitsPerPage()
           
 PredicateEvaluator getPredicateEvaluator(String type)
          Can only be called during the execution of getResult(), because it requires a cleanup done by calling releasePredicateEvaluators(), which happens at the end of getResult().
 PredicateGroup getPredicates()
          Returns the list of predicates that define this query.
 QueryResult getRawQueryResult()
           
 org.apache.sling.api.resource.ResourceResolver getResourceResolver()
           
 SearchResult getResult()
          Executes the query and returns the result.
 Session getSession()
           
 long getStart()
           
 String getStatement()
           
 Query refine(Bucket bucket)
          This will return a new query that includes the given bucket from a previous search.
 void registerPredicateEvaluator(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 display on a ResultPage.
 void setStart(long start)
          This sets an offset for the actual search results, ie.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryImpl

public QueryImpl(PredicateGroup rootPredicate,
                 Session session,
                 QueryBuilderImpl queryBuilder)
Method Detail

getResult

public SearchResult getResult()
Description copied from interface: Query
Executes the query and returns the result. Implementations will cache the result, ie. a second call of this method will return the initial result of the query execution; each Query only runs once. This also means that adding or removing predicates is no longer possible after calling getResult().

Specified by:
getResult in interface Query

getPredicates

public PredicateGroup getPredicates()
Description copied from interface: Query
Returns the list of predicates that define this query. Changing this predicate tree only has an effect before Query.getResult() has been called.

Specified by:
getPredicates in interface Query
Returns:
the root predicate group making up this query

registerPredicateEvaluator

public void registerPredicateEvaluator(String type,
                                       PredicateEvaluator evaluator)
Description copied from interface: Query
This is an alternate way of providing a custom evaluator for predicates. The normal way is to register them as OSGi component factories (see 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.

Specified by:
registerPredicateEvaluator in interface Query
Parameters:
type - the predicate type to register the evaluator for
evaluator - a custom predicate evaluator

refine

public Query refine(Bucket bucket)
Description copied from interface: Query
This will return a new query that includes the given bucket from a previous search. It will simply take the predicate provided by the bucket (Bucket.getPredicate()) and add it to the new query so that both the existing predicate group is required and this new predicate are required to match.

Specified by:
refine in interface Query
Parameters:
bucket - a bucket (typically from the facets of this queries search result)
Returns:
a new query that includes the predicate provided by the bucket

setExcerpt

public void setExcerpt(boolean excerpt)
Description copied from interface: Query
Whether the query should return plain nodes or an excerpt. Default is false.

Specified by:
setExcerpt in interface Query
Parameters:
excerpt - true if an excerpt should be returned, false if not

getExcerpt

public boolean getExcerpt()
Description copied from interface: Query
Returns whether the query will return plain nodes or an excerpt. Default is false.

Specified by:
getExcerpt in interface Query
Returns:
true if an excerpt should be returned, false if not

getStart

public long getStart()
Specified by:
getStart in interface Query
Returns:
offset in the actual search results to start from

setStart

public void setStart(long start)
Description copied from interface: Query
This sets an offset for the actual search results, ie. it will skip the first N (= start) items of the underlying result. By default this is 0, ie. right from the very beginning.

Specified by:
setStart in interface Query
Parameters:
start - the offset in the actual search results to start from

getHitsPerPage

public long getHitsPerPage()
Specified by:
getHitsPerPage in interface Query
Returns:
the number of hits to display per page.

setHitsPerPage

public void setHitsPerPage(long hitsPerPage)
Description copied from interface: Query
Sets the number of hits to display on a ResultPage. For unlimited results on a single page, use 0. Default value is 10

Specified by:
setHitsPerPage in interface Query
Parameters:
hitsPerPage - the number of hits to display on a page (0 for all).

getSession

public Session getSession()

getResourceResolver

public org.apache.sling.api.resource.ResourceResolver getResourceResolver()

getPredicateEvaluator

public PredicateEvaluator getPredicateEvaluator(String type)
Can only be called during the execution of getResult(), because it requires a cleanup done by calling releasePredicateEvaluators(), which happens at the end of getResult().


getExcerptPropertyNames

public Set<String> getExcerptPropertyNames()

getRawQueryResult

public QueryResult getRawQueryResult()

extractFacets

public Map<String,Facet> extractFacets()

getStatement

public String getStatement()

getFilteringPredicates

public String getFilteringPredicates()

execute

protected SearchResultImpl execute()


Copyright © 2009 Day Management AG. All Rights Reserved.