-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Problem
FTS5 has native synonym support, but there's currently no way to configure synonyms through the gem. Apps that need synonym expansion must implement it outside the gem.
Use Case
In a food database, users search for "chicken broth" but USDA data uses "stock":
- "broth" should match "stock"
- "unsalted" should match "without salt"
Currently this requires either:
- Preprocessing queries before calling
search() - Adding synonyms to the AI/LLM prompt that generates queries
Proposed API
class Food < ApplicationRecord
include ActiveRecord::Searchable
searchable do
field :description, weight: 2.0
field :category
# Option 1: Simple hash mapping
synonyms "broth" => "stock", "unsalted" => "without salt"
# Option 2: Bidirectional synonyms
synonyms "broth" <=> "stock" # matches in either direction
end
endImplementation Notes
SQLite FTS5 supports synonyms via:
- Query-time expansion - Expand "broth" to "broth OR stock" before search
- Custom tokenizer - More complex but handles index-time synonyms
Query-time expansion is simpler and probably sufficient for most use cases.
References
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels