@ExperimentalAppSearchApi
class TextNode : 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 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".

TextNodes is guaranteed to not have child nodes.

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

Summary

Public constructors

TextNode(original: TextNode)

Copy constructor that takes in TextNode.

TextNode(value: String)

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

Public functions

Boolean
equals(o: Any!)
String

Retrieve the string value that the TextNode holds.

Int
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.

Unit
setPrefix(isPrefix: Boolean)

Set whether or not the TextNode represents a prefix.

Unit
setValue(value: String)

Set the text value that the TextNode holds.

Unit
setVerbatim(isVerbatim: Boolean)

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

String

Get the query string representation of TextNode.

Inherited functions

From androidx.appsearch.ast.Node
(Mutable)List<Node!>

Get a list of the node's child Nodes.

Public constructors

TextNode

Added in 1.1.0-alpha07
TextNode(original: TextNode)

Copy constructor that takes in TextNode.

Parameters
original: TextNode

The TextNode to copy and return another TextNode.

TextNode

Added in 1.1.0-alpha07
TextNode(value: String)

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
value: String

The text value that TextNode holds.

Public functions

equals

fun equals(o: Any!): Boolean

getValue

Added in 1.1.0-alpha07
fun getValue(): String

Retrieve the string value that the TextNode holds.

Returns
String

A string representing the text that the TextNode holds.

hashCode

fun hashCode(): Int

isPrefix

Added in 1.1.0-alpha07
fun isPrefix(): 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.

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-alpha07
fun isVerbatim(): Boolean

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-alpha07
fun setPrefix(isPrefix: Boolean): Unit

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

Parameters
isPrefix: Boolean

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-alpha07
fun setValue(value: String): Unit

Set the text value that the TextNode holds.

Parameters
value: String

The string that the TextNode will hold.

setVerbatim

Added in 1.1.0-alpha07
fun setVerbatim(isVerbatim: Boolean): Unit

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

Parameters
isVerbatim: Boolean

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

toString

fun toString(): String

Get the query string representation of TextNode.

If no flags are set, then the string representation is just the value held by TextNode. Otherwise the value will be formatted depending on the combination of flags set.

The string representation of TextNode maybe different from mValue if it contains operators that need to be escaped for the query string to be treated as a string rather than a query.