> ## 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 EU frameworks with the Law4Devs Java SDK.

## Overview

The search endpoint lets you query across all frameworks simultaneously. Results include articles, recitals, and requirements that match your query. Use `client.search().query()` to search.

***

## Methods

### `query(String q)`

Search across all frameworks with default pagination.

```java theme={null}
Page<SearchResult> results = client.search().query("incident notification 72 hours");

System.out.printf("Found %d results%n", results.meta().total());
for (SearchResult r : results.data()) {
    System.out.printf("  [%s] %s — %s%n",
        r.frameworkSlug().toUpperCase(),
        r.type(),
        r.title() != null ? r.title() : r.matchContext());
}
```

**Returns** `Page<SearchResult>`

***

### `query(String q, String framework, String resultType, int page, int perPage)`

Search with optional framework scope, result type filter, and custom pagination.

```java theme={null}
Page<SearchResult> results = client.search().query(
    "breach notification",   // query
    "gdpr",                  // framework filter (null = all)
    "article",               // result type filter (null = all)
    1,                       // page
    20                       // perPage
);
```

**Parameters**

| Parameter    | Type     | Default  | Description                                               |
| ------------ | -------- | -------- | --------------------------------------------------------- |
| `q`          | `String` | required | Search query                                              |
| `framework`  | `String` | `null`   | Limit to one framework slug                               |
| `resultType` | `String` | `null`   | Filter by type: `"article"`, `"recital"`, `"requirement"` |
| `page`       | `int`    | `1`      | Page number                                               |
| `perPage`    | `int`    | `20`     | Items per page                                            |

**Returns** `Page<SearchResult>`

***

### `iter(String q)`

Lazily iterate all search results for a query.

```java theme={null}
for (SearchResult r : client.search().iter("cyber resilience")) {
    System.out.printf("[%s] %s%n", r.frameworkSlug(), r.matchContext());
}
```

**Returns** `Iterable<SearchResult>`

***

### `iter(String q, String framework, String resultType)`

Lazily iterate with optional framework and result-type filters.

```java theme={null}
for (SearchResult r : client.search().iter("encryption", "cra", "requirement")) {
    System.out.println(r.matchContext());
}
```

**Returns** `Iterable<SearchResult>`

***

## Model

### `SearchResult`

| Field               | Type     | Description                                  |
| ------------------- | -------- | -------------------------------------------- |
| `type()`            | `String` | `"article"`, `"recital"`, or `"requirement"` |
| `frameworkSlug()`   | `String` | Framework the result belongs to              |
| `frameworkName()`   | `String` | Human-readable framework name                |
| `articleNumber()`   | `String` | For article results                          |
| `recitalNumber()`   | `String` | For recital results                          |
| `paragraphRef()`    | `String` | Specific paragraph reference                 |
| `title()`           | `String` | Result heading, if any                       |
| `requirementType()` | `String` | For requirement results                      |
| `matchContext()`    | `String` | Snippet showing the match in context         |
| `url()`             | `String` | Direct API URL to the full resource          |

***

## Examples

### Search within a specific framework

```java theme={null}
Page<SearchResult> results = client.search().query(
    "breach notification", "gdpr", null, 1, 20);

for (SearchResult r : results.data()) {
    System.out.println(r.frameworkSlug() + " — " +
        (r.title() != null ? r.title() : r.matchContext()));
}
```

### Filter by result type

```java theme={null}
Page<SearchResult> results = client.search().query(
    "encryption at rest", null, "requirement", 1, 20);

for (SearchResult r : results.data()) {
    System.out.println("- " + r.matchContext());
}
```

### Cross-framework comparison

```java theme={null}
String[] frameworks = {"nis2", "dora", "cra"};
for (String fw : frameworks) {
    Page<SearchResult> r = client.search().query(
        "incident notification", fw, null, 1, 1);
    System.out.printf("%-6s %d results%n", fw, r.meta().total());
}
```

<Tip>
  Use the `framework` parameter to narrow results when you know which regulation you're working with. Cross-framework search (without a filter) is great for discovering related obligations across different laws.
</Tip>
