Class: Sunspot::Query::CompositeFulltext
- Inherits:
-
Object
- Object
- Sunspot::Query::CompositeFulltext
- Defined in:
- lib/sunspot/query/composite_fulltext.rb
Direct Known Subclasses
Instance Method Summary collapse
- #add_boost_function(function) ⇒ Object
- #add_boost_query(factor) ⇒ Object
- #add_conjunction ⇒ Object
- #add_disjunction ⇒ Object
- #add_fulltext(keywords) ⇒ Object
- #add_join(keywords, target, from, to) ⇒ Object
- #add_location(field, lat, lng, options) ⇒ Object
- #add_multiplicative_boost_function(function) ⇒ Object
-
#initialize ⇒ CompositeFulltext
constructor
A new instance of CompositeFulltext.
- #to_params ⇒ Object
- #to_subquery ⇒ Object
Constructor Details
#initialize ⇒ CompositeFulltext
Returns a new instance of CompositeFulltext.
4 5 6 7 |
# File 'lib/sunspot/query/composite_fulltext.rb', line 4 def initialize @components = [] @dismax = nil end |
Instance Method Details
#add_boost_function(function) ⇒ Object
20 21 22 23 24 |
# File 'lib/sunspot/query/composite_fulltext.rb', line 20 def add_boost_function(function) @dismax ||= Dismax.new("*:*") @components << @dismax unless @components.include?(@dismax) @dismax.add_additive_boost_function(function) end |
#add_boost_query(factor) ⇒ Object
14 15 16 17 18 |
# File 'lib/sunspot/query/composite_fulltext.rb', line 14 def add_boost_query(factor) @dismax ||= Dismax.new("*:*") @components << @dismax unless @components.include?(@dismax) @dismax.add_boost_query(factor) end |
#add_conjunction ⇒ Object
47 48 49 50 |
# File 'lib/sunspot/query/composite_fulltext.rb', line 47 def add_conjunction @components << conjunction = Conjunction.new conjunction end |
#add_disjunction ⇒ Object
42 43 44 45 |
# File 'lib/sunspot/query/composite_fulltext.rb', line 42 def add_disjunction @components << disjunction = Disjunction.new disjunction end |
#add_fulltext(keywords) ⇒ Object
9 10 11 12 |
# File 'lib/sunspot/query/composite_fulltext.rb', line 9 def add_fulltext(keywords) @components << @dismax = Dismax.new(keywords) @dismax end |
#add_join(keywords, target, from, to) ⇒ Object
32 33 34 35 |
# File 'lib/sunspot/query/composite_fulltext.rb', line 32 def add_join(keywords, target, from, to) @components << join = Join.new(keywords, target, from, to) join end |
#add_location(field, lat, lng, options) ⇒ Object
37 38 39 40 |
# File 'lib/sunspot/query/composite_fulltext.rb', line 37 def add_location(field, lat, lng, ) @components << location = Geo.new(field, lat, lng, ) location end |
#add_multiplicative_boost_function(function) ⇒ Object
26 27 28 29 30 |
# File 'lib/sunspot/query/composite_fulltext.rb', line 26 def add_multiplicative_boost_function(function) @dismax ||= Dismax.new("*:*") @components << @dismax unless @components.include?(@dismax) @dismax.add_multiplicative_boost_function(function) end |
#to_params ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/sunspot/query/composite_fulltext.rb', line 52 def to_params if @components.length == 0 {} elsif @components.length > 1 or @components.find { |c| c.is_a?(Join) } to_subquery.merge(:fl => '* score') else @components.first.to_params.merge(:fl => '* score') end end |
#to_subquery ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/sunspot/query/composite_fulltext.rb', line 62 def to_subquery return {} unless @components.any? params = @components.map(&:to_subquery).inject({:q => []}) do |res, subquery| res[:q] << subquery.delete(:q) if subquery[:q] res.merge(subquery) end params[:q] = params[:q].size > 1 ? "(#{params[:q].join(" #{connector} ")})" : params[:q].join params end |