Class: Queries::MatchQueryBuilder

Inherits:
QueryBuilder show all
Defined in:
lib/queries/match_query_builder.rb

Constant Summary collapse

NAME =

@params: analyzer, auto_generate_synonyms_phrase_query, cutoff_frequency, field_name, fuzziness, fuzzy_transposition,

      lenient, max_expansions, minimum_should_match, operator, prefix_length, value, zero_terms_query
analyzer: analyzer to be used for this query
auto_generate_synonyms_phrase_query: The match query supports multi-terms synonym expansion with the synonym_graph token filter.
                                     When this filter is used, the parser creates a phrase query for each multi-terms synonyms.
                                     For example, the following synonym: "ny, new york" would produce:
                                     (ny OR ("new york"))
cutoff_frequency: cutoff value in [0..1] (or absolute number >=1) representing the maximum threshold of a terms document frequency 
                  to be considered a low frequency term.
field_name: name of the field to be queried
fuzziness: fuzziness used when evaluated to a fuzzy query type
fuzzy_transposition: fuzzy transpositions (ab → ba) are allowed by default but can be disabled by setting fuzzy_transpositions to false
max_expansions: max_expansions limit the number of matching docs that will be returned
minimum_should_match: minimum number of cases to match in case of or query
value: value to be matched in that field in the documents
zero_terms_query: If the analyzer used removes all tokens in a query like a stop filter does, the default behavior is to match no documents at all.
                  In order to change that the zero_terms_query option can be used, which accepts none (default) and all which corresponds to a match_all query.
fuzzy_prefix_length: prefix length provides the number of characters from beginning that have to be exactly matched
"match"

Instance Method Summary collapse

Methods inherited from QueryBuilder

#boost

Methods included from AttributesReader

#attributes

Methods included from AbstractQueryBuilder

#do_equals?, #name

Constructor Details

#initialize(field_name:, value: nil) ⇒ MatchQueryBuilder

Returns a new instance of MatchQueryBuilder.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/queries/match_query_builder.rb', line 28

def initialize field_name: , value: nil
  @field_name = field_name
  @value = value
  @zero_terms_query = nil
  @analyzer = nil
  @auto_generate_synonyms_phrase_query = nil
  @cutoff_frequency = nil
  @fuzziness = nil
  @fuzzy_transpositions = nil
  @max_expansions = nil
  @minimum_should_match = nil
  @operator = nil
  @prefix_length = nil
  @zero_terms_query = nil
end

Instance Method Details

#analyzer(value) ⇒ Object

sets analyzer



82
83
84
85
# File 'lib/queries/match_query_builder.rb', line 82

def analyzer value
  @analyzer = value
  return self
end

#analyzer_exprObject

SEARCH ANALYZER ########## return analyzer



78
79
80
# File 'lib/queries/match_query_builder.rb', line 78

def analyzer_expr
  return @analyzer
end

#auto_generate_synonyms_phrase_query(value) ⇒ Object

sets auto_generate_synonyms_phrase_query



94
95
96
97
# File 'lib/queries/match_query_builder.rb', line 94

def auto_generate_synonyms_phrase_query value
  @auto_generate_synonyms_phrase_query = value
  return self
end

#auto_generate_synonyms_phrase_query_exprObject

AUTO GENERATE SYNONYMS PHRASE QUERY ########## returns auto_generate_synonyms_phrase_query



90
91
92
# File 'lib/queries/match_query_builder.rb', line 90

def auto_generate_synonyms_phrase_query_expr
  return @auto_generate_synonyms_phrase_query
end

#cutoff_frequency(value) ⇒ Object

sets cutoff_frequency



106
107
108
109
# File 'lib/queries/match_query_builder.rb', line 106

def cutoff_frequency value
  @cutoff_frequency = value
  return self
end

#cutoff_frequency_exprObject

CUTOFF FREQUENCY ########## returns cutoff_frequency



102
103
104
# File 'lib/queries/match_query_builder.rb', line 102

def cutoff_frequency_expr
  return @cutoff_frequency
end

#field_name_exprObject

FIELD NAME ########## returns field_name



66
67
68
# File 'lib/queries/match_query_builder.rb', line 66

def field_name_expr
  return @field_name
end

