Class: EagleSearch::Index
- Inherits:
-
Object
- Object
- EagleSearch::Index
- Defined in:
- lib/eagle_search/index.rb
Instance Attribute Summary collapse
-
#alias_name ⇒ Object
readonly
Returns the value of attribute alias_name.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
- #has_synonyms? ⇒ Boolean
- #info ⇒ Object
-
#initialize(klass, settings) ⇒ Index
constructor
A new instance of Index.
- #mappings ⇒ Object
- #name ⇒ Object
- #refresh ⇒ Object
- #reindex ⇒ Object
- #type_name ⇒ Object
Constructor Details
#initialize(klass, settings) ⇒ Index
Returns a new instance of Index.
8 9 10 11 |
# File 'lib/eagle_search/index.rb', line 8 def initialize(klass, settings) @klass = klass @settings = settings end |
Instance Attribute Details
#alias_name ⇒ Object (readonly)
Returns the value of attribute alias_name.
5 6 7 |
# File 'lib/eagle_search/index.rb', line 5 def alias_name @alias_name end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
5 6 7 |
# File 'lib/eagle_search/index.rb', line 5 def settings @settings end |
Instance Method Details
#create ⇒ Object
13 14 15 |
# File 'lib/eagle_search/index.rb', line 13 def create EagleSearch.client.indices.create index: name, body: body end |
#delete ⇒ Object
17 18 19 |
# File 'lib/eagle_search/index.rb', line 17 def delete EagleSearch.client.indices.delete index: alias_name end |
#has_synonyms? ⇒ Boolean
81 82 83 |
# File 'lib/eagle_search/index.rb', line 81 def has_synonyms? @settings[:synonyms] end |
#info ⇒ Object
25 26 27 |
# File 'lib/eagle_search/index.rb', line 25 def info EagleSearch.client.indices.get index: alias_name end |
#mappings ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/eagle_search/index.rb', line 63 def mappings if @settings[:mappings] @settings[:mappings] else base_mappings = { type_name => { properties: {} } } columns.each do |column| base_mappings[type_name][:properties][column.name] = EagleSearch::Field.new(self, column).mapping end base_mappings end end |
#name ⇒ Object
29 30 31 |
# File 'lib/eagle_search/index.rb', line 29 def name @name ||= @settings[:index_name] || "#{ alias_name }_#{ DateTime.now.strftime('%Q') }" end |
#refresh ⇒ Object
21 22 23 |
# File 'lib/eagle_search/index.rb', line 21 def refresh EagleSearch.client.indices.refresh index: alias_name end |
#reindex ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/eagle_search/index.rb', line 45 def reindex client = EagleSearch.client begin aliases = client.indices.get_alias name: alias_name client.indices.delete index: aliases.keys.join(",") rescue #do something ensure create bulk = [] @klass.all.each do |record| bulk << { index: { _index: alias_name, _type: type_name, _id: record.id } } bulk << record.index_data end client.bulk body: bulk end end |
#type_name ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/eagle_search/index.rb', line 37 def type_name if @settings[:mappings] @settings[:mappings].keys.first.downcase else @klass.model_name.param_key end end |