Overview
- Synonyms expand recall by matching alternate spellings or equivalent terms.
- Stopwords remove low-information tokens (like “and”, “the”). Overuse can hurt recall.
- Runtime toggles allow per-query control when you need to experiment or override defaults.
Management (admin API)
Use the admin helpers to upsert sets per collection.SearchEngine::Admin::Synonyms.list(collection: "books")SearchEngine::Admin::Synonyms.get(collection: "books", id: "colors")SearchEngine::Admin::Synonyms.delete!(collection: "books", id: "colors")SearchEngine::Admin::Stopwords.list(...),get(...),delete!(...)
collectionandidmust be non-empty strings;idmust match/\A[\w\-:\.]+\z/.termsare stripped, downcased, de-duplicated; empty inputs are rejected.
CLI import/export
Rake tasks provide stable JSON import/export with dry-run support.rails 'search_engine:synonyms:export[collection,path]'rails 'search_engine:synonyms:import[collection,path]'rails 'search_engine:stopwords:export[collection,path]'rails 'search_engine:stopwords:import[collection,path]'
DRY_RUN=1to preview (no writes).HALT_ON_ERROR=1to stop on first failure.FORMAT=jsonto output a machine-readable summary.
Runtime toggles (Relation)
Enable or disable per-query, chainably and immutably:use_synonyms(value)anduse_stopwords(value)accepttrue,false, ornil(to clear override).- Booleans are strictly coerced; the last call wins.
- See
#explainto preview effective flags.
Compiler mapping
These flags are compiled into Typesense parameters:use_synonyms→enable_synonyms=true|falseuse_stopwords→remove_stop_words=true|false(inversion of our DSL)
- The engine adds an internal preview
_runtime_flagsfor observability; it is stripped before HTTP. - If server parameter names change, the DSL remains stable and mapping is adapted here.
Troubleshooting
- Empty
terms: ensure at least one non-empty term (duplicates are removed). - Conflicting IDs: delete then re-upsert the desired set.
- Flag seems ignored: verify collection vs alias and confirm the set exists for the target physical collection.
- Invalid JSON during import: expected keys
collection,kind,items[] {id, terms[]}.
Observability
Events emitted:search_engine.admin.synonyms.upsert,search_engine.admin.stopwords.upsertsearch_engine.compile,search_engine.search
Backlinks
- See DX, Relation Guide, Cookbook Queries, Observability, CLI, Testing.