Class: Algolia::Search::BaseIndexSettings

Inherits:
Object
  • Object
show all
Defined in:
lib/algolia/models/search/base_index_settings.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ BaseIndexSettings

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/algolia/models/search/base_index_settings.rb', line 115

def initialize(attributes = {})
  unless attributes.is_a?(Hash)
    raise ArgumentError, "The input argument (attributes) must be a hash in `Algolia::BaseIndexSettings` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  attributes = attributes.each_with_object({}) do |(k, v), h|
    unless self.class.attribute_map.key?(k.to_sym)
      raise ArgumentError,
            "`#{k}` is not a valid attribute in `Algolia::BaseIndexSettings`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
    end

    h[k.to_sym] = v
  end

  if attributes.key?(:replicas)
    if (value = attributes[:replicas]).is_a?(Array)
      self.replicas = value
    end
  end

  if attributes.key?(:pagination_limited_to)
    self.pagination_limited_to = attributes[:pagination_limited_to]
  end

  if attributes.key?(:unretrievable_attributes)
    if (value = attributes[:unretrievable_attributes]).is_a?(Array)
      self.unretrievable_attributes = value
    end
  end

  if attributes.key?(:disable_typo_tolerance_on_words)
    if (value = attributes[:disable_typo_tolerance_on_words]).is_a?(Array)
      self.disable_typo_tolerance_on_words = value
    end
  end

  if attributes.key?(:attributes_to_transliterate)
    if (value = attributes[:attributes_to_transliterate]).is_a?(Array)
      self.attributes_to_transliterate = value
    end
  end

  if attributes.key?(:camel_case_attributes)
    if (value = attributes[:camel_case_attributes]).is_a?(Array)
      self.camel_case_attributes = value
    end
  end

  if attributes.key?(:decompounded_attributes)
    self.decompounded_attributes = attributes[:decompounded_attributes]
  end

  if attributes.key?(:index_languages)
    if (value = attributes[:index_languages]).is_a?(Array)
      self.index_languages = value
    end
  end

  if attributes.key?(:disable_prefix_on_attributes)
    if (value = attributes[:disable_prefix_on_attributes]).is_a?(Array)
      self.disable_prefix_on_attributes = value
    end
  end

  if attributes.key?(:allow_compression_of_integer_array)
    self.allow_compression_of_integer_array = attributes[:allow_compression_of_integer_array]
  end

  if attributes.key?(:numeric_attributes_for_filtering)
    if (value = attributes[:numeric_attributes_for_filtering]).is_a?(Array)
      self.numeric_attributes_for_filtering = value
    end
  end

  if attributes.key?(:separators_to_index)
    self.separators_to_index = attributes[:separators_to_index]
  end

  if attributes.key?(:searchable_attributes)
    if (value = attributes[:searchable_attributes]).is_a?(Array)
      self.searchable_attributes = value
    end
  end

  if attributes.key?(:user_data)
    self.user_data = attributes[:user_data]
  end

  if attributes.key?(:custom_normalization)
    if (value = attributes[:custom_normalization]).is_a?(Hash)
      self.custom_normalization = value
    end
  end

  if attributes.key?(:attribute_for_distinct)
    self.attribute_for_distinct = attributes[:attribute_for_distinct]
  end
end

Instance Attribute Details

#allow_compression_of_integer_arrayObject

Incidates whether the engine compresses arrays with exclusively non-negative integers. When enabled, the compressed arrays may be reordered.



37
38
39
# File 'lib/algolia/models/search/base_index_settings.rb', line 37

def allow_compression_of_integer_array
  @allow_compression_of_integer_array
end

#attribute_for_distinctObject

