Module: ElasticsearchRecord::ModelSchema::ClassMethods
- Defined in:
- lib/elasticsearch_record/model_schema.rb
Instance Method Summary collapse
-
#auto_increment? ⇒ Boolean
returns true, if the table should behave as +auto_increment+ by creating new records.
-
#max_result_window ⇒ Integer
returns the configured +max_result_window+ (default: 10000).
-
#reload_schema_from_cache(recursive = true) ⇒ Object
clears schema-related instance variables.
-
#searchable_column_names ⇒ Array<String>
returns an array with columns names, that are searchable (also includes nested fields & properties ).
-
#source_column_names ⇒ Array<String>
returns an array with columns names, that are not virtual (and not a base structure).
-
#table_name_prefix ⇒ String
overwrite this method to provide an optional +table_name_prefix+ from the connection config.
-
#table_name_suffix ⇒ String
overwrite this method to provide an optional +table_name_suffix+ from the connection config.
-
#undecorated_table_name(model_name) ⇒ Object
Guesses the table name, but does not decorate it with prefix and suffix information.
Instance Method Details
#auto_increment? ⇒ Boolean
returns true, if the table should behave as +auto_increment+ by creating new records. resolves the auto_increment status from the tables +_meta+.
40 41 42 |
# File 'lib/elasticsearch_record/model_schema.rb', line 40 def auto_increment? @auto_increment ||= !!connection.(table_name).dig('auto_increment') end |
#max_result_window ⇒ Integer
returns the configured +max_result_window+ (default: 10000)
33 34 35 |
# File 'lib/elasticsearch_record/model_schema.rb', line 33 def max_result_window @max_result_window ||= connection.max_result_window(table_name) end |
#reload_schema_from_cache(recursive = true) ⇒ Object
clears schema-related instance variables.
61 62 63 64 65 66 67 |
# File 'lib/elasticsearch_record/model_schema.rb', line 61 def reload_schema_from_cache(recursive = true) # we also need to clear our custom-defined variables @source_column_names = nil @searchable_column_names = nil super end |
#searchable_column_names ⇒ Array<String>
returns an array with columns names, that are searchable (also includes nested fields & properties )
53 54 55 56 57 |
# File 'lib/elasticsearch_record/model_schema.rb', line 53 def searchable_column_names @searchable_column_names ||= columns.select(&:enabled?).reduce([]) { |m, column| m + [column.name] + column.field_names + column.property_names }.uniq end |
#source_column_names ⇒ Array<String>
returns an array with columns names, that are not virtual (and not a base structure). so this is a array of real document (+_source+) attributes of the index.
47 48 49 |
# File 'lib/elasticsearch_record/model_schema.rb', line 47 def source_column_names @source_column_names ||= columns.reject(&:virtual?).map(&:name) - ActiveRecord::ConnectionAdapters::ElasticsearchAdapter.base_structure_keys end |
#table_name_prefix ⇒ String
overwrite this method to provide an optional +table_name_prefix+ from the connection config.
15 16 17 |
# File 'lib/elasticsearch_record/model_schema.rb', line 15 def table_name_prefix super.presence || connection.table_name_prefix end |
#table_name_suffix ⇒ String
overwrite this method to provide an optional +table_name_suffix+ from the connection config.
21 22 23 |
# File 'lib/elasticsearch_record/model_schema.rb', line 21 def table_name_suffix super.presence || connection.table_name_suffix end |
#undecorated_table_name(model_name) ⇒ Object
Guesses the table name, but does not decorate it with prefix and suffix information.
26 27 28 29 |
# File 'lib/elasticsearch_record/model_schema.rb', line 26 def undecorated_table_name(model_name) # check the 'index_base_name' first, so +table_name_prefix+ & +table_name_suffix+ can still be used index_base_name || super(model_name) end |