@ExperimentalAppSearchApi
public final class TextNode implements Node


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. TextNodes may represent integers or doubles and treat numbers as terms.
  • price is NOT a string but a property path as part of a 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".

TextNodes is guaranteed to not have child nodes.

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

Summary

Public constructors

Copy constructor that takes in TextNode.

Public constructor for TextNode representing text passed into the constructor as a string.

Public methods

@NonNull String

Retrieve the string value that the TextNode holds.

boolean

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

Whether or not a TextNode represents a quoted string.

void
setPrefix(boolean isPrefix)

Set whether or not the TextNode represents a prefix.

void

Set the text value that the TextNode holds.

void
setVerbatim(boolean isVerbatim)

Set whether or not the TextNode represents a quoted string, i.e. verbatim.

Inherited methods

From androidx.appsearch.ast.Node
@NonNull List<Node>

Get a list of the node's child Nodes.

Public constructors

TextNode

Added in 1.1.0-alpha06
public TextNode(@NonNull TextNode original)

Copy constructor that takes in TextNode.

Parameters
@NonNull TextNode original

The TextNode to copy and return another TextNode.

TextNode

Added in 1.1.0-alpha06
public TextNode(@NonNull String value)

Public constructor for TextNode representing text passed into the constructor as a string.

By default mPrefix and mVerbatim are both false. In other words the 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
@NonNull String value

The text value that TextNode holds.

Public methods

getValue

Added in 1.1.0-alpha06
public @NonNull String getValue()

Retrieve the string value that the TextNode holds.

Returns
@NonNull String

A string representing the text that the TextNode holds.

isPrefix

Added in 1.1.0-alpha06
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-alpha06
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-alpha06
public void setPrefix(boolean isPrefix)

Set whether or not the TextNode represents a prefix. If true, the TextNode represents a prefix match for value.

Parameters
boolean isPrefix

Whether or not the 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-alpha06
public void setValue(@NonNull String value)

Set the text value that the TextNode holds.

Parameters
@NonNull String value

The string that the TextNode will hold.

setVerbatim

Added in 1.1.0-alpha06
public void setVerbatim(boolean isVerbatim)

Set whether or not the TextNode represents a quoted string, i.e. verbatim. If true, the TextNode represents a quoted string.

Parameters
boolean isVerbatim

Whether or not the TextNode represents a quoted string. If true, it represents a quoted string.