# Search Media Items

Search for media items by title, author, series, tags, or contributors.

**Note:** Search is case-insensitive and punctuation-agnostic. The search query is matched against normalized tags_search and contributors_search fields, allowing users to find matches regardless of casing or punctuation.

Examples:

- Search "acme corp" finds items with "ACME CORP." or "Acme Corp"
- Search "oreilly" finds items with "O'Reilly Media" or "OReilly Media"
- Search "science fiction" finds items with "Science-Fiction" or "science-fiction"

**Endpoint**: `GET /api/media-items/search`
**Auth**: Required

## Query Parameters

| Parameter | Type    | Required | Description                                 |
| --------- | ------- | -------- | ------------------------------------------- |
| q         | string  | Yes      | Search query (minimum 2 characters)        |
| library_id| string  | No       | Filter results to specific library (UUID)  |
| limit     | integer | No       | Number of results (default 20)             |
| offset    | integer | No       | Number to skip                              |

## Request Headers

| Header        | Type   | Required | Description  |
| ------------- | ------ | -------- | ------------ |
| Authorization | string | Yes      | Bearer token |

### Example Request

Search all libraries:

```http
GET /api/media-items/search?q=Harry+Potter&limit=20&offset=0
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
```

Search within a specific library:

```http
GET /api/media-items/search?q=Harry&library_id=123e4567-e89b-12d3-a456-426614174000&limit=20
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
```

## Response (200 OK)

```json
{
  "results": [
    {
      "id": "uuid",
      "title": "Book Title",
      "author": "Author Name",
      "library_id": "...",
      "library_name": "E-Books",
      "match_score": 0.95
    }
  ],
  "total": 15
}
```

## Error Responses

| Code | Description                      |
| ---- | -------------------------------- |
| 400  | Invalid search query (too short) |
| 401  | Invalid or expired token         |
