Class: S3arch::Searcher
- Inherits:
-
Object
- Object
- S3arch::Searcher
- Defined in:
- lib/s3arch/searcher.rb
Class Attribute Summary collapse
-
.db_cache ⇒ Object
Returns the value of attribute db_cache.
-
.version_cache ⇒ Object
Returns the value of attribute version_cache.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(config: S3arch.configuration, store: nil) ⇒ Searcher
constructor
A new instance of Searcher.
- #search(query:, owner_ids:, filters: {}) ⇒ Object
Constructor Details
#initialize(config: S3arch.configuration, store: nil) ⇒ Searcher
Returns a new instance of Searcher.
19 20 21 22 23 |
# File 'lib/s3arch/searcher.rb', line 19 def initialize(config: S3arch.configuration, store: nil) config.validate! @config = config @store = store || Store.new(config: config) end |
Class Attribute Details
.db_cache ⇒ Object
Returns the value of attribute db_cache.
11 12 13 |
# File 'lib/s3arch/searcher.rb', line 11 def db_cache @db_cache end |
.version_cache ⇒ Object
Returns the value of attribute version_cache.
11 12 13 |
# File 'lib/s3arch/searcher.rb', line 11 def version_cache @version_cache end |
Class Method Details
.reset! ⇒ Object
13 14 15 16 |
# File 'lib/s3arch/searcher.rb', line 13 def reset! @version_cache = {} @db_cache = {} end |
Instance Method Details
#search(query:, owner_ids:, filters: {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/s3arch/searcher.rb', line 25 def search(query:, owner_ids:, filters: {}) return nil if owner_ids.empty? || query.nil? || query.strip.empty? log(:info, 'Search started', query: query, owner_ids: owner_ids, filters: filters) results = [] owner_ids.each do |owner_id| db = ensure_database(owner_id) unless db log(:info, 'No database available', owner_id: owner_id) next end hits = query_fts(db, query, filters: filters) log(:info, 'Owner search complete', owner_id: owner_id, hits: hits.size) results.concat(hits) end log(:info, 'Search complete', total_results: results.size) return nil if results.empty? results.sort_by! { |r| r[:rank] } { record_ids: results.first(@config.max_results).map { |r| r[:record_id] }, search_mode: 'fts5' } end |