Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion lib/elasticsearch_dsl_builder/dsl/search/queries/match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,30 @@ def value(value)
self
end

def operator(operator)
raise ArgumentError, 'operator must be a String' unless operator.instance_of?(String)
@operator = operator
self
end

def boost(boost)
raise ArgumentError, 'boost must be a Integer' unless boost.instance_of?(Integer)
@boost = boost
self
end

def fuzziness(fuzziness)
raise ArgumentError, 'fuzziness must be a Integer' unless fuzziness.instance_of?(Integer)
@fuzziness = fuzziness
self
end

def to_hash
@query = { @field => @value }
nested_query = { value: @value }
nested_query.update(operator: @operator) if @operator
nested_query.update(boost: @boost) if @boost
nested_query.update(fuzziness: @fuzziness) if @fuzziness
@query = { @field => nested_query }
super
end
end
Expand Down
56 changes: 56 additions & 0 deletions lib/elasticsearch_dsl_builder/dsl/search/queries/match_phrase.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module ElasticsearchDslBuilder
module DSL
module Search
module Queries
class MatchPhrase < Query
def initialize(field = nil, value = nil)
@type = :match_phrase
field(field)
value(value)
super()
end

def field(field)
field_valid = field.instance_of?(String) || field.instance_of?(Symbol)
raise ArgumentError, 'field must be a String or Symbol' unless field_valid
@field = field.to_sym
self
end

def value(value)
raise ArgumentError, 'value must be a String' unless value.instance_of?(String)
@value = value
self
end

def operator(operator)
raise ArgumentError, 'operator must be a String' unless operator.instance_of?(String)
@operator = operator
self
end

def boost(boost)
raise ArgumentError, 'boost must be a Integer' unless boost.instance_of?(Integer)
@boost = boost
self
end

def fuzziness(fuzziness)
raise ArgumentError, 'fuzziness must be a Integer' unless fuzziness.instance_of?(Integer)
@fuzziness = fuzziness
self
end

def to_hash
nested_query = { value: @value }
nested_query.update(operator: @operator) if @operator
nested_query.update(boost: @boost) if @boost
nested_query.update(fuzziness: @fuzziness) if @fuzziness
@query = { @field => nested_query }
super
end
end
end
end
end
end
17 changes: 16 additions & 1 deletion lib/elasticsearch_dsl_builder/dsl/search/queries/multi_match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,23 @@ def value(value)
self
end

def operator(operator)
raise ArgumentError, 'operator must be a String' unless operator.instance_of?(String)
@operator = operator
self
end

def boost(boost)
raise ArgumentError, 'boost must be a Integer' unless boost.instance_of?(Integer)
@boost = boost
self
end

def to_hash
@query = { fields: @fields, query: @value } if @fields && @value
nested_query = { fields: @fields, query: @value } if @fields && @value
nested_query.update(operator: @operator) if @operator
nested_query.update(boost: @boost) if @boost
@query = nested_query
super
end
end
Expand Down
41 changes: 41 additions & 0 deletions lib/elasticsearch_dsl_builder/dsl/search/queries/prefix.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module ElasticsearchDslBuilder
module DSL
module Search
module Queries
class Prefix < Query
def initialize(field = nil, value = nil)
@type = :prefix
field(field)
value(value)
super()
end

def field(field)
field_valid = field.instance_of?(String) || field.instance_of?(Symbol)
raise ArgumentError, 'field must be a String or Symbol' unless field_valid
@field = field.to_sym
self
end

def value(value)
@value = value
self
end

def boost(boost)
raise ArgumentError, 'boost must be a Integer' unless boost.instance_of?(Intger)
@boost = boost
self
end

def to_hash
nested_query = { value: @value }
nested_query.update(boost: @boost) if @boost
@query = { @field => nested_query }
super
end
end
end
end
end
end
9 changes: 8 additions & 1 deletion lib/elasticsearch_dsl_builder/dsl/search/queries/term.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ def value(value)
self
end

def boost(boost)
@boost = boost
self
end

def to_hash
raise InvalidQuery, 'field and value must be provided for Term Query' unless @field && @value
@query = { @field => @value }
nested_query = { value: @value }
nested_query.update(boost: @boost) if @boost
@query = { @field => nested_query }
super
end
end
Expand Down