# SearchNode

Artifact: [androidx.appsearch:appsearch](https://developer.android.com/jetpack/androidx/releases/appsearch) [View Source](https://cs.android.com/search?q=file:androidx/appsearch/ast/query/SearchNode.java+class:androidx.appsearch.ast.query.SearchNode) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

*** ** * ** ***


```
@ExperimentalAppSearchApi
class SearchNode : FunctionNode
```

<br />

*** ** * ** ***

`https://developer.android.com/reference/kotlin/androidx/appsearch/ast/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 |
|---|
| `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode#SearchNode(androidx.appsearch.ast.Node)(childNode: https://developer.android.com/reference/kotlin/androidx/appsearch/ast/Node)` Create a `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode` representing the query function \`search(queryString)\`. |
| `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode#SearchNode(androidx.appsearch.ast.Node,java.util.List<androidx.appsearch.app.PropertyPath>)(childNode: https://developer.android.com/reference/kotlin/androidx/appsearch/ast/Node, propertyPaths: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/appsearch/app/PropertyPath!>)` Create a `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode` representing the query function \`search(queryString, createList(listOfProperties)\`. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode#addPropertyPath(androidx.appsearch.app.PropertyPath)(propertyPath: https://developer.android.com/reference/kotlin/androidx/appsearch/app/PropertyPath)` Add a restrict to the end of the current list of restricts `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode#mPropertyPaths()`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode#equals(java.lang.Object)(o: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html!)` |
| `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/Node` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode#getChild()()` Returns the child query searched for in the function. |
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/appsearch/ast/Node!>` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode#getChildren()()` Returns the child `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/Node` of `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode` as a list containing the only child `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/Node`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode#getFunctionName()()` Returns the name of the function represented by `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode`. |
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/appsearch/app/PropertyPath!>` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode#getPropertyPaths()()` Returns the list of property restricts applied to the query. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode#hashCode()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode#setChild(androidx.appsearch.ast.Node)(childNode: https://developer.android.com/reference/kotlin/androidx/appsearch/ast/Node)` Sets the query searched for in the function. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode#setPropertyPaths(java.util.List<androidx.appsearch.app.PropertyPath>)(properties: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/appsearch/app/PropertyPath!>)` Sets what property restricts will be applied to the query. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode#toString()()` Get the query string representation of `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode`. |

| ### Inherited Constants |
|---|
| From [androidx.appsearch.ast.FunctionNode](https://developer.android.com/reference/kotlin/androidx/appsearch/ast/FunctionNode) |---|---| | `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/FunctionNode#FUNCTION_NAME_GET_SEARCH_STRING_PARAMETER() = "getSearchStringParameter"` Name of the query function represented by `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/GetSearchStringParameterNode`. | | `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/FunctionNode#FUNCTION_NAME_HAS_PROPERTY() = "hasProperty"` Name of the query function represented by `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/HasPropertyNode`. | | `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/FunctionNode#FUNCTION_NAME_PROPERTY_DEFINED() = "propertyDefined"` Name of the query function represented by `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/PropertyDefinedNode`. | | `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/FunctionNode#FUNCTION_NAME_SEARCH() = "search"` Name of the query function represented by `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode`. | | `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/FunctionNode#FUNCTION_NAME_SEMANTIC_SEARCH() = "semanticSearch"` Name of the query function represented by `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SemanticSearchNode`. | |

## Public constructors

### SearchNode

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
SearchNode(childNode: Node)
```

Create a `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/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.

| Parameters |
|---|---|
| `childNode: https://developer.android.com/reference/kotlin/androidx/appsearch/ast/Node` | The query to search for represented as a `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/Node`. |

### SearchNode

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
SearchNode(childNode: Node, propertyPaths: (Mutable)List<PropertyPath!>)
```

Create a `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode` representing the query function \`search(queryString, createList(listOfProperties)\`.

| Parameters |
|---|---|
| `childNode: https://developer.android.com/reference/kotlin/androidx/appsearch/ast/Node` | The query to search for represented as a `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/Node`. |
| `propertyPaths: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/appsearch/app/PropertyPath!>` | A list of property paths to restrict results from the query. If the list is empty, all results from the query will be returned. |

## Public functions

### addPropertyPath

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun addPropertyPath(propertyPath: PropertyPath): Unit
```

Add a restrict to the end of the current list of restricts `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode#mPropertyPaths()`.

### equals

```
fun equals(o: Any!): Boolean
```

### getChild

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun getChild(): Node
```

Returns the child query searched for in the function.

### getChildren

```
fun getChildren(): (Mutable)List<Node!>
```

Returns the child `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/Node` of `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode` as a list containing the only child `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/Node`.

### getFunctionName

```
fun getFunctionName(): String
```

Returns the name of the function represented by `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode`.

### getPropertyPaths

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun getPropertyPaths(): (Mutable)List<PropertyPath!>
```

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.

### hashCode

```
fun hashCode(): Int
```

### setChild

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun setChild(childNode: Node): Unit
```

Sets the query searched for in the function.

### setPropertyPaths

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun setPropertyPaths(properties: (Mutable)List<PropertyPath!>): Unit
```

Sets what property restricts will be applied to the query.

### toString

```
fun toString(): String
```

Get the query string representation of `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/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

```kotlin
TextNode node = new TextNode("foo");
SearchNode searchNode = new SearchNode(node);
```
will be represented by the query string \`search("(foo)")\`.

If there are property restricts, i.e. `https://developer.android.com/reference/kotlin/androidx/appsearch/ast/query/SearchNode#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

```kotlin
List<PropertyPath> propertyPaths = List.of(new PropertyPath("example.path"),
                                           new PropertyPath("anotherPath"));
TextNode node = new TextNode("foo");
SearchNode searchNode = new SearchNode(node, propertyPaths);
```
the query string will be \`search("(foo)", createList("example.path", "anotherPath"))\`.

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

```kotlin
TextNode node = new TextNode("foo");
node.setVerbatim(true);
SearchNode nestedSearchNode = new SearchNode(node);
SearchNode searchNode = new SearchNode(nestedSearchNode);
```
the query string of `searchNode` will be \`search("search(\\"(\\\\\\"foo\\\\\\")\\")")\`