Skip to main content

Crate larust_scout

Crate larust_scout 

Source
Expand description

Laravel’s laravel/scout - full-text search, narrowed to its Meilisearch driver: self-hostable (no required paid service, matching this framework’s own posture elsewhere - larust-reverb’s own WebSocket server, larust-db’s embedded redb), with a REST API stable and simple enough to call directly over reqwest rather than needing a dedicated SDK dependency.

No Searchable trait / automatic model-lifecycle indexing. Real Scout re-indexes a model automatically on save/delete via an Eloquent model observer - this framework has already rejected that shape of magic once, deliberately: rust-laravel.md’s own “What should remain deliberately different” section singles out “Magic lazy-loaded relationships by default” as something to reject, and silent lifecycle-hook re-indexing is the same instinct applied to writes instead of reads - a save that also does an unrelated network call the caller never asked for, with no visible line of code at the call site explaining why. index/remove are explicit calls instead, the same shape larust_queue::dispatch/larust_events::dispatch already use for “something happens as a deliberate, visible side effect of this write”, not an invisible one.

Single-driver (Meilisearch only), not Scout’s own pluggable driver split (Algolia, a database/collection driver for local dev and testing). A real database-style LIKE-query fallback is a genuinely different, larger feature - this crate has one job, talking to a real Meilisearch instance, and does it without an abstraction layer only one implementation would ever sit behind.

Re-exported through larust_support::scout (see crates/ larust-support/src/lib.rs) so generated apps depend only on larust-support, never on this crate directly.

§Deliberately out of scope for this version

  • No index configuration (searchable/filterable/sortable attribute settings, typo tolerance, synonyms - Meilisearch’s own PATCH /indexes/{uid}/settings). index relies entirely on Meilisearch’s own sensible defaults (every field searchable); an app with real tuning needs calls reqwest against the settings endpoint directly for now.
  • No filters, sorting, facets, or pagination parameters on search - plain q-only full-text search. A real, separate follow-up once a caller actually needs them, not spec’d speculatively here.
  • No task-completion polling. Meilisearch indexes/deletes asynchronously - index/remove return once Meilisearch has accepted the write (its own task-enqueued response), not once indexing has actually finished. This matches Scout’s own real-world behavior (also eventually consistent, especially when its own queue driver is active) - not a shortcut unique to this crate.

Structs§

SearchResults
One page of search results - Meilisearch’s own default (offset-based, not the alternate page-number mode its own API also supports, see this module’s own “deliberately out of scope” note on pagination parameters). estimated_total_hits is None only for the “index doesn’t exist yet” fallback search itself applies - a real Meilisearch response always includes it.

Functions§

index
Indexes document into index_name - Laravel’s $model->searchable(). document must serialize to a JSON object carrying an "id" field (Meilisearch’s own default primary-key convention, and the same id every #[derive(Model)] struct already has) - this crate adds no separate id parameter or primary-key configuration on top of that. Meilisearch creates index_name automatically on this first write if it doesn’t already exist; no separate “create the index” call is needed.
remove
Removes the document with id id from index_name - Laravel’s $model->unsearchable(). Not an error to remove an id that was never indexed or has already been removed - Meilisearch itself treats that as a normal, successful no-op (it still enqueues a delete task; there is nothing to roll back).
search
Searches index_name for query - Laravel’s Model::search($query) ->get(). An index that has never had a document written to it (see index’s own doc comment - Meilisearch never auto-creates one for a search, only for a write) returns Meilisearch’s own index_not_found error; treated here as an ordinary empty result set, not a caller- visible error, the same “nothing indexed yet looks like zero results, not a failure” tolerance an empty SQL table already gets everywhere else in this codebase.