UC8 - Enable Search for Text

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.

See Also
SEARCH
RESULT SET
Search Field
Defining Data Queries
Interacting with Top Bar Search
  1. Create an input parameter to inject users' query terms into the data query.
    1. From the top bar, click $ Input parameters.
    2. In the Parameters panel, click to add a Parameter.
    3. Give a name to the parameter. For example, search_parameter.
    4. For Return type, select String.
    5. For Default value, define an empty string by entering "".
    6. Select DataQuery parameter, to make the input parameter available in data queries.
  2. Add a SEARCH operator to the data query.    
    1. Select an Index unit.
    2. In Variable, select an index unit class, and specify the name of the variable that you will use in the Expression field.
  3. Configure the Expression with a Text.hasTerm() function.
    1. In Expression, click .
    2. 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: )

    3. For attribute: specify the attribute that contains the text on which you want to search for. For example, attribute: country.`Introduction`.
    4. 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:
      Text.hasTerm(attribute: country.`Introduction`, term: "myterm".(normalize())

  4. 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).

  5. Test your configuration.
    1. Click Run.
    2. In the bottom field, define a view, for example, a table view.
    3. 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.