Name of the deduplication attribute to be used with Algolia’s [distinct feature](www.algolia.com/doc/guides/managing-results/refine-results/grouping/#introducing-algolias-distinct-feature).



55
56
57
# File 'lib/algolia/models/search/base_index_settings.rb', line 55

def attribute_for_distinct
  @attribute_for_distinct
end

#attributes_to_transliterateObject

Attributes in your index to which [Japanese transliteration](www.algolia.com/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/language-specific-configurations/#japanese-transliteration-and-type-ahead) applies. This will ensure that words indexed in Katakana or Kanji can also be searched in Hiragana.



22
23
24
# File 'lib/algolia/models/search/base_index_settings.rb', line 22

def attributes_to_transliterate
  @attributes_to_transliterate
end

#camel_case_attributesObject

Attributes on which to split [camel case](wikipedia.org/wiki/Camel_case) words.



25
26
27
# File 'lib/algolia/models/search/base_index_settings.rb', line 25

def camel_case_attributes
  @camel_case_attributes
end

#custom_normalizationObject

A list of characters and their normalized replacements to override Algolia’s default [normalization](www.algolia.com/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/normalization/).



52
53
54
# File 'lib/algolia/models/search/base_index_settings.rb', line 52

def custom_normalization
  @custom_normalization
end

#decompounded_attributesObject



28
29
30
# File 'lib/algolia/models/search/base_index_settings.rb', line 28

def decompounded_attributes
  @decompounded_attributes
end

#disable_prefix_on_attributesObject



34
35
36
# File 'lib/algolia/models/search/base_index_settings.rb', line 34

def disable_prefix_on_attributes
  @disable_prefix_on_attributes
end

#disable_typo_tolerance_on_wordsObject

Words for which you want to turn off [typo tolerance](www.algolia.com/doc/guides/managing-results/optimize-search-results/typo-tolerance/).



19
20
21
# File 'lib/algolia/models/search/base_index_settings.rb', line 19

def disable_typo_tolerance_on_words
  @disable_typo_tolerance_on_words
end

#index_languagesObject



31
32
33
# File 'lib/algolia/models/search/base_index_settings.rb', line 31

def index_languages
  @index_languages
end

#numeric_attributes_for_filteringObject



40
41
42
# File 'lib/algolia/models/search/base_index_settings.rb', line 40

def numeric_attributes_for_filtering
  @numeric_attributes_for_filtering
end

#pagination_limited_toObject

Maximum number of hits accessible through pagination.



13
14
15
# File 'lib/algolia/models/search/base_index_settings.rb', line 13

def pagination_limited_to
  @pagination_limited_to
end

#replicasObject

Creates [replicas](www.algolia.com/doc/guides/managing-results/refine-results/sorting/in-depth/replicas/), which are copies of a primary index with the same records but different settings.



10
11
12
# File 'lib/algolia/models/search/base_index_settings.rb', line 10

def replicas
  @replicas
end

#searchable_attributesObject



46
47
48
# File 'lib/algolia/models/search/base_index_settings.rb', line 46

def searchable_attributes
  @searchable_attributes
end

#separators_to_indexObject

Controls which separators are added to an Algolia index as part of [normalization](www.algolia.com/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/#what-does-normalization-mean). Separators are all non-letter characters except spaces and currency characters, such as $€£¥.



43
44
45
# File 'lib/algolia/models/search/base_index_settings.rb', line 43

def separators_to_index
  @separators_to_index
end

#unretrievable_attributesObject

Attributes that can’t be retrieved at query time.



16
17
18
# File 'lib/algolia/models/search/base_index_settings.rb', line 16

def unretrievable_attributes
  @unretrievable_attributes
end

#user_dataObject

Lets you store custom data in your indices.



49
50
51
# File 'lib/algolia/models/search/base_index_settings.rb', line 49

def user_data
  @user_data
end

Class Method Details

._deserialize(type, value) ⇒ Object

Deserializes the data based on type

Parameters:

  • string

    type Data type

  • string

    value Value to be deserialized

Returns:

  • (Object)

    Deserialized data



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/algolia/models/search/base_index_settings.rb', line 280

def self._deserialize(type, value)
  case type.to_sym
  when :Time
    Time.parse(value)
  when :Date
    Date.parse(value)
  when :String
    value.to_s
  when :Integer
    value.to_i
  when :Float
    value.to_f
  when :Boolean
    if value.to_s =~ /\A(true|t|yes|y|1)\z/i
      true
    else
      false
    end
  when :Object
    # generic object (usually a Hash), return directly
    value
  when /\AArray<(?<inner_type>.+)>\z/
    inner_type = Regexp.last_match[:inner_type]
    value.map { |v| _deserialize(inner_type, v) }
  when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
    k_type = Regexp.last_match[:k_type]
    v_type = Regexp.last_match[:v_type]
    {}.tap do |hash|
      value.each do |k, v|
        hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
      end
    end
  else # model
    # models (e.g. Pet) or oneOf
    klass = Algolia::Search.const_get(type)
    klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
  end
end

.acceptable_attributesObject

Returns all the JSON keys this model knows about



80
81
82
# File 'lib/algolia/models/search/base_index_settings.rb', line 80

def self.acceptable_attributes
  attribute_map.values
end

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/algolia/models/search/base_index_settings.rb', line 58

def self.attribute_map
  {
    :replicas => :replicas,
    :pagination_limited_to => :paginationLimitedTo,
    :unretrievable_attributes => :unretrievableAttributes,
    :disable_typo_tolerance_on_words => :disableTypoToleranceOnWords,
    :attributes_to_transliterate => :attributesToTransliterate,
    :camel_case_attributes => :camelCaseAttributes,
    :decompounded_attributes => :decompoundedAttributes,
    :index_languages => :indexLanguages,
    :disable_prefix_on_attributes => :disablePrefixOnAttributes,
    :allow_compression_of_integer_array => :allowCompressionOfIntegerArray,
    :numeric_attributes_for_filtering => :numericAttributesForFiltering,
    :separators_to_index => :separatorsToIndex,
    :searchable_attributes => :searchableAttributes,
    :user_data => :userData,
    :custom_normalization => :customNormalization,
    :attribute_for_distinct => :attributeForDistinct
  }
end

.build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/algolia/models/search/base_index_settings.rb', line 255

def self.build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)

  attributes = attributes.transform_keys(&:to_sym)
  transformed_hash = {}
  types_mapping.each_pair do |key, type|
    if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
      transformed_hash[key.to_sym] = nil
    elsif type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[attribute_map[key]].is_a?(Array)
        transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| _deserialize(::Regexp.last_match(1), v) }
      end
    elsif !attributes[attribute_map[key]].nil?
      transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
    end
  end
  new(transformed_hash)
end

.openapi_nullableObject

List of attributes with nullable: true



107
108
109
110
111
# File 'lib/algolia/models/search/base_index_settings.rb', line 107

def self.openapi_nullable
  Set.new([
            :user_data
          ])
end

.types_mappingObject

Attribute type mapping.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/algolia/models/search/base_index_settings.rb', line 85

def self.types_mapping
  {
    :replicas => :'Array<String>',
    :pagination_limited_to => :Integer,
    :unretrievable_attributes => :'Array<String>',
    :disable_typo_tolerance_on_words => :'Array<String>',
    :attributes_to_transliterate => :'Array<String>',
    :camel_case_attributes => :'Array<String>',
    :decompounded_attributes => :Object,
    :index_languages => :'Array<String>',
    :disable_prefix_on_attributes => :'Array<String>',
    :allow_compression_of_integer_array => :Boolean,
    :numeric_attributes_for_filtering => :'Array<String>',
    :separators_to_index => :String,
    :searchable_attributes => :'Array<String>',
    :user_data => :Object,
    :custom_normalization => :'Hash<String, Hash<String, String>>',
    :attribute_for_distinct => :String
  }
end

Instance Method Details

#==(other) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/algolia/models/search/base_index_settings.rb', line 217

def ==(other)
  return true if equal?(other)

  self.class == other.class &&
    replicas == other.replicas &&
    pagination_limited_to == other.pagination_limited_to &&
    unretrievable_attributes == other.unretrievable_attributes &&
    disable_typo_tolerance_on_words == other.disable_typo_tolerance_on_words &&
    attributes_to_transliterate == other.attributes_to_transliterate &&
    camel_case_attributes == other.camel_case_attributes &&
    decompounded_attributes == other.decompounded_attributes &&
    index_languages == other.index_languages &&
    disable_prefix_on_attributes == other.disable_prefix_on_attributes &&
    allow_compression_of_integer_array == other.allow_compression_of_integer_array &&
    numeric_attributes_for_filtering == other.numeric_attributes_for_filtering &&
    separators_to_index == other.separators_to_index &&
    searchable_attributes == other.searchable_attributes &&
    user_data == other.user_data &&
    custom_normalization == other.custom_normalization &&
    attribute_for_distinct == other.attribute_for_distinct
end

#_to_hash(value) ⇒ Hash

Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value

Parameters:

  • value (Object)

    Any valid value

Returns:

  • (Hash)

    Returns the value in the form of hash



355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/algolia/models/search/base_index_settings.rb', line 355

def _to_hash(value)
  if value.is_a?(Array)
    value.compact.map { |v| _to_hash(v) }
  elsif value.is_a?(Hash)
    {}.tap do |hash|
      value.each { |k, v| hash[k] = _to_hash(v) }
    end
  elsif value.respond_to? :to_hash
    value.to_hash
  else
    value
  end
end

#eql?(other) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


241
242
243
# File 'lib/algolia/models/search/base_index_settings.rb', line 241

def eql?(other)
  self == other
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



247
248
249
250
# File 'lib/algolia/models/search/base_index_settings.rb', line 247

def hash
  [replicas, pagination_limited_to, unretrievable_attributes, disable_typo_tolerance_on_words, attributes_to_transliterate, camel_case_attributes, decompounded_attributes,
   index_languages, disable_prefix_on_attributes, allow_compression_of_integer_array, numeric_attributes_for_filtering, separators_to_index, searchable_attributes, user_data, custom_normalization, attribute_for_distinct].hash
end

#to_bodyHash

to_body is an alias to to_hash (backward compatibility)

Returns:

  • (Hash)

    Returns the object in the form of hash



327
328
329
# File 'lib/algolia/models/search/base_index_settings.rb', line 327

def to_body
  to_hash
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/algolia/models/search/base_index_settings.rb', line 337

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = send(attr)
    if value.nil?
      is_nullable = self.class.openapi_nullable.include?(attr)
      next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
    end

    hash[param] = _to_hash(value)
  end
  hash
end

#to_json(*_args) ⇒ Object



331
332
333
# File 'lib/algolia/models/search/base_index_settings.rb', line 331

def to_json(*_args)
  to_hash.to_json
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



321
322
323
# File 'lib/algolia/models/search/base_index_settings.rb', line 321

def to_s
  to_hash.to_s
end