SEARCH

In a data query, you can use the SEARCH operator to target a specific item type in the index, including its type subclasses.

For example, if you search for the employee item type, you get entries for engineers, consultants, managers, etc., which are subclasses of that item type.

This page discusses:

See Also
UC8 - Enable Search for Text
Discovering Index Units with the IU Browser
Expression Language
Defining Data Queries

Input

The SEARCH operator is a source so it has no input.

Output

By default, the output of this operator is a stream with multiple elements. The type of the elements in the stream depends on the configuration.

If you select the Advanced > Use matching annotations option, the type of element in the output stream becomes a tuple (see below).

Note: The SEARCH operator does not order the output stream, even if you activate the text scoring in Advanced > Use matching annotations.

General Parameters

Parameter Description
Label

Specify the label to display below the operator type in the data query.

Description

Add a description to display as tooltip on hover over the operator icon.

Tip: It is useful to explain what the operator does, especially when you share the data query with other users.

Search Clause Configuration

The operator returns the selected index unit elements that match a predicate (Boolean condition).

  1. Define an Index unit.
    Note: You can only select the index units created on the same tenant, and shared with users having the Data Analyst (DAA) role.
    • In Value mode, you can select an index unit directly. The default index unit is 3DSpace.
    • In $ (parameter) mode, you can select an Index Unit Parameter defined beforehand in $ Input parameters. For more information, see Creating Input Parameters.
  2. Optional: To explore the index unit and find the class to use in Variable, click to open the Index Unit Browser.
  3. In Variable, select an index unit class, and specify the name of the variable, that you will use in the Expression field.

    For example, you select the Person type and enter person as variable name.

  4. In Expression, configure the expression used to filter the results.

    For example, enter the following expression (its return type must be a Boolean):

    person.age > 30 AND person.city = "New York City"

    The operator returns every item of the Person type (including the Employee type) with an age higher than 30 and living in New York City.

Matching Annotations and Text Scoring

You can select Advanced > Use matching annotations to specify matching annotations. These are metadata, which indicate how the item has matched the expression. Matching annotations can be implicit or explicit.

The query engine computes implicit annotations internally, without explicit declaration in the Expression. It is an implicit annotation named score that generates the text scoring.

You declare explicit annotations in the Expression.

Example

  • Expression: person.age > 30 AND ( (person.city == "New York City"){city=1} OR (person.city == "Miami"){city=2} )
  • Matching annotations: city and score

With the explicit matching annotation city, the operator annotates the items that match the query with city=1 or city=2 depending on the city.

If you add matching annotations, the output type of the operator changes to Tuple. The output displays a tuple containing an item and the different matching annotations (ma) that have been listed.

For the example above, the output is:

Tuple
  item:Item<athletes.Events> 
  ma:Tuple
    city:Integer 
    score:Integer
Tip: You can see this output when hovering over the link coming out of the SEARCH operator.

Builtin Matching Annotation

You can use matching annotations to know the frequency of terms in text.

Example 1

Input:

  • Expression: Text.hasTerm(item.text, "car")
  • Matching annotations: score

Output:

Tuple
  item: Item<core.Item>
  ma: Tuple
    score: Integer

For example:

{
  item: {
    ...
    text: "I love car"
  },
  ma: {
    score: 16
  }
},
{
  item: {
    ...
    text: "I love my car and cars are eveything for me"
  },
  ma: {
    score: 32
  }
},

Example 2

Input:

  • Expression: Text.hasTerm(item.text, "car"){boost= 10} OR Text.hasTerm(item.text, "literature")
  • Matching annotations: score and boost.

Output:

Tuple
  item: Item<core.Item>
  ma: Tuple
    score: Integer
    boost: Integer

For example:

{
  item: {
    ...
    text: "I love car"
  },
  ma: {
    score: 160
  }
},
{
  item: {
    ...
    text: "I love car because cars are eveything for me"
  },
  ma: {
    score: 320
  }
},
{
  item: {
    ...
    text: "I love litterature"
  },
  ma: {
    score: 42
  }
},

In this example, the scores of the item.text containing car have been multiplied by 10, as specified with {boost= 10} in the expression.

Other Use of Matching Annotations

You can use matching annotations for other purposes. They are typically useful when used as "side variables". For example, to know what worked and what did not work.

Input:

  • Expression: Text.hasTerm(item.text, "red"){matchRed= 1} OR Text.hasTerm(item.text, "magenta"){matchMagenta= 1}
  • Matching annotations: matchMagenta and matchRed

Output:

Tuple
  item: Item<core.Item>, 
  ma: Tuple
    matchMagenta: Integer
    matchRed: Integer

For example:

{
  item: {
    ...
    text: "these tulips are red"
  },
  ma: {
    matchMagenta: 0,
    matchRed: 1
  }
},
{
  item: {
    ...
    text: "The ink cartridge color is magenta"
  },
  ma: {
    matchMagenta: 1,
    matchRed: 0
  }
},
{
  item: {
    ...
    text: "John cannot make the difference between red and magenta"
  },
  ma: {
    matchMagenta: 1,
    matchRed: 1
  }
},