scrypath

CI Hex.pm HexDocs License

Scrypath, the Ecto-native search indexing library, helps Phoenix and Ecto teams add search to existing schemas without hiding the operational work that keeps search in sync.

Scrypath needs a running Meilisearch server; the repository's examples use the getmeili/meilisearch:v1.15 image on http://127.0.0.1:7700. Meilisearch is eventually consistent, so a record can take a moment to show up in search after you save it.

Public website: sztheory.github.io/scrypath

When Scrypath Fits

Scrypath is a good fit when you want:

  • search indexing that feels native to Ecto instead of bolted onto a controller or callback maze
  • one explicit place to choose between inline, manual, and Oban-backed sync
  • repo-backed record loading through the common Scrypath.search/3 path
  • first-class backfill and managed reindex workflows when drift or schema changes happen

When It Does Not

Scrypath is not trying to be:

  • a Postgres full-text abstraction
  • a Phoenix-only library
  • a public multi-backend facade in v1
  • a callback-heavy runtime that hides when search is out of date

If you want hidden model hooks, implicit repo access, or a library that pretends accepted work means immediate search visibility, this is the wrong tool.

Scrypath is Meilisearch-first in v1. Its backend seam is internal, not a promised public abstraction, and v1 does not promise public multi-backend parity.

Installation

Add Scrypath to your dependencies:

def deps do
  [
    {:scrypath, "~> 0.3"}
  ]
end

Scrypath owns its internal transport dependency; configure backend and sync behavior in your app instead of pinning Req in the base install path. Add Oban only when you choose sync_mode: :oban.

Scrypath follows semantic versioning for its public API, and the changelog says what each release changed. The optional operator UI lives in the source checkout and is not part of the Hex package.

Quick Path

Start a Meilisearch server first; these steps assume it answers on http://127.0.0.1:7700. Because Meilisearch is eventually consistent, a new record can take a moment to show up in search. The golden path covers each step in full.

Declare the searchable fields on your Ecto schema. use Scrypath only declares metadata; persistence and sync stay in your context:

defmodule MyApp.Blog.Post do
  use Ecto.Schema

  use Scrypath,
    fields: [:title, :body],
    filterable: [:status],
    sortable: [:inserted_at]

  schema "posts" do
    field :title, :string
    field :body, :string
    field :status, :string
    timestamps()
  end
end

Point Scrypath at Meilisearch in config/runtime.exs:

import Config

config :scrypath, :defaults,
  backend: Scrypath.Meilisearch,
  meilisearch_url: System.get_env("SCRYPATH_MEILISEARCH_URL") || "http://127.0.0.1:7700",
  repo: MyApp.Repo

After a successful repo write, sync the record:

{:ok, post} =
  MyApp.Repo.insert(%MyApp.Blog.Post{title: "Ecto search", body: "Hello", status: "published"})

{:ok, _sync} = Scrypath.sync_record(MyApp.Blog.Post, post, sync_mode: :inline)

Choose :inline for the first-hour path, :oban when durable enqueue and worker throughput matter, or :manual for imports and operator-controlled follow-up. A successful Scrypath.sync_record/3 return means work was accepted or, when inline waiting applies, completed. Neither makes the database and search writes atomic, and accepted work may not yet be visible in search. See sync modes and visibility for the exact return contract, lifecycle, and recovery guidance.

Then search. result.records holds the matching rows, loaded through your repo:

{:ok, result} = Scrypath.search(MyApp.Blog.Post, "ecto", page: [size: 10])
result.records

Next Steps

  • Continue with the golden path for a context module and an IEx check.
  • Support and compatibility covers release-backed guidance and supported versions; main may contain unreleased changes. Scope reopens only for a concrete production bug, reviewed outside-adopter evidence, or a deliberate strategic product decision.
  • The guides overview gives a recommended reading order; the HexDocs sidebar lists every guide, grouped by job.