TextNode
@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 |
|---|
|
Copy constructor that takes in |
|
Public constructor for |
Public functions |
|
|---|---|
Boolean |
|
String |
getValue()Retrieve the string value that the TextNode holds. |
Int |
hashCode() |
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. |
Boolean |
Whether or not a TextNode represents a quoted string. |
Unit |
Set whether or not the |
Unit |
Set the text value that the |
Unit |
setVerbatim(isVerbatim: Boolean)Set whether or not the |
String |
toString()Get the query string representation of |
Public constructors
TextNode
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.
Public functions
getValue
fun getValue(): String
Retrieve the string value that the TextNode holds.
| Returns | |
|---|---|
String |
A string representing the text that the TextNode holds. |
isPrefix
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
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
fun setPrefix(isPrefix: Boolean): Unit
Set whether or not the TextNode represents a prefix. If true, the TextNode represents a prefix match for value.
setValue
fun setValue(value: String): Unit
Set the text value that the TextNode holds.
setVerbatim
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.
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.