Class: AzureSearch::IndexField
- Inherits:
-
Object
- Object
- AzureSearch::IndexField
- 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
-
#analyzer(analyzer) ⇒ self
Sets the analyzer name used for search and indexing.
-
#facetable(facetable) ⇒ self
Sets the field to be facetable.
-
#filterable(filterable) ⇒ self
Sets the field to be filterable.
-
#initialize(name, type) ⇒ IndexField
constructor
A new instance of IndexField.
-
#key(key) ⇒ self
Sets the field to be the key (Only Edm.String fields can be keys).
-
#retrievable(retrievable) ⇒ self
Sets the field to be retrievable.
-
#searchable(searchable) ⇒ self
Sets the field to be searchable.
-
#sortable(sortable) ⇒ self
Sets the field to be sortable.
-
#to_hash ⇒ Hash
Converts this IndexField to a Hash.
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.
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.
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.
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).
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.
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.
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.
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_hash ⇒ Hash
Converts this IndexField to a Hash.
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 |