SearchNode
@ExperimentalAppSearchApi
public final class SearchNode implements FunctionNode
FunctionNode
that represents the search function.
The search function is a convenience function that takes a query string and parses it according to the supported query language, and can optionally take a list of property paths to serve as property restricts. This means that the query `search("foo bar", createList("subject", body")` is equivalent to the query `(subject:foo OR body:foo) (subject:bar OR body:bar)`.
Summary
Public constructors |
---|
SearchNode(@NonNull Node childNode) Create a |
SearchNode( Create a |
Public methods |
|
---|---|
void |
addPropertyPath(@NonNull PropertyPath propertyPath) Add a restrict to the end of the current list of restricts |
boolean |
|
@NonNull Node |
getChild() Returns the child query searched for in the function. |
@NonNull List<Node> |
Returns the child |
@NonNull String |
Returns the name of the function represented by |
@NonNull List<PropertyPath> |
Returns the list of property restricts applied to the query. |
int |
hashCode() |
void |
Sets the query searched for in the function. |
void |
setPropertyPaths(@NonNull List<PropertyPath> properties) Sets what property restricts will be applied to the query. |
@NonNull String |
toString() Get the query string representation of |
Inherited Constants |
||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
Public constructors
SearchNode
public SearchNode(@NonNull Node childNode)
Create a SearchNode
representing the query function `search(queryString)`.
By default, the query function search will have an empty list of restricts. The search function will return all results from the query.
SearchNode
public SearchNode(
@NonNull Node childNode,
@NonNull List<PropertyPath> propertyPaths
)
Create a SearchNode
representing the query function `search(queryString, createList(listOfProperties)`.
Public methods
addPropertyPath
public void addPropertyPath(@NonNull PropertyPath propertyPath)
Add a restrict to the end of the current list of restricts mPropertyPaths
.
getChild
public @NonNull Node getChild()
Returns the child query searched for in the function.
getChildren
public @NonNull List<Node> getChildren()
Returns the child Node
of SearchNode
as a list containing the only child Node
.
getFunctionName
public @NonNull String getFunctionName()
Returns the name of the function represented by SearchNode
.
getPropertyPaths
public @NonNull List<PropertyPath> getPropertyPaths()
Returns the list of property restricts applied to the query. If the list is empty, there are no property restricts, which means that `search` will return all results from the query.
setChild
public void setChild(@NonNull Node childNode)
Sets the query searched for in the function.
setPropertyPaths
public void setPropertyPaths(@NonNull List<PropertyPath> properties)
Sets what property restricts will be applied to the query.
toString
public @NonNull String toString()
Get the query string representation of SearchNode
.
If there are no property restricts, then the string representation is the function name followed by the string representation of the child subquery as a string literal, surrounded by parentheses. For example the node represented by
TextNode node = new TextNode("foo"); SearchNode searchNode = new SearchNode(node);
If there are property restricts, i.e. getPropertyPaths
is not empty, then in addition to the string representation of the child subquery, the property restricts will be represented as inputs to the createList
function, which itself will be an input. So for the node represented by
List<PropertyPath> propertyPaths = List.of(new PropertyPath("example.path"), new PropertyPath("anotherPath")); TextNode node = new TextNode("foo"); SearchNode searchNode = new SearchNode(node, propertyPaths);
Operators in the query string are supported. As such additional escaping are applied to ensure that operators stay scoped to the search node. This applies recursively, so if we had three layers of search i.e. a search function that takes a query containing a nested search, we would apply three levels of escaping. So for the node represented by
TextNode node = new TextNode("foo"); node.setVerbatim(true); SearchNode nestedSearchNode = new SearchNode(node); SearchNode searchNode = new SearchNode(nestedSearchNode);
searchNode
will be `search("search(\"(\\\"foo\\\")\")")`