Class: RailsPanda::Search::Strategies::Ngram::NgramEntry
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- RailsPanda::Search::Strategies::Ngram::NgramEntry
- Defined in:
- lib/rails_panda_search/strategies/ngram/ngram_entry.rb
Overview
Schema Information
Table name: rails_panda_search_ngram_entries
id :integer not null, primary key ngram :string not null source_type :string not null source_column :string not null source_id :string not null created_at :datetime not null updated_at :datetime not null
Indexes
idx_rails_panda_search_ngram_entries_on_ngram_and_source_type (ngram,source_type)
Class Method Summary collapse
-
.matching_source_ids(ngrams, source_type: nil, columns: nil) ⇒ Array<Hash>
Returns source_id hashes that match ALL given n-grams.
-
.table_name ⇒ Object
Always read from config at call time, so initializers and late config changes are respected.
Class Method Details
.matching_source_ids(ngrams, source_type: nil, columns: nil) ⇒ Array<Hash>
Returns source_id hashes that match ALL given n-grams. Optionally scoped by source_type and/or columns.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rails_panda_search/strategies/ngram/ngram_entry.rb', line 40 def self.matching_source_ids(ngrams, source_type: nil, columns: nil) return [] if ngrams.empty? where(ngram: ngrams) .then do |scope| if source_type scope.for_source_type(source_type) else scope end end .then do |scope| if columns scope.where(source_column: Array(columns).map(&:to_s)) else scope end end .group(:source_type, :source_id) .having("COUNT(DISTINCT ngram) = ?", ngrams.length) .pluck(:source_type, :source_id) .map { |type, id_json| [type, JSON.parse(id_json)] } end |
.table_name ⇒ Object
Always read from config at call time, so initializers and late config changes are respected.
25 26 27 |
# File 'lib/rails_panda_search/strategies/ngram/ngram_entry.rb', line 25 def self.table_name RailsPanda::Search.config.ngram_entries_table_name end |