Class: AzureSearch::IndexField

Inherits:
Object
  • Object
show all
Defined in:
lib/azure_search/index_field.rb

Overview

Represents an Index field definition.

Constant Summary collapse

VALID_EDM_TYPES =

Valid EDM (Entity Data Model) data types.

[
  "Edm.String",
  "Collection(Edm.String)",
  "Edm.Boolean",
  "Edm.Int32",
  "Edm.Int64",
  "Edm.Double",
  "Edm.DateTimeOffset",
  "Edm.GeographyPoint"
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(name, type) ⇒ IndexField

Returns a new instance of IndexField.



17
18
19
20
21
22
# File 'lib/azure_search/index_field.rb', line 17

def initialize(name, type)
  raise "Field name is required." unless !name.empty?
  @name = name
  raise "Invalid field type." unless VALID_EDM_TYPES.include? type
  @type = type
end

Instance Method Details

#analyzer(analyzer) ⇒ self

Sets the analyzer name used for search and indexing.

Parameters:

  • analyzer (String)

    The analyzer name.

Returns:

  • (self)

    The current instance.



28
29
30
31
# File 'lib/azure_search/index_field.rb', line 28

def analyzer(analyzer)
  @analyzer = analyzer
  self
end

#facetable(facetable) ⇒ self

Sets the field to be facetable.

Parameters:

  • facetable (TrueClass, FalseClass)

    true or false.

Returns:

  • (self)

    The current instance.



77
78
79
80
81
# File 'lib/azure_search/index_field.rb', line 77

def facetable(facetable)
  raise "facetable must be a boolean." unless is_bool? facetable
  @facetable = facetable
  self
end

#filterable(filterable) ⇒ self

Sets the field to be filterable.

Parameters:

  • filterable (TrueClass, FalseClass)

    true or false.

Returns:

  • (self)

    The current instance.



47
48
49
50
51
# File 'lib/azure_search/index_field.rb', line 47

def filterable(filterable)
  raise "filterable must be a boolean." unless is_bool? filterable
  @filterable = filterable
  self
end

#key(key) ⇒ self

Sets the field to be the key (Only Edm.String fields can be keys).

Parameters:

  • key (TrueClass, FalseClass)

    true or false.

Returns:

  • (self)

    The current instance.



87
88
89
90
91
92
# File 'lib/azure_search/index_field.rb', line 87

def key(key)
  raise "key must be a boolean." unless is_bool? key
  raise "Only Edm.String fields can be keys." unless @type == "Edm.String"
  @key = key
  self
end

#retrievable(retrievable) ⇒ self

Sets the field to be retrievable.

Parameters:

  • retrievable (TrueClass, FalseClass)

    true or false.

Returns:

  • (self)

    The current instance.



57
58
59
60
61
# File 'lib/azure_search/index_field.rb', line 57

def retrievable(retrievable)
  raise "retrievable must be a boolean." unless is_bool? retrievable
  @retrievable = retrievable
  self
end

#searchable(searchable) ⇒ self

Sets the field to be searchable.

Parameters:

  • searchable (TrueClass, FalseClass)

    true or false.

Returns:

  • (self)

    The current instance.



37
38
39
40
41
# File 'lib/azure_search/index_field.rb', line 37

def searchable(searchable)
  raise "searchable must be a boolean." unless is_bool? searchable
  @searchable = searchable
  self
end

#sortable(sortable) ⇒ self

Sets the field to be sortable.

Parameters:

  • sortable (TrueClass, FalseClass)

    true or false.

Returns:

  • (self)

    The current instance.



67
68
69
70
71
# File 'lib/azure_search/index_field.rb', line 67

def sortable(sortable)
  raise "sortable must be a boolean." unless is_bool? sortable
  @sortable = sortable
  self
end

#to_hashHash

Converts this IndexField to a Hash.

Returns:

  • (Hash)

    Hash representation of IndexField.



97
98
99
100
101
# File 'lib/azure_search/index_field.rb', line 97

def to_hash
  hash = {}
  instance_variables.each {|var| hash[var.to_s.delete("@")] = instance_variable_get(var) }
  hash
end