Class: Searchkick::Index
- Inherits:
-
Object
- Object
- Searchkick::Index
- Defined in:
- lib/searchkick/index.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #create(options = {}) ⇒ Object
- #delete ⇒ Object
- #exists? ⇒ Boolean
- #import(records) ⇒ Object
-
#initialize(name) ⇒ Index
constructor
A new instance of Index.
- #klass_document_type(klass) ⇒ Object
- #refresh ⇒ Object
- #remove(record) ⇒ Object
- #retrieve(record) ⇒ Object
- #store(record) ⇒ Object
Constructor Details
#initialize(name) ⇒ Index
Returns a new instance of Index.
5 6 7 |
# File 'lib/searchkick/index.rb', line 5 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/searchkick/index.rb', line 3 def name @name end |
Instance Method Details
#create(options = {}) ⇒ Object
9 10 11 |
# File 'lib/searchkick/index.rb', line 9 def create( = {}) client.indices.create index: name, body: end |
#delete ⇒ Object
13 14 15 |
# File 'lib/searchkick/index.rb', line 13 def delete client.indices.delete index: name end |
#exists? ⇒ Boolean
17 18 19 |
# File 'lib/searchkick/index.rb', line 17 def exists? client.indices.exists index: name end |
#import(records) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/searchkick/index.rb', line 42 def import(records) records.group_by{|r| document_type(r) }.each do |type, batch| client.bulk( index: name, type: type, body: batch.map{|r| data = search_data(r); {index: {_id: search_id(r), data: data}} } ) end end |
#klass_document_type(klass) ⇒ Object
60 61 62 |
# File 'lib/searchkick/index.rb', line 60 def klass_document_type(klass) klass.model_name.to_s.underscore end |
#refresh ⇒ Object
21 22 23 |
# File 'lib/searchkick/index.rb', line 21 def refresh client.indices.refresh index: name end |
#remove(record) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/searchkick/index.rb', line 34 def remove(record) client.delete( index: name, type: document_type(record), id: search_id(record) ) end |
#retrieve(record) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/searchkick/index.rb', line 52 def retrieve(record) client.get( index: name, type: document_type(record), id: record.id )["_source"] end |
#store(record) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/searchkick/index.rb', line 25 def store(record) client.index( index: name, type: document_type(record), id: search_id(record), body: search_data(record) ) end |