Class: Stretchy::Clauses::BoostClause

Inherits:
Base
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/stretchy/clauses/boost_clause.rb

Direct Known Subclasses

BoostMatchClause, BoostWhereClause

Constant Summary

Constants inherited from Base

Stretchy::Clauses::Base::DEFAULT_LIMIT, Stretchy::Clauses::Base::DEFAULT_OFFSET

Instance Attribute Summary

Attributes inherited from Base

#aggregate_builder, #boost_builder, #index_name, #inverse, #match_builder, #type, #where_builder

Instance Method Summary collapse

Methods inherited from Base

#boost, #get_limit, #get_offset, #inverse?, #limit, #offset, #query_results, #should, #to_search

Constructor Details

#initialize(base, options = {}) ⇒ BoostClause

Returns a new instance of BoostClause.



11
12
13
14
# File 'lib/stretchy/clauses/boost_clause.rb', line 11

def initialize(base, options = {})
  super(base)
  @inverse = options.delete(:inverse)
end

Instance Method Details

#all(num) ⇒ Object



42
43
44
45
# File 'lib/stretchy/clauses/boost_clause.rb', line 42

def all(num)
  @boost_builder.overall_boost = num
  self
end

#boost_mode(mode) ⇒ Object



57
58
59
60
# File 'lib/stretchy/clauses/boost_clause.rb', line 57

def boost_mode(mode)
  @boost_builder.boost_mode = mode
  self
end

#match(options = {}) ⇒ Object Also known as: fulltext



16
17
18
# File 'lib/stretchy/clauses/boost_clause.rb', line 16

def match(options = {})
  BoostMatchClause.new(self, options)
end

#max(num) ⇒ Object



47
48
49
50
# File 'lib/stretchy/clauses/boost_clause.rb', line 47

def max(num)
  @boost_builder.max_boost = num
  self
end

#near(options = {}) ⇒ Object Also known as: geo



26
27
28
29
30
31
32
33
34
# File 'lib/stretchy/clauses/boost_clause.rb', line 26

def near(options = {})
  if options[:lat] || options[:latitude]  ||
     options[:lng] || options[:longitude] || options[:lon]

    options[:origin] = Stretchy::Types::GeoPoint.new(options)
  end
  @boost_builder.functions << Stretchy::Boosts::FieldDecayBoost.new(options)
  self
end

#not(options = {}) ⇒ Object



62
63
64
65
# File 'lib/stretchy/clauses/boost_clause.rb', line 62

def not(options = {})
  inst = self.class.new(self, options.merge(inverse: !inverse?))
  inst
end

#random(*args) ⇒ Object



37
38
39
40
# File 'lib/stretchy/clauses/boost_clause.rb', line 37

def random(*args)
  @boost_builder.functions << Stretchy::Boosts::RandomBoost.new(*args)
  self
end

#score_mode(mode) ⇒ Object



52
53
54
55
# File 'lib/stretchy/clauses/boost_clause.rb', line 52

def score_mode(mode)
  @boost_builder.score_mode = mode
  self
end

#where(options = {}) ⇒ Object Also known as: filter



21
22
23
# File 'lib/stretchy/clauses/boost_clause.rb', line 21

def where(options = {})
  BoostWhereClause.new(self, options)
end