> ## Documentation Index
> Fetch the complete documentation index at: https://docs.law4devs.eu/llms.txt
> Use this file to discover all available pages before exploring further.

# Search

> Full-text search across all frameworks with the Law4Devs TypeScript SDK.

## Overview

The search resource provides full-text search across all framework content — articles, recitals, and requirements. Results include a `matchContext` snippet showing the matched text in context.

***

## Methods

### `query()`

Execute a full-text search and return a page of results.

```typescript theme={null}
const results = await client.search.query('data breach notification', {
  framework: 'gdpr',
  resultType: 'article',
  page: 1,
  perPage: 20,
});

console.log(`Found ${results.meta.total} matching articles`);

for (const result of results.data) {
  console.log(`[${result.type}] ${result.frameworkName} Art. ${result.articleNumber}: ${result.title}`);
  console.log(`  ...${result.matchContext}...`);
  console.log(`  ${result.url}`);
}
```

**Parameters**

| Parameter    | Type     | Default  | Description                                                          |
| ------------ | -------- | -------- | -------------------------------------------------------------------- |
| `query`      | `string` | required | Search terms                                                         |
| `framework`  | `string` | —        | Filter results to a specific framework slug                          |
| `resultType` | `string` | —        | Filter by content type: `"article"`, `"recital"`, or `"requirement"` |
| `page`       | `number` | `1`      | Page number                                                          |
| `perPage`    | `number` | `20`     | Items per page (1–100)                                               |

**Returns** `Promise<Page<SearchResult>>`

<Warning>
  `meta.pages` is always `0` for search results. This is an endpoint limitation — use `meta.total` and `links.next` to determine if more results exist.
</Warning>

***

### `iter()`

Iterate over all search results without managing pagination.

```typescript theme={null}
for await (const result of client.search.iter('security requirements')) {
  console.log(`[${result.type}] ${result.frameworkName} — ${result.title ?? result.requirementType}`);
}
```

**Parameters** — same options as `query()` (except `page`, which is managed internally).

**Returns** `AsyncGenerator<SearchResult>`

***

## Model

### `SearchResult`

| Field             | Type             | Description                                               |
| ----------------- | ---------------- | --------------------------------------------------------- |
| `type`            | `string`         | Result type: `"article"`, `"recital"`, or `"requirement"` |
| `frameworkSlug`   | `string`         | Parent framework slug                                     |
| `frameworkName`   | `string`         | Parent framework display name                             |
| `articleNumber`   | `number \| null` | Article number (for article and requirement results)      |
| `recitalNumber`   | `number \| null` | Recital number (for recital results)                      |
| `paragraphRef`    | `string \| null` | Source paragraph reference                                |
| `title`           | `string \| null` | Article title (for article results)                       |
| `requirementType` | `string \| null` | Requirement type (for requirement results)                |
| `matchContext`    | `string`         | Snippet of text surrounding the match                     |
| `url`             | `string`         | Deep link to the matched item in the API                  |

***

## Examples

### Search for a concept across all frameworks

```typescript theme={null}
const results = await client.search.query('legitimate interest');

for (const result of results.data) {
  const ref = result.articleNumber
    ? `Art. ${result.articleNumber}`
    : `Recital ${result.recitalNumber}`;
  console.log(`${result.frameworkName} ${ref}: ...${result.matchContext}...`);
}
```

### Collect all requirement results mentioning a term

```typescript theme={null}
const requirementMatches: SearchResult[] = [];

for await (const result of client.search.iter('incident response', {
  resultType: 'requirement',
})) {
  requirementMatches.push(result);
}

console.log(`Found ${requirementMatches.length} matching requirements`);
```

<Tip>
  Combine `resultType: 'article'` with `iter()` for a simple way to find every article across all frameworks that mentions a specific term — no need to iterate frameworks first.
</Tip>
