Class Predicate
- java.lang.Object
-
- com.day.cq.search.Predicate
-
- All Implemented Interfaces:
java.lang.Cloneable
- Direct Known Subclasses:
PredicateGroup
public class Predicate extends java.lang.Object implements java.lang.CloneableAPredicateis a single constraint for aQuery. It is a pure data model object, consisting of a parameter map based on key-value string pairs.Each
Predicatehas a type (getType()) that is used to find the rightPredicateEvaluatorthat will handle this predicate and eg. translate it into an XPath statement.Using the composite pattern, the subclass
PredicateGroupallows to group multiple predicates into one. This allows the query to actually consist of a predicate tree and reflects more complex queries that include sub-terms. The methodsgetName(),getPath()and#getParent()return that hierarchy information. The name/path is important, because facets will be returned in a map with the appropriate predicate path as key (seeSearchResult.getFacets()).The parameters are set via the
set(String, String)method and retrieved viaget(String),get(String, String)orgetParameters(). Predicates are alsoCloneable, so that it is easy to copy them.- Since:
- 5.2
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringIGNORE_CASEstatic java.lang.StringORDER_BYstatic java.lang.StringPARAM_CASEParameter onorderbyto control whether sorting is case insensitive or not.static java.lang.StringPARAM_EXCERPTstatic java.lang.StringPARAM_FACET_STRATEGYstatic java.lang.StringPARAM_GUESS_TOTALIf true, this allows the implementation to optimize the query and return just a guessedcount.static java.lang.StringPARAM_LIMITstatic java.lang.StringPARAM_OFFSETstatic java.lang.StringPARAM_OPTIONS_INDEXTAGTranslated into Query Option 'index tag'static java.lang.StringPARAM_OPTIONS_TRAVERSALHow to handle traversals - translated into Query Option 'traversal'.static java.lang.StringPARAM_SORTParameter onorderbyto control whether the sort order is ascending (default) or descending.static java.lang.StringSORT_ASCENDINGstatic java.lang.StringSORT_DESCENDINGstatic java.lang.StringTRAVERSAL_FAILstatic java.lang.StringTRAVERSAL_OKstatic java.lang.StringTRAVERSAL_WARN
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Predicateclone()Clones this predicate so that the returned clone can be used completely independently from this original.Predicateclone(boolean resetName)Clones this predicate so that the returned clone can be used completely independently from this original.booleanequals(java.lang.Object obj)java.lang.Stringget(java.lang.String parameterName)Returns the value for the given parameter name ornullif that parameter is not set.java.lang.Stringget(java.lang.String parameterName, java.lang.String defaultValue)Returns the value for the given parameter name or the given default value if that parameter is not set.booleangetBool(java.lang.String parameterName)Returns the boolean value for the given parameter name orfalseif that parameter is not set, ie.java.lang.StringgetName()Returns the name of this predicate.java.util.Map<java.lang.String,java.lang.String>getParameters()Returns an unmodifiable map of all parameters and their values.java.lang.StringgetPath()Returns the path in a predicate tree ofPredicateGroupsto this predicate, eg.java.lang.StringgetType()Returns the predicate type name for finding the rightPredicateEvaluator.inthashCode()booleanhasNonEmptyValue(java.lang.String parameterName)Returnstruewhen there is a parameter present with the given name and if the string value is not empty.booleanignored()This is used only during evaluation and indicates that this predicate is marked as "invisible" for anyPredicateEvaluatorthat will encounter it.Predicateset(java.lang.String parameterName, java.lang.String value)Sets the parameter 'parameterName' to the value given by 'value'.voidsetIgnored(boolean ignore)This is used only during evaluation and marks this predicate as "invisible" for anyPredicateEvaluatorthat will encounter it.java.lang.StringtoString()Overwrites the standardObject.toString()implementation and returns a debug-friendly string representation of the predicate.
-
-
-
Field Detail
-
PARAM_OFFSET
public static final java.lang.String PARAM_OFFSET
- See Also:
- Constant Field Values
-
PARAM_LIMIT
public static final java.lang.String PARAM_LIMIT
- See Also:
- Constant Field Values
-
PARAM_EXCERPT
public static final java.lang.String PARAM_EXCERPT
- See Also:
- Constant Field Values
-
PARAM_FACET_STRATEGY
public static final java.lang.String PARAM_FACET_STRATEGY
- See Also:
- Constant Field Values
-
PARAM_OPTIONS_TRAVERSAL
public static final java.lang.String PARAM_OPTIONS_TRAVERSAL
How to handle traversals - translated into Query Option 'traversal'. Valid values = ok|fail|warnp.traversal=ok
- See Also:
- Constant Field Values
-
TRAVERSAL_OK
public static final java.lang.String TRAVERSAL_OK
- See Also:
- Constant Field Values
-
TRAVERSAL_FAIL
public static final java.lang.String TRAVERSAL_FAIL
- See Also:
- Constant Field Values
-
TRAVERSAL_WARN
public static final java.lang.String TRAVERSAL_WARN
- See Also:
- Constant Field Values
-
PARAM_OPTIONS_INDEXTAG
public static final java.lang.String PARAM_OPTIONS_INDEXTAG
Translated into Query Option 'index tag'p.indexTag=tagName
- See Also:
- Constant Field Values
-
PARAM_GUESS_TOTAL
public static final java.lang.String PARAM_GUESS_TOTAL
If true, this allows the implementation to optimize the query and return just a guessedcount. Defaults to false, in which case the total is always accurate.- Since:
- 5.4
- See Also:
- Constant Field Values
-
ORDER_BY
public static final java.lang.String ORDER_BY
- See Also:
- Constant Field Values
-
PARAM_SORT
public static final java.lang.String PARAM_SORT
Parameter onorderbyto control whether the sort order is ascending (default) or descending. Possible values areascanddesc.orderby.sort=desc
- See Also:
- Constant Field Values
-
SORT_ASCENDING
public static final java.lang.String SORT_ASCENDING
- See Also:
- Constant Field Values
-
SORT_DESCENDING
public static final java.lang.String SORT_DESCENDING
- See Also:
- Constant Field Values
-
PARAM_CASE
public static final java.lang.String PARAM_CASE
Parameter onorderbyto control whether sorting is case insensitive or not. Only the valueignoreis supported, in which case "a" comes before "B". If empty or left out, sorting is case sensitive, e.g. "B" comes before "a".orderby.case=ignore
- See Also:
- Constant Field Values
-
IGNORE_CASE
public static final java.lang.String IGNORE_CASE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Predicate
public Predicate(java.lang.String type)
Creates aPredicateof the given type. Note that the type cannot be changed later. The name will be deducted automatically, seegetName(). Initially no parameters will be set and no parent will be present.- Parameters:
type- predicate type name for finding the rightPredicateEvaluator
-
Predicate
public Predicate(java.lang.String name, java.lang.String type)Creates aPredicatewith the given name and type. Note that name and type cannot be changed later. Initially no parameters will be set and no parent will be present.The name should not be
null- this case is reserved for a rootPredicateGroup(usingPredicateGroup()).- Parameters:
name- identifying name for this predicatetype- predicate type name for finding the rightPredicateEvaluator
-
-
Method Detail
-
getType
public java.lang.String getType()
Returns the predicate type name for finding the rightPredicateEvaluator.
-
getName
public java.lang.String getName()
Returns the name of this predicate. The name is used to allow round-trip serialization of predicate trees (where the order is encoded in the names) and for identifying predicates in thefacet map, in logging or other debug output.When a predicate is included in
PredicateGroup, the names of the parent predicates will make up thepath, eg.parent.child.grandchild. The name must not be changed after the predicate is passed to aQuery.If no name was set previously, it will be automatically created. If this predicate is part of a group, it will get a name of the form "N_type" where N is the 1-based index of its position in the parent group and "type" is it's
type. If it does not have a parent group, the name will only consist of the type.- Returns:
- identifying name for this predicate (can be
nullif no name was set)
-
getPath
public java.lang.String getPath()
Returns the path in a predicate tree ofPredicateGroupsto this predicate, eg.parent.child.grandchild. This can benullif no name was set. The path is used for identifying predicates in thefacet map, in logging or other debug output.
-
get
public java.lang.String get(java.lang.String parameterName)
Returns the value for the given parameter name ornullif that parameter is not set. Parameters always haveStringvalues.
-
get
public java.lang.String get(java.lang.String parameterName, java.lang.String defaultValue)Returns the value for the given parameter name or the given default value if that parameter is not set. Parameters always haveStringvalues.
-
getBool
public boolean getBool(java.lang.String parameterName)
Returns the boolean value for the given parameter name orfalseif that parameter is not set, ie. it assumesfalseas the default of the boolean parameter.Since actual parameter values are strings, it is considered
trueif the string value is either "true" or "on" (used by HTTP forms for checkboxes).
-
set
public Predicate set(java.lang.String parameterName, java.lang.String value)
Sets the parameter 'parameterName' to the value given by 'value'. Parameters have alwaysStringvalues.- Returns:
- returns itself for simple one-liners:
group.add(new Predicate("mytype", "type").set("type", "nt:file"));
-
hasNonEmptyValue
public boolean hasNonEmptyValue(java.lang.String parameterName)
Returnstruewhen there is a parameter present with the given name and if the string value is not empty. Parameters always haveStringvalues.
-
getParameters
public java.util.Map<java.lang.String,java.lang.String> getParameters()
Returns an unmodifiable map of all parameters and their values.
-
setIgnored
public void setIgnored(boolean ignore)
This is used only during evaluation and marks this predicate as "invisible" for anyPredicateEvaluatorthat will encounter it. Don't use that method when creating a query.- Parameters:
ignore-trueif this predicate should be ignored by evaluators (default isfalse)
-
ignored
public boolean ignored()
This is used only during evaluation and indicates that this predicate is marked as "invisible" for anyPredicateEvaluatorthat will encounter it. This method has no use for clients of the querybuilder API.- Returns:
trueif this predicate should be ignored by evaluators (default isfalse)
-
clone
public Predicate clone()
Clones this predicate so that the returned clone can be used completely independently from this original. Same asclone(false).
-
clone
public Predicate clone(boolean resetName)
Clones this predicate so that the returned clone can be used completely independently from this original. Allows for automatic reset of the name.- Parameters:
resetName- whether to reset the name tonullso that they will be automatically deducted (seegetName())
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
Overwrites the standardObject.toString()implementation and returns a debug-friendly string representation of the predicate.- Overrides:
toStringin classjava.lang.Object
-
-