# TextNode

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

*** ** * ** ***


```
@ExperimentalAppSearchApi
public final class TextNode implements Node
```

<br />

*** ** * ** ***

`https://developer.android.com/reference/androidx/appsearch/ast/Node` that stores text.

Text may represent a string or number. For example in the query \`hello AND "world peace" -cat price:49.99\`

- hello and cat are strings.
- "world peace" is a verbatim string, i.e. a quoted string that can be represented by setting mVerbatim to true. Because it is a verbatim string, it will be treated as a single term "world peace" instead of terms "world" and "peace".
- 49.99 is a number. `https://developer.android.com/reference/androidx/appsearch/ast/TextNode`s may represent integers or doubles and treat numbers as terms.
- price is NOT a string but a property path as part of a `https://developer.android.com/reference/androidx/appsearch/ast/operators/PropertyRestrictNode`.

The node will be segmented and normalized based on the flags set in the Node. For example, if the node containing the string "foo" has both mPrefix and mVerbatim set to true, then the resulting tree will be treated as the query \`"foo"\*\` i.e. the prefix of the quoted string "foo".

`https://developer.android.com/reference/androidx/appsearch/ast/TextNode`s is guaranteed to not have child nodes.

This API may change in response to feedback and additional changes.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/appsearch/ast/TextNode#TextNode(androidx.appsearch.ast.TextNode)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/ast/TextNode original)` Copy constructor that takes in `https://developer.android.com/reference/androidx/appsearch/ast/TextNode`. |
| `https://developer.android.com/reference/androidx/appsearch/ast/TextNode#TextNode(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html value)` Public constructor for `https://developer.android.com/reference/androidx/appsearch/ast/TextNode` representing text passed into the constructor as a string. |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/appsearch/ast/TextNode#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object.html o)` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/appsearch/ast/TextNode#getValue()()` Retrieve the string value that the TextNode holds. |
| `int` | `https://developer.android.com/reference/androidx/appsearch/ast/TextNode#hashCode()()` |
| `boolean` | `https://developer.android.com/reference/androidx/appsearch/ast/TextNode#isPrefix()()` Whether or not a TextNode represents a query term that will match indexed tokens when the query term is a prefix of the token. |
| `boolean` | `https://developer.android.com/reference/androidx/appsearch/ast/TextNode#isVerbatim()()` Whether or not a TextNode represents a quoted string. |
| `void` | `https://developer.android.com/reference/androidx/appsearch/ast/TextNode#setPrefix(boolean)(boolean isPrefix)` Set whether or not the `https://developer.android.com/reference/androidx/appsearch/ast/TextNode` represents a prefix. |
| `void` | `https://developer.android.com/reference/androidx/appsearch/ast/TextNode#setValue(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html value)` Set the text value that the `https://developer.android.com/reference/androidx/appsearch/ast/TextNode` holds. |
| `void` | `https://developer.android.com/reference/androidx/appsearch/ast/TextNode#setVerbatim(boolean)(boolean isVerbatim)` Set whether or not the `https://developer.android.com/reference/androidx/appsearch/ast/TextNode` represents a quoted string, i.e. verbatim. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/appsearch/ast/TextNode#toString()()` Get the query string representation of `https://developer.android.com/reference/androidx/appsearch/ast/TextNode`. |

