Class: Tagliani::Search
- Inherits:
-
Object
- Object
- Tagliani::Search
- Defined in:
- lib/tagliani/search.rb,
lib/tagliani/search/index.rb,
lib/tagliani/search/index/object.rb
Defined Under Namespace
Classes: Index
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(body:, where: nil) ⇒ Search
constructor
A new instance of Search.
- #response ⇒ Object
- #serialize(type:) ⇒ Object
Constructor Details
#initialize(body:, where: nil) ⇒ Search
Returns a new instance of Search.
17 18 19 20 21 22 23 24 |
# File 'lib/tagliani/search.rb', line 17 def initialize(body:, where: nil) @index = Tagliani.config.elasticsearch.index @client = self.class.client @where_clause = where @body = body build_where(@where_clause) if @where_clause end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
15 16 17 |
# File 'lib/tagliani/search.rb', line 15 def client @client end |
Class Method Details
Instance Method Details
#response ⇒ Object
26 27 28 |
# File 'lib/tagliani/search.rb', line 26 def response @client.search(index: @index, body: @body) end |
#serialize(type:) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tagliani/search.rb', line 30 def serialize(type:) model_kls = "#{type}_kls" model_id = "#{type}_id" models = {} response['hits']['hits'].each do |entry| entry_source = entry['_source'] class_name = entry_source[model_kls] models[class_name] ||= [] models[class_name] << entry_source[model_id] end models.flat_map do |model, ids| model.constantize.where(id: ids) end end |