Module: ElasticsearchRecord::ModelSchema::ClassMethods

Defined in:
lib/elasticsearch_record/model_schema.rb

Instance Method Summary collapse

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+.

Returns:

  • (Boolean)


40
41
42
# File 'lib/elasticsearch_record/model_schema.rb', line 40

def auto_increment?
  @auto_increment ||= !!connection.table_metas(table_name).dig('auto_increment')
end

#max_result_windowInteger

returns the configured +max_result_window+ (default: 10000)

Returns:

  • (Integer)


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.

See Also:

  • ActiveRecord::ModelSchema::ClassMethods#reload_schema_from_cache


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_namesArray<String>

returns an array with columns names, that are searchable (also includes nested fields & properties )

Returns:

  • (Array<String>)


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_namesArray<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.

Returns:

  • (Array<String>)


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_prefixString

overwrite this method to provide an optional +table_name_prefix+ from the connection config.

Returns:

  • (String)


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_suffixString

overwrite this method to provide an optional +table_name_suffix+ from the connection config.

Returns:

  • (String)


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