Class: Textus::Infra::Store::EntryIndex
- Defined in:
- lib/textus/infra/store/entry_index.rb
Instance Method Summary collapse
- #record(key:, lane:, format:, schema:, content:) ⇒ Object
- #remove(key:) ⇒ Object
- #search(query: nil, schema: nil, lane: nil, prefix: nil) ⇒ Object
Methods inherited from Base
Constructor Details
This class inherits a constructor from Textus::Infra::Store::Base
Instance Method Details
#record(key:, lane:, format:, schema:, content:) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/textus/infra/store/entry_index.rb', line 5 def record(key:, lane:, format:, schema:, content:) table(:entries).insert_conflict(:replace).insert( key:, lane:, format:, schema:, content:, indexed_at: Time.now.utc ) end |
#remove(key:) ⇒ Object
12 13 14 |
# File 'lib/textus/infra/store/entry_index.rb', line 12 def remove(key:) table(:entries).where(key:).delete end |
#search(query: nil, schema: nil, lane: nil, prefix: nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/textus/infra/store/entry_index.rb', line 16 def search(query: nil, schema: nil, lane: nil, prefix: nil) dataset = table(:entries).select(:key, :lane, :format, :schema, :content, :indexed_at) if query match_query = query.to_s.gsub("-", " ") matching_rowids = @db[:entries_fts].where(Sequel.lit("entries_fts MATCH ?", match_query)).select_map(:rowid) dataset = dataset.where(Sequel[:entries][:rowid] => matching_rowids) end dataset = dataset.where(schema:) if schema dataset = dataset.where(lane:) if lane dataset = dataset.where(Sequel.like(:key, "#{prefix}%")) if prefix results(dataset.all) end |