Interface PredicateEvaluator

    • Method Detail

      • getXPathExpression

        java.lang.String getXPathExpression​(Predicate predicate,
                                            EvaluationContext context)
        Returns an XPath predicate expression, which is just a partial expression that can be placed inside "[" and "]" in a full XPath statement. Examples are:
         @jcr:title = 'Foobar'
         
        or this longer expression:
         (@count > 10 and @count < 20) or @state = 'foo'
         

        As a different constraint, an implementation can also filter the result of the query, using the includes(Predicate, Row, EvaluationContext) method. Also, it is recommended to implement the xpath-based constraint again inside includes() to support the case where filtering is forced by a parent predicte group.

        Note that an implementation must return an empty string or null if its parameters are empty, ie. if the predicate should not "take part" in the actual query. This is because we need to keep track of the potential predicates for the query to get all Facets, not only the ones for what is already queried.

        If you implement this method, don't forget to implement canXpath(Predicate, EvaluationContext) so that it returns true.

        Parameters:
        predicate - predicate (for this evaluator type) which is evaluated
        context - helper class which provides access to various elements of the query evaluation
        Returns:
        string containing an XPath predicateEvaluator expression
      • includes

        boolean includes​(Predicate predicate,
                         Row row,
                         EvaluationContext context)
        If the constraint for the given predicate formulated via a JCR XPath expression, this method can be used to filter the result set row by row (to get the node behind the row, one can use context.getNode(row).

        Please note that this is more likely to negatively impact performance!

        If you implement this method, don't forget to implement canFilter(Predicate, EvaluationContext) so that it returns true.

        Parameters:
        predicate - predicate (for this evaluator type) which is evaluated
        row - current row of the result set returned through the xpath query
        context - helper class which provides access to various elements of the query evaluation
        Returns:
        true if this row should be part of the final result set, false if it should be dropped
      • canXpath

        boolean canXpath​(Predicate predicate,
                         EvaluationContext context)
        Returns whether this evaluator can return its constraint via xpath, ie. getXPathExpression(Predicate, EvaluationContext).

        Note that the result typically does not depend on either the predicate or the context (given as parameters) - in most cases this depends directly on the implementation.

        Parameters:
        predicate - predicate (for this evaluator type) which is evaluated
        context - helper class which provides access to various elements of the query evaluation
        Returns:
        true if this evaluator can express itself via xpath, ie. getXPathExpression(Predicate, EvaluationContext)
        Since:
        5.3
      • canFilter

        boolean canFilter​(Predicate predicate,
                          EvaluationContext context)
        Returns whether this evaluator can handle its constraint via filtering, ie. includes(Predicate, Row, EvaluationContext).

        Note that the result typically does not depend on either the predicate or the context (given as parameters) - in most cases this depends directly on the implementation.

        Parameters:
        predicate - predicate (for this evaluator type) which is evaluated
        context - helper class which provides access to various elements of the query evaluation
        Returns:
        true if this evaluator can be express itself via filtering, ie. includes(Predicate, Row, EvaluationContext)
        Since:
        5.3
      • getOrderByProperties

        java.lang.String[] getOrderByProperties​(Predicate predicate,
                                                EvaluationContext context)
        Returns a list of JCR property names or relative paths to properties that should be used when the result should be ordered by the given predicate. The paths will be used in the order by part of the Xpath query (in the given order). Can return null if there is no property to order by. Additional ordering can happen by returning a custom Comparator in getOrderByComparator(Predicate, EvaluationContext).
        Parameters:
        predicate - predicate (for this evaluator type) which is evaluated
        context - helper class which provides access to various elements of the query evaluation
        Returns:
        one or multiple relative paths to JCR properties or null
      • getOrderByComparator

        java.util.Comparator<Row> getOrderByComparator​(Predicate predicate,
                                                       EvaluationContext context)
        Returns a comparator that will be used to "manually" sort the result after running the xpath query and after filtering via includes(Predicate, Row, EvaluationContext) happened. This can be expensive and if possible, getOrderByProperties(Predicate, EvaluationContext) (which is used for XPath order by) should be used. Result can be null.
        Parameters:
        predicate - predicate (for this evaluator type) which is evaluated
        context - helper class which provides access to various elements of the query evaluation
        Returns:
        a custom comparator for the given predicate or null
      • getFacetExtractor

        FacetExtractor getFacetExtractor​(Predicate predicate,
                                         EvaluationContext context)
        Returns a FacetExtractor that is used to create a Facet that maps to the given predicate. There are built-in extractor implementations that can be used (eg. DistinctValuesFacetExtractor which automatically creates a Facet with buckets based on the distinct values of a certain property).

        This method will only be called when the API user actually requests the facets from the search result using SearchResult.getFacets().

        Important note: this object (the PredicateEvaluator) as an OSGi component instance will be released before the returned FacetExtractor is used, ie. before any method is called on it. This lazy usage of the extractor is needed, because during query execution it cannot be known if SearchResult.getFacets() will be called by the client afterwards. Thus be careful if you return an inner or anonymous class that uses members of this evaluator which are references to other OSGi components - at the time of facet extraction, these will be effectively null. Thus you should retrieve information from the service while this method is called and store the result in the returned FacetExtractor object. This also means that you cannot directly use OSGi references in a FacetExtractor at all (they are not OSGi components).

        Parameters:
        predicate - predicate (for this evaluator type) which is evaluated
        context - helper class which provides access to various elements of the query evaluation
        Returns:
        a FacetExtractor that is used to create a Facet or null if no extractor shall be provided