Searching for text in the index is a very common use case, that you can configure
using the Text.hasTerm() expression in your data query. This expression
retrieves entries from fields of text type in your data model.
Note:
The String.contains function is different and allows you to
introspect the whole data query in its transformation process, to find a string. It is much
slower than using a search in the index with Text.hasTerm(). Moreover, it
does not support tokenization, even if it should normally split on every nonletter
character.
Create an input parameter to inject users' query terms into the data query.
From the top bar, click $ Input parameters.
In the Parameters panel, click to add a Parameter.
Give a name to the parameter. For example, search_parameter.
For Return type, select String.
For Default value, define an empty string by entering
"".
Select DataQuery parameter, to make the input parameter
available in data queries.
Add a SEARCH operator to the data query.
Select an Index unit.
In Variable, select an index unit class, and specify the
name of the variable that you will use in the Expression
field.
Configure the Expression with a Text.hasTerm()
function.
In Expression, click .
In the Expression Editor, start entering
text and use the completion to select the
Text.hasTerm() function.
It adds the following expression:
Text.hasTerm(attribute: , term: )
For attribute: specify the attribute that contains the text on
which you want to search for. For example, attribute:
country.`Introduction`.
For term: specify the input parameter specified in step 1. For
example, term: $search_parameter.
Recommendation:
Use the normalize() function after your
term so that the query will not take into account accents and capital letters. The
expression should look like:
Link a RESULT SET operator to the end of the data query.
Define the fields that you want to retrieve in the data query, including the text
field on which you want to apply the text search (for example
Introduction).
Test your configuration.
Click Run.
In the bottom field, define a view, for example, a table view.
Click $ Input parameters and enter a term that you want to
search for in the text field.
The view refreshes to show all the entries containing the term you searched
for.