| ### Inherited methods |
|---|
| From [androidx.appsearch.ast.Node](https://developer.android.com/reference/androidx/appsearch/ast/Node) |---|---| | `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/appsearch/ast/Node>` | `https://developer.android.com/reference/androidx/appsearch/ast/Node#getChildren()()` Get a list of the node's child `https://developer.android.com/reference/androidx/appsearch/ast/Node`s. | |

## Public constructors

### TextNode

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

```
public TextNode(@NonNull TextNode original)
```

Copy constructor that takes in `https://developer.android.com/reference/androidx/appsearch/ast/TextNode`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/ast/TextNode original` | The `https://developer.android.com/reference/androidx/appsearch/ast/TextNode` to copy and return another `https://developer.android.com/reference/androidx/appsearch/ast/TextNode`. |

### TextNode

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

```
public TextNode(@NonNull String value)
```

Public constructor for `https://developer.android.com/reference/androidx/appsearch/ast/TextNode` representing text passed into the constructor as a string.

By default `https://developer.android.com/reference/androidx/appsearch/ast/TextNode#mPrefix()` and `https://developer.android.com/reference/androidx/appsearch/ast/TextNode#mVerbatim()` are both false. In other words the `https://developer.android.com/reference/androidx/appsearch/ast/TextNode` represents a term that is not the prefix of a potentially longer term that could be matched against and not a quoted string to be treated as a single term.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html value` | The text value that `https://developer.android.com/reference/androidx/appsearch/ast/TextNode` holds. |

## Public methods

### equals

```
public boolean equals(Object o)
```

### getValue

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

```
public @NonNull String getValue()
```

Retrieve the string value that the TextNode holds.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | A string representing the text that the TextNode holds. |

### hashCode

```
public int hashCode()
```

### isPrefix

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

```
public boolean isPrefix()
```

Whether or not a TextNode represents a query term that will match indexed tokens when the query term is a prefix of the token.

For example, if the value of the TextNode is "foo" and mPrefix is set to true, then the TextNode represents the query \`foo\*\`, and will match against tokens like "foo", "foot", and "football".

If mPrefix and mVerbatim are both true, then the TextNode represents the prefix of the quoted string. For example if the value of the TextNode is "foo bar" and both mPrefix and mVerbatim are set to true, then the TextNode represents the query \`"foo bar"\*\`.

| Returns |
|---|---|
| `boolean` | True, if the TextNode represents a query term that will match indexed tokens when the query term is a prefix of the token. False, if the TextNode represents a query term that will only match exact tokens in the index. |

### isVerbatim

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

```
public boolean isVerbatim()
```

Whether or not a TextNode represents a quoted string.

For example, if the value of the TextNode is "foo bar" and mVerbatim is set to true, then the TextNode represents the query \`"foo bar"\`. "foo bar" will be treated as a single token and match documents that have a property marked as verbatim and exactly contain "foo bar".

If mVerbatim and mPrefix are both true, then the TextNode represents the prefix of the quoted string. For example if the value of the TextNode is "foo bar" and both mPrefix and mVerbatim are set to true, then the TextNode represents the query \`"foo bar"\*\`.

| Returns |
|---|---|
| `boolean` | True, if the TextNode represents a quoted string. For example, if the value of TextNode is "foo bar", then the query represented is \`"foo bar"\`. This means "foo bar" will be treated as one term, matching documents that have a property marked as verbatim and contains exactly "foo bar". False, if the TextNode does not represent a quoted string. For example, if the value of TextNode is "foo bar", then the query represented is \`foo bar\`. This means that "foo" and "bar" will be treated as separate terms instead of one term and implicitly ANDed, matching documents that contain both "foo" and "bar". |

### setPrefix

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

```
public void setPrefix(boolean isPrefix)
```

Set whether or not the `https://developer.android.com/reference/androidx/appsearch/ast/TextNode` represents a prefix. If true, the `https://developer.android.com/reference/androidx/appsearch/ast/TextNode` represents a prefix match for `value`.

| Parameters |
|---|---|
| `boolean isPrefix` | Whether or not the `https://developer.android.com/reference/androidx/appsearch/ast/TextNode` represents a prefix. If true, it represents a query term that will match against indexed tokens when the query term is a prefix of token. |

### setValue

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

```
public void setValue(@NonNull String value)
```

Set the text value that the `https://developer.android.com/reference/androidx/appsearch/ast/TextNode` holds.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html value` | The string that the `https://developer.android.com/reference/androidx/appsearch/ast/TextNode` will hold. |

### setVerbatim

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

```
public void setVerbatim(boolean isVerbatim)
```

Set whether or not the `https://developer.android.com/reference/androidx/appsearch/ast/TextNode` represents a quoted string, i.e. verbatim. If true, the `https://developer.android.com/reference/androidx/appsearch/ast/TextNode` represents a quoted string.

| Parameters |
|---|---|
| `boolean isVerbatim` | Whether or not the `https://developer.android.com/reference/androidx/appsearch/ast/TextNode` represents a quoted string. If true, it represents a quoted string. |

### toString

```
public @NonNull String toString()
```

Get the query string representation of `https://developer.android.com/reference/androidx/appsearch/ast/TextNode`.

If no flags are set, then the string representation is just the value held by `https://developer.android.com/reference/androidx/appsearch/ast/TextNode`. Otherwise the value will be formatted depending on the combination of flags set.

The string representation of `https://developer.android.com/reference/androidx/appsearch/ast/TextNode` maybe different from `https://developer.android.com/reference/androidx/appsearch/ast/TextNode#mValue()` if it contains operators that need to be escaped for the query string to be treated as a string rather than a query.