4.5 KiB
meilisearch-showcase
A small, production-shaped Go demo of Meilisearch: full-text search with typo tolerance, prefix search, filters, facets and highlighting — wrapped in a Domain-Driven Design layout and driven by Task.
Why it is structured this way
The interesting part of a search demo is not the SDK calls, it is keeping the search engine out of your business code. Meilisearch is an infrastructure detail behind a port:
cmd/ process entrypoints (api, seed)
internal/
domain/catalog/ entities, value objects, invariants, PORTS
movie.go Movie aggregate + MovieID value object
search.go Query/Results value objects + MovieIndex port
app/ use cases (import, search, get, delete)
infra/
meili/ DRIVEN adapter: MovieIndex -> Meilisearch
config/ env configuration
interfaces/http/ DRIVING adapter: HTTP -> use cases
test/ integration tests against a live Meilisearch
Dependencies point inwards only. internal/domain and internal/app import
nothing from Meilisearch — go list -deps proves it. Swapping in Elastic or a
plain map means writing one new adapter, not touching the domain.
The domain speaks catalog.Query{Genre, MinYear, MinRating}; the adapter
translates that into Meilisearch filter syntax (internal/infra/meili/filter.go).
Documents indexed in Meilisearch use a separate persistence model
(meili.document) that is mapped to/from the aggregate, so the read model can
change without breaking invariants.
Requirements
- Go 1.27+
- Docker (for
task meili:up) — or any reachable Meilisearch, setMEILI_HOST - Task
Quick start
task meili:up # Meilisearch v1.24 on :7700
task seed # create index, apply settings, load data/movies.json
task run # API on :8080
# in another shell:
task query # runs scripts/demo-queries.sh
task demo chains up + seed + queries in one go. task --list shows everything.
API
| Method | Path | Description |
|---|---|---|
| GET | /healthz |
liveness |
| GET | /search |
q, genre, min_year, max_year, min_rating, limit, offset |
| GET | /movies/{id} |
single document |
| POST | /movies |
JSON array of movies, validated then indexed |
| DELETE | /movies/{id} |
remove a document |
curl 'localhost:8080/search?q=matrx' # typo tolerance
curl 'localhost:8080/search?q=spid' # prefix search
curl 'localhost:8080/search?q=dream' # searches overviews
curl 'localhost:8080/search?q=&genre=Sci-Fi&min_rating=8' # filter + facets
curl 'localhost:8080/search?q=&limit=5' # browse, ranked by rating
Response:
{
"hits": [
{"id":"1","title":"The Matrix","genres":["Sci-Fi","Action"],"year":1999,
"rating":8.7,"match":"The <em>Matrix</em>"}
],
"estimatedTotal": 1,
"processingMs": 0,
"genres": [{"value":"Sci-Fi","count":6}]
}
What the index settings do
internal/infra/meili/index.go EnsureSchema is idempotent and sets:
searchableAttributes: title, overview, genres— ranked in that orderfilterableAttributes: genres, year, rating— enables filters and facetssortableAttributes: year, rating- a custom ranking rule
rating:descas the final tie-breaker
Tests
task test # unit tests, fake index, no Meilisearch needed
task meili:up
task test:integration # real engine: typo tolerance, filters, facets, 404s
Unit tests use an in-memory MovieIndex fake — that is the payoff of the port.
Configuration
| Env | Default |
|---|---|
MEILI_HOST |
http://localhost:7700 |
MEILI_MASTER_KEY |
(empty) |
MEILI_INDEX |
movies |
HTTP_ADDR |
:8080 |
SEED_FILE |
data/movies.json |
Scope
Deliberately skipped: auth on the demo API, pagination beyond limit/offset,
tenant tokens, embedders/vector search, and a UI. Each would live in its own
adapter without touching internal/domain.