# `textSearch`

## Description

Searches for a text phrase within a target value.

The behavior depends on the type of the target:

- **Primitive types** (`string`, `number`, `bool`, `interval`, `timestamp`, `regexp`, `enum`) are converted to strings before searching.
- **Objects** are searched by their values (keys are ignored).
- **Arrays** are searched by their elements.

The `phrase` must appear as one or more complete tokens. Tokens are defined during log parsing and are split on the following characters: whitespace (`\s`), `=`, `/`, `:`, `@`, `#`, `$`, `*`, `|`, `,`, `;`, `'`, `"`, `(`, `[`, `{`, `}`, `)`, `]`, `<`, `>`, `.`, `_`, `-`.

Because of this, a search for `online` will not match `onlineboutique` (one token), but will match `online_boutique` (`online` and `boutique` are separate tokens). Similarly, `Version 17` matches `Version 17.4 (Build 21E213)` because `Version` and `17` are two tokens, but `Vers` would not match because it is not a full token.

## Syntax

Like many functions in DataPrime, `textSearch` supports [two notations](https://coralogix.com/docs/dataprime/language-reference/functions-reference/index.md), **function** and **method** notation. These interchangeable forms allow flexibility in how you structure expressions.

```dataprime
textSearch(target: T, phrase: string): bool
```

```dataprime
(target: T).textSearch(phrase: string): bool
```

## Arguments

| Name   | Type   | Required | Description                                                                                                                     |
| ------ | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------- |
| target | T      | **true** | Must be one of `string`, `bool`, `number`, `interval`, `timestamp`, `regexp`, or `enum`. Objects and arrays are also supported. |
| phrase | string | **true** | The search string. Must be a literal value, not the result of a calculation                                                     |

## Example

**Find a string in a complex object**

Use `textSearch` to locate the value `"mi"` inside nested arrays and objects:

### Example data

```json
{
    "doc": {
        "id": 1,
        "name": "woods",
        "warning": "mi",
        "details": {
        "level": 3,
        "message": "proceed cautiously",
        }
    },
    "doc": {
        "id": 2,
        "type": "fortress",
        "extra": {"fun_fact": "mi"}
    },
    "doc": {
        "id": 5,
        "village": "stonekeep",
        "motto": "it is a curious place",
    }
}
```

### Example query

```dataprime
textSearch(doc, 'mi')
```

```dataprime
doc.textSearch('mi')
```

### Example output

```json
{
    true,
    true,
    false
}
```
