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



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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/algolia/models/search/base_index_settings.rb', line 120

def initialize(attributes = {})
  if (!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({}) { |(k, v), h|
    if (!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
  }

  if attributes.key?(:attributes_for_faceting)
    if (value = attributes[:attributes_for_faceting]).is_a?(Array)
      self.attributes_for_faceting = value
    end
  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

Whether arrays with exclusively non-negative integers should be compressed for better performance. If true, the compressed arrays may be reordered.



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

def allow_compression_of_integer_array
  @allow_compression_of_integer_array
end

#attribute_for_distinctObject

Attribute that should be used to establish groups of results. Attribute names are case-sensitive. All records with the same value for this attribute are considered a group. You can combine ‘attributeForDistinct` with the `distinct` search parameter to control how many items per group are included in the search results. If you want to use the same attribute also for faceting, use the `afterDistinct` modifier of the `attributesForFaceting` setting. This applies faceting after deduplication, which will result in accurate facet counts.



58
59
60
# File 'lib/algolia/models/search/base_index_settings.rb', line 58

def attribute_for_distinct
  @attribute_for_distinct
end

#attributes_for_facetingObject

Attributes used for [faceting](www.algolia.com/doc/guides/managing-results/refine-results/faceting/). Facets are attributes that let you categorize search results. They can be used for filtering search results. By default, no attribute is used for faceting. Attribute names are case-sensitive. Modifiers - ‘filterOnly("ATTRIBUTE")`. Allows using this attribute as a filter, but doesn’t evalue the facet values. - ‘searchable("ATTRIBUTE")`. Allows searching for facet values. - `afterDistinct("ATTRIBUTE")`. Evaluates the facet count after deduplication with `distinct`. This ensures accurate facet counts. You can apply this modifier to searchable facets: `afterDistinct(searchable(ATTRIBUTE))`.



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

def attributes_for_faceting
  @attributes_for_faceting
end

#attributes_to_transliterateObject

Attributes, for which you want to support [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). Transliteration supports searching in any of the Japanese writing systems. To support transliteration, you must set the indexing language to Japanese. Attribute names are case-sensitive.



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

def attributes_to_transliterate
  @attributes_to_transliterate
end

#camel_case_attributesObject

Attributes for which to split [camel case](wikipedia.org/wiki/Camel_case) words. Attribute names are case-sensitive.



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

def camel_case_attributes
  @camel_case_attributes
end

#custom_normalizationObject

Characters and their normalized replacements. This overrides Algolia’s default [normalization](www.algolia.com/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/normalization/).



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

def custom_normalization
  @custom_normalization
end

#decompounded_attributesObject

Searchable attributes to which Algolia should apply [word segmentation](www.algolia.com/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/how-to/customize-segmentation/) (decompounding). Attribute names are case-sensitive. Compound words are formed by combining two or more individual words, and are particularly prevalent in Germanic languages—for example, "firefighter". With decompounding, the individual components are indexed separately. You can specify different lists for different languages. Decompounding is supported for these languages: Dutch (‘nl`), German (`de`), Finnish (`fi`), Danish (`da`), Swedish (`sv`), and Norwegian (`no`).



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

def decompounded_attributes
  @decompounded_attributes
end

#disable_prefix_on_attributesObject

Searchable attributes for which you want to turn off [prefix matching](www.algolia.com/doc/guides/managing-results/optimize-search-results/override-search-engine-defaults/#adjusting-prefix-search). Attribute names are case-sensitive.



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

def disable_prefix_on_attributes
  @disable_prefix_on_attributes
end

#disable_typo_tolerance_on_wordsObject



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

def disable_typo_tolerance_on_words
  @disable_typo_tolerance_on_words
end

#index_languagesObject

Languages for language-specific processing steps, such as word detection and dictionary settings. **You should always specify an indexing language.** If you don’t specify an indexing language, the search engine uses all [supported languages](www.algolia.com/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/supported-languages/), or the languages you specified with the ‘ignorePlurals` or `removeStopWords` parameters. This can lead to unexpected search results. For more information, see [Language-specific configuration](www.algolia.com/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/language-specific-configurations/).



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

def index_languages
  @index_languages
end

#numeric_attributes_for_filteringObject

Numeric attributes that can be used as [numerical filters](www.algolia.com/doc/guides/managing-results/rules/detecting-intent/how-to/applying-a-custom-filter-for-a-specific-query/#numerical-filters). Attribute names are case-sensitive. By default, all numeric attributes are available as numerical filters. For faster indexing, reduce the number of numeric attributes. If you want to turn off filtering for all numeric attributes, specifiy an attribute that doesn’t exist in your index, such as ‘NO_NUMERIC_FILTERING`. Modifier - `equalOnly("ATTRIBUTE")`. Support only filtering based on equality comparisons `=` and `!=`.



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

def numeric_attributes_for_filtering
  @numeric_attributes_for_filtering
end

#pagination_limited_toObject

Maximum number of search results that can be obtained through pagination. Higher pagination limits might slow down your search. For pagination limits above 1,000, the sorting of results beyond the 1,000th hit can’t be guaranteed.



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

def pagination_limited_to
  @pagination_limited_to
end

#replicasObject

Creates [replica indices](www.algolia.com/doc/guides/managing-results/refine-results/sorting/in-depth/replicas/). Replicas are copies of a primary index with the same records but different settings, synonyms, or rules. If you want to offer a different ranking or sorting of your search results, you’ll use replica indices. All index operations on a primary index are automatically forwarded to its replicas. To add a replica index, you must provide the complete set of replicas to this parameter. If you omit a replica from this list, the replica turns into a regular, standalone index that will no longer by synced with the primary index. Modifier - ‘virtual("REPLICA")`. Create a virtual replica, Virtual replicas don’t increase the number of records and are optimized for [Relevant sorting](www.algolia.com/doc/guides/managing-results/refine-results/sorting/in-depth/relevant-sort/).



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

def replicas
  @replicas
end

#searchable_attributesObject

Attributes used for searching. Attribute names are case-sensitive. By default, all attributes are searchable and the [Attribute](www.algolia.com/doc/guides/managing-results/relevance-overview/in-depth/ranking-criteria/#attribute) ranking criterion is turned off. With a non-empty list, Algolia only returns results with matches in the selected attributes. In addition, the Attribute ranking criterion is turned on: matches in attributes that are higher in the list of ‘searchableAttributes` rank first. To make matches in two attributes rank equally, include them in a comma-separated string, such as `"title,alternate_title"`. Attributes with the same priority are always unordered. For more information, see [Searchable attributes](www.algolia.com/doc/guides/sending-and-managing-data/prepare-your-data/how-to/setting-searchable-attributes/). Modifier - `unordered("ATTRIBUTE")`. Ignore the position of a match within the attribute. Without modifier, matches at the beginning of an attribute rank higer than matches at the end.



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

def searchable_attributes
  @searchable_attributes
end

#separators_to_indexObject

Controls which separators are indexed. Separators are all non-letter characters except spaces and currency characters, such as $€£¥. By default, separator characters aren’t indexed. With ‘separatorsToIndex`, Algolia treats separator characters as separate words. For example, a search for `C#` would report two matches.



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

def separators_to_index
  @separators_to_index
end

#unretrievable_attributesObject

Attributes that can’t be retrieved at query time. This can be useful if you want to use an attribute for ranking or to [restrict access](www.algolia.com/doc/guides/security/api-keys/how-to/user-restricted-access-to-data/), but don’t want to include it in the search results. Attribute names are case-sensitive.



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

def unretrievable_attributes
  @unretrievable_attributes
end

#user_dataObject

An object with custom data. You can store up to 32kB as custom data.



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

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



330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'lib/algolia/models/search/base_index_settings.rb', line 330

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
    # model
  else
    # 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



84
85
86
# File 'lib/algolia/models/search/base_index_settings.rb', line 84

def self.acceptable_attributes
  attribute_map.values
end

.attribute_mapObject

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



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

def self.attribute_map
  {
    :attributes_for_faceting => :attributesForFaceting,
    :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



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/algolia/models/search/base_index_settings.rb', line 303

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



112
113
114
115
116
# File 'lib/algolia/models/search/base_index_settings.rb', line 112

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

.types_mappingObject

Attribute type mapping.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/algolia/models/search/base_index_settings.rb', line 89

def self.types_mapping
  {
    :attributes_for_faceting => :"Array<String>",
    :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<SupportedLanguage>",
    :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



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/algolia/models/search/base_index_settings.rb', line 248

def ==(other)
  return true if self.equal?(other)
  self.class == other.class &&
    attributes_for_faceting == other.attributes_for_faceting &&
    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



409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'lib/algolia/models/search/base_index_settings.rb', line 409

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


272
273
274
# File 'lib/algolia/models/search/base_index_settings.rb', line 272

def eql?(other)
  self == other
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/algolia/models/search/base_index_settings.rb', line 278

def hash
  [
    attributes_for_faceting,
    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



380
381
382
# File 'lib/algolia/models/search/base_index_settings.rb', line 380

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



390
391
392
393
394
395
396
397
398
399
400
401
402
403
# File 'lib/algolia/models/search/base_index_settings.rb', line 390

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



384
385
386
# File 'lib/algolia/models/search/base_index_settings.rb', line 384

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



374
375
376
# File 'lib/algolia/models/search/base_index_settings.rb', line 374

def to_s
  to_hash.to_s
end