Class: AzureSearch::IndexSearchOptions

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

Overview

Represents search options that will be sent along with a search request.

Since:

  • 0.1.0

Constant Summary collapse

SPECIAL_PARAMS =

Since:

  • 0.1.0

%w(count filter orderby select top skip).freeze

Instance Method Summary collapse

Instance Method Details

#facets(fs) ⇒ self

Sets the list of fields to facet by.

Parameters:

  • fs (Array)

    The list of fields.

Returns:

  • (self)

    The current instance.

Since:

  • 0.1.0



63
64
65
66
67
# File 'lib/azure_search/index_search_options.rb', line 63

def facets(fs)
  raise "facts requires an Array of Strings." unless fs.is_a? Array
  @facet = fs
  self
end

#filter(val) ⇒ self

Sets the structured search expression in standard OData syntax.

Parameters:

  • val (String)

    The filter expression.

Returns:

  • (self)

    The current instance.

Since:

  • 0.1.0



23
24
25
26
27
# File 'lib/azure_search/index_search_options.rb', line 23

def filter(val)
  raise "filter requires a String." unless val.is_a? String
  @filter = val
  self
end

#highlight(hl) ⇒ self

Sets the set of comma-separated field names used for hit highlights.

Parameters:

  • hl (String)

    Comma-separated field names.

Returns:

  • (self)

    The current instance.

Since:

  • 0.1.0



73
74
75
76
77
# File 'lib/azure_search/index_search_options.rb', line 73

def highlight(hl)
  raise "highlight requires a String." unless hl.is_a? String
  @highlight = hl
  self
end

#highlight_post_tag(hpt) ⇒ self

Sets the string tag that appends to hit highlights (defaults to </em>).

Parameters:

  • hpt (String)

    The string tag.

Returns:

  • (self)

    The current instance.

Since:

  • 0.1.0



93
94
95
96
97
# File 'lib/azure_search/index_search_options.rb', line 93

def (hpt)
  raise "highlight_post_tag requires an HTML string." unless has_html?(hpt)
  @highlightPostTag = hpt
  self
end

#highlight_pre_tag(hpt) ⇒ self

Sets the string tag that appends to hit highlights (defaults to <em>).

Parameters:

  • hpt (String)

    The string tag.

Returns:

  • (self)

    The current instance.

Since:

  • 0.1.0



83
84
85
86
87
# File 'lib/azure_search/index_search_options.rb', line 83

def highlight_pre_tag(hpt)
  raise "highlight_pre_tag requires an HTML string." unless has_html?(hpt)
  @highlightPreTag = hpt
  self
end

#include_count(val) ⇒ self

Specifies whether to fetch the total count of results.

Parameters:

  • val (TrueClass, FalseClass)

    true or false.

Returns:

  • (self)

    the current instance.

Since:

  • 0.1.0



13
14
15
16
17
# File 'lib/azure_search/index_search_options.rb', line 13

def include_count(val)
  raise "include_count requires a boolean value." unless is_bool?(val)
  @count = val
  self
end

#minimum_coverage(val) ⇒ self

Sets the percentage of the index that must be covered by a search query.

Parameters:

  • val (Float)

    The percentage (must be between 0 and 100).

Returns:

  • (self)

    The current instance.

Since:

  • 0.1.0



153
154
155
156
157
158
# File 'lib/azure_search/index_search_options.rb', line 153

def minimum_coverage(val)
  raise "minimum_coverage requires a Float." unless val.is_a? Float
  raise "minimum_coverage must be between 0 and 100" unless val.between?(0, 100)
  @minimumCoverage = val
  self
end

#order_by(val) ⇒ self

Sets the list of comma-separated expressions to sort the results by.

Parameters:

  • val (String)

    Comma-separated expressions.

Returns:

  • (self)

    The current instance.

Since:

  • 0.1.0



33
34
35
36
37
# File 'lib/azure_search/index_search_options.rb', line 33

def order_by(val)
  raise "order_by requires a String." unless val.is_a? String
  @orderby = val
  self
end

#scoring_parameters(params) ⇒ self

Sets the values for each parameter defined in a scoring function.

Parameters:

  • params (Array)

    The parameters values.

Returns:

  • (self)

    The current instance.

Since:

  • 0.1.0



113
114
115
116
117
# File 'lib/azure_search/index_search_options.rb', line 113

def scoring_parameters(params)
  raise "scoring_parameters requires an Array of Strings." unless params.is_a? Array
  @scoringParameter = params
  self
end

#scoring_profile(sp) ⇒ self

Sets the name of a scoring profile to evaluate match scores for matching documents.

Parameters:

  • sp (String)

    The scoring profile name.

Returns:

  • (self)

    The current instance.

Since:

  • 0.1.0



103
104
105
106
107
# File 'lib/azure_search/index_search_options.rb', line 103

def scoring_profile(sp)
  raise "scoring_profile requires a String." unless sp.is_a? String
  @scoringProfile = sp
  self
end

#search_fields(val) ⇒ self

Sets the list of comma-separated field names to search for the specified text.

Parameters:

  • val (String)

    Comma-separated field names.

Returns:

  • (self)

    The current instance.

Since:

  • 0.1.0



53
54
55
56
57
# File 'lib/azure_search/index_search_options.rb', line 53

def search_fields(val)
  raise "search_fields requires a String." unless val.is_a? String
  @searchFields = val
  self
end

#search_mode(mode) ⇒ self

Specifies whether any or all of the search terms must be matched.

Parameters:

  • mode (String)

    The search mode.

Returns:

  • (self)

    The current instance.

Since:

  • 0.1.0



143
144
145
146
147
# File 'lib/azure_search/index_search_options.rb', line 143

def search_mode(mode)
  raise "invalid search mode." unless ["any", "all"].include? mode
  @searchMode = mode
  self
end

#select(val) ⇒ self

Sets the list of comma-separated fields to retrieve.

Parameters:

  • val (String)

    Comma-separated fields.

Returns:

  • (self)

    The current instance.

Since:

  • 0.1.0



43
44
45
46
47
# File 'lib/azure_search/index_search_options.rb', line 43

def select(val)
  raise "select requires a String." unless val.is_a? String
  @select = val
  self
end

#skip(val) ⇒ self

Sets the number of search results to skip.

Parameters:

  • val (Integer)

    The number to skip (cannot be greater than 100,000).

Returns:

  • (self)

    The current instance.

Since:

  • 0.1.0



133
134
135
136
137
# File 'lib/azure_search/index_search_options.rb', line 133

def skip(val)
  raise "skip requires an Integer." unless val.is_a? Integer
  @skip = val
  self
end

#to_hashHash

Returns the search options as a Hash.

Returns:

  • (Hash)

    The search options as a Hash.

Since:

  • 0.1.0



163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/azure_search/index_search_options.rb', line 163

def to_hash
  hash = {}
  instance_variables.each {|var|
    varname = var.to_s.delete("@")
    if SPECIAL_PARAMS.include? varname
      hash["$"+varname] = instance_variable_get(var)
    else
      hash[varname] = instance_variable_get(var)
    end
  }
  hash
end

#top(val) ⇒ self

Sets the number of search results to retrieve (defaults to 50).

Parameters:

  • val (Integer)

    The number of search results.

Returns:

  • (self)

    The current instance.

Since:

  • 0.1.0



123
124
125
126
127
# File 'lib/azure_search/index_search_options.rb', line 123

def top(val)
  raise "top requires an Integer." unless val.is_a? Integer
  @top = val
  self
end