#fuzziness(fuzziness) ⇒ Object

sets fuzziness



118
119
120
121
# File 'lib/queries/match_query_builder.rb', line 118

def fuzziness fuzziness
  @fuzziness = fuzziness.fuzziness
  return self
end

#fuzziness_exprObject

FUZZINESS VALUE ########## returns fuzziness



114
115
116
# File 'lib/queries/match_query_builder.rb', line 114

def fuzziness_expr
  return @fuzziness
end

#fuzzy_prefix_length(value) ⇒ Object

sets prefix_length



129
130
131
132
# File 'lib/queries/match_query_builder.rb', line 129

def fuzzy_prefix_length value
  @prefix_length = value
  return self
end

#fuzzy_prefix_length_exprObject

PREFIX LENGTH ######## returns prefix_length



125
126
127
# File 'lib/queries/match_query_builder.rb', line 125

def fuzzy_prefix_length_expr
  return @prefix_length
end

#fuzzy_transpositions(value) ⇒ Object

sets fuzzy_transpositions



151
152
153
154
# File 'lib/queries/match_query_builder.rb', line 151

def fuzzy_transpositions value
  @fuzzy_transpositions = value
  return self
end

#fuzzy_transpositions_exprObject

FUZZY TRANSPOSITIONS ########## returns fuzzy_transpositions



147
148
149
# File 'lib/queries/match_query_builder.rb', line 147

def fuzzy_transpositions_expr
  return @fuzzy_transpositions
end

#max_expansions(value) ⇒ Object

sets max_expansions



140
141
142
143
# File 'lib/queries/match_query_builder.rb', line 140

def max_expansions value
  @max_expansions = value
  return self    
end

#max_expansions_exprObject

MAX EXPANSIONS ########## returns max_expansions



136
137
138
# File 'lib/queries/match_query_builder.rb', line 136

def max_expansions_expr
  return @max_expansions
end

#minimum_should_match(value) ⇒ Object

sets minimum_should_match



162
163
164
165
# File 'lib/queries/match_query_builder.rb', line 162

def minimum_should_match value
  @minimum_should_match = value
  return self
end

#minimum_should_match_exprObject

MINIMUM SHOULD ########## returns minimum_should_match



158
159
160
# File 'lib/queries/match_query_builder.rb', line 158

def minimum_should_match_expr
  return @minimum_should_match
end

#queryObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/queries/match_query_builder.rb', line 44

def query
  query = {}
  match_query = {}
  field_options = self.common_query
  field_options[:query] = @value
  field_options[:operator] = @operator if @operator.present?
  field_options[:analyzer] = @analyzer if @analyzer.present?
  field_options[:auto_generate_synonyms_phrase_query] = @auto_generate_synonyms_phrase_query if @auto_generate_synonyms_phrase_query.present?
  field_options[:cutoff_frequency] = @cutoff_frequency if @cutoff_frequency.present?
  field_options[:fuzzy_prefix_length] = @fuzzy_prefix_length if @fuzzy_prefix_length.present?
  field_options[:max_expansions] = @max_expansions if @max_expansions.present?
  field_options[:fuzzy_transpositions] = @fuzzy_transpositions if @fuzzy_transpositions.present?
  field_options[:minimum_should_match] = @minimum_should_match if @minimum_should_match.present?
  field_options[:zero_terms_query] = @zero_terms_query if @zero_terms_query.present?
  field_options[:fuzziness] = @fuzziness if @fuzziness.present?
  match_query[@field_name.to_s.intern] = field_options
  query[name.intern] = match_query
  return query
end

#value_exprObject

FIELD VALUE ########## returns value



72
73
74
# File 'lib/queries/match_query_builder.rb', line 72

def value_expr
  return @value
end

#zero_terms_query(zero_terms_query) ⇒ Object

sets zero_terms_query



173
174
175
176
# File 'lib/queries/match_query_builder.rb', line 173

def zero_terms_query zero_terms_query
  @zero_terms_query = zero_terms_query.zero_term
  return self
end

#zero_terms_query_exprObject

ZERO TERMS ########## returns zero_terms_query



169
170
171
# File 'lib/queries/match_query_builder.rb', line 169

def zero_terms_query_expr
  return @zero_terms_query
end