> For the complete documentation index, see [llms.txt](https://kinesis-school-of-programming.gitbook.io/nestjs-unleashed/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kinesis-school-of-programming.gitbook.io/nestjs-unleashed/extra-module-5-advanced-querying/filtering-and-sorting/encapsulating-text-filter.md).

# Encapsulating text filter

A method for checking if a text contains a fragment.

Before finishing this section, let's just make two improvements. First, we are finding products whose <mark style="color:blue;">`name`</mark> contains a received text. Well, this behavior is quite common, and is probably going to appear elsewhere at some moment. So, it would be interesting to encapsulate this logic. Let's then begin by creating a service for filtering.

```sh
nest g s querying/filtering --flat
```

{% hint style="info" %}
Already **export** this service, as it will be used afterwards.
{% endhint %}

In it, we may create a method called <mark style="color:blue;">`contains()`</mark>, which is a simple and intuitive name. If we also check there if the <mark style="color:blue;">`text`</mark> exists, we avoid having to manually return <mark style="color:blue;">undefined</mark>.

```typescript
contains(text: string) {
  if (!text) return;

  return ILike(`%${text}%`);
}
```

Now, we just need to inject the <mark style="color:blue;">`filteringService`</mark> and use it.

```typescript
name: this.filteringService.contains(name),
```

<mark style="color:green;">**Commit**</mark> - Method to check if field contains text
