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 + Compose v2 (for task meili:up) — or any reachable Meilisearch, set MEILI_HOST
  • Task

Quick start

task meili:up      # Compose: Meilisearch v1.24 on :7700
task seed          # create index, apply settings, load data/movies.json
task run           # API on :8080 (go run, fast dev loop)
# in another shell:
task query         # runs scripts/demo-queries.sh

task demo chains up + seed + queries in one go. task --list shows everything.

Everything in containers

task up            # build API image, start engine + API, seed the index
task meili:logs    # tail the engine
task meili:down    # stop (keeps the volume)
task meili:reset   # stop and drop the index volume

compose.yaml keeps the API behind the full profile, so a plain docker compose up -d gives you just the search engine to develop against. Index data lives in the named volume meili-data.

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 order
  • filterableAttributes: genres, year, rating — enables filters and facets
  • sortableAttributes: year, rating
  • a custom ranking rule rating:desc as 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.

S
Description
No description provided
Readme
49 KiB
0 Stars 1 Watchers 0 Forks
Languages
Go 96.3%
Shell 2.6%
Dockerfile 1.1%