# Search (Prompt 5C)

`GET /api/v1/public/search?q=` (+ the story-list filters, `page`, `per_page`) and
`GET /search/suggest?q=`. Stories are indexed through Laravel Scout on the `search`
queue after commit; only publicly visible stories are searchable (`Story::shouldBeSearchable`).

## Drivers

| `SCOUT_DRIVER` | Where | Behaviour |
| --- | --- | --- |
| `opensearch` | staging / production | `App\Support\Search\OpenSearchEngine` (opensearch-php, already installed): Nepali analyser (`indic_normalization`, `decimal_digit`, Nepali stop words), English analyser, `fuzziness: AUTO` (typos), keyword filters, `<mark>` highlights |
| `collection` | local, tests | substring match; Romanised fallback through the phonetic key (each token must start a key word) |

Setup:

```bash
SCOUT_DRIVER=opensearch OPENSEARCH_HOST=https://search.internal:9200 OPENSEARCH_USERNAME=… OPENSEARCH_PASSWORD=…
php artisan scout:index stories            # creates the index with App\Support\Search\StoryIndex::definition()
php artisan scout:import "App\Models\Story" # (re)index published stories
```

## Romanised → Devanagari

`App\Support\Search\Transliteration::key()` reduces Devanagari and Roman text to the same
phonetic key: aspiration dropped, retroflex/dental merged, long vowels shortened, the
inherent "a" removed, doubles collapsed — `धनगढी`, `dhangadhi`, `dhangadi` → `dngdi`;
`बाढी`, `baadhi`, `badhi` → `bdi`. Each story's `phonetic` field holds the keys of its
Nepali headline, summary and tags; queries are keyed the same way and matched as an
extra `should` clause (OpenSearch) or as the fallback (collection).

Index fields: `headline_ne/en`, `summary_ne/en`, `body`, `tag_names`, `phonetic`, and
keyword filters `categories`, `tags`, `topics`, `provinces`, `districts`, `local_levels`,
`authors`, `content_type`, `language`, `flags`, `published_at`.
