Class: Sunspot::Query::Query
- Inherits:
-
Object
- Object
- Sunspot::Query::Query
- Defined in:
- lib/sunspot/query/query.rb
Instance Attribute Summary collapse
-
#fulltext ⇒ Object
Returns the value of attribute fulltext.
-
#parameter_adjustment ⇒ Object
Returns the value of attribute parameter_adjustment.
-
#scope ⇒ Object
Returns the value of attribute scope.
Instance Method Summary collapse
- #add_field_facet(facet) ⇒ Object
- #add_location_restriction(coordinates, radius) ⇒ Object
- #add_query_facet(facet) ⇒ Object
- #add_sort(sort) ⇒ Object
-
#initialize(types) ⇒ Query
constructor
A new instance of Query.
- #page ⇒ Object
- #paginate(page, per_page) ⇒ Object
- #per_page ⇒ Object
- #set_fulltext(keywords) ⇒ Object
- #set_solr_parameter_adjustment(block) ⇒ Object
- #to_params ⇒ Object
Constructor Details
#initialize(types) ⇒ Query
Returns a new instance of Query.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/sunspot/query/query.rb', line 6 def initialize(types) @scope = Scope.new @sort = SortComposite.new @components = [] if types.length == 1 @scope.add_restriction(TypeField.instance, Restriction::EqualTo, types.first) else @scope.add_restriction(TypeField.instance, Restriction::AnyOf, types) end end |
Instance Attribute Details
#fulltext ⇒ Object
Returns the value of attribute fulltext.
4 5 6 |
# File 'lib/sunspot/query/query.rb', line 4 def fulltext @fulltext end |
#parameter_adjustment ⇒ Object
Returns the value of attribute parameter_adjustment.
4 5 6 |
# File 'lib/sunspot/query/query.rb', line 4 def parameter_adjustment @parameter_adjustment end |
#scope ⇒ Object
Returns the value of attribute scope.
4 5 6 |
# File 'lib/sunspot/query/query.rb', line 4 def scope @scope end |
Instance Method Details
#add_field_facet(facet) ⇒ Object
33 34 35 36 |
# File 'lib/sunspot/query/query.rb', line 33 def add_field_facet(facet) @components << facet facet end |
#add_location_restriction(coordinates, radius) ⇒ Object
25 26 27 |
# File 'lib/sunspot/query/query.rb', line 25 def add_location_restriction(coordinates, radius) @local = Local.new(coordinates, radius) end |
#add_query_facet(facet) ⇒ Object
38 39 40 41 |
# File 'lib/sunspot/query/query.rb', line 38 def add_query_facet(facet) @components << facet facet end |
#add_sort(sort) ⇒ Object
29 30 31 |
# File 'lib/sunspot/query/query.rb', line 29 def add_sort(sort) @sort << sort end |
#page ⇒ Object
77 78 79 |
# File 'lib/sunspot/query/query.rb', line 77 def page @pagination.page if @pagination end |
#paginate(page, per_page) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/sunspot/query/query.rb', line 43 def paginate(page, per_page) if @pagination @pagination.page = page @pagination.per_page = per_page else @pagination = Pagination.new(page, per_page) end end |
#per_page ⇒ Object
81 82 83 |
# File 'lib/sunspot/query/query.rb', line 81 def per_page @pagination.per_page if @pagination end |
#set_fulltext(keywords) ⇒ Object
17 18 19 |
# File 'lib/sunspot/query/query.rb', line 17 def set_fulltext(keywords) @fulltext = Dismax.new(keywords) end |
#set_solr_parameter_adjustment(block) ⇒ Object
21 22 23 |
# File 'lib/sunspot/query/query.rb', line 21 def set_solr_parameter_adjustment( block ) @parameter_adjustment = block end |
#to_params ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/sunspot/query/query.rb', line 52 def to_params params = if @local if @fulltext raise( IllegalSearchError, "Can't perform search with both fulltext and geographical components due to LocalSolr limitations" ) end { :q => @scope.to_boolean_phrase } else @scope.to_params end Sunspot::Util.deep_merge!(params, @fulltext.to_params) if @fulltext Sunspot::Util.deep_merge!(params, @sort.to_params) Sunspot::Util.deep_merge!(params, @pagination.to_params) if @pagination Sunspot::Util.deep_merge!(params, @local.to_params) if @local @components.each do |component| Sunspot::Util.deep_merge!(params, component.to_params) end @parameter_adjustment.call(params) if @parameter_adjustment params[:q] ||= '*:*' params end |