Class: Sunspot::DSL::FieldQuery
- Defined in:
- lib/sunspot/dsl/field_query.rb
Overview
Provides an API for areas of the query DSL that operate on specific fields. This functionality is provided by the query DSL and the dynamic query DSL.
Direct Known Subclasses
Constant Summary
Constants inherited from Scope
Instance Method Summary collapse
-
#facet(*field_names, &block) ⇒ Object
Request facets on the given field names.
-
#order_by(field_name, direction = nil) ⇒ Object
Specify the order that results should be returned in.
-
#order_by_random ⇒ Object
DEPRECATED Use
order_by(:random)
.
Methods inherited from Scope
#all_of, #any_of, #dynamic, #initialize, #with, #without
Constructor Details
This class inherits a constructor from Sunspot::DSL::Scope
Instance Method Details
#facet(*field_names, &block) ⇒ Object
Request facets on the given field names. If the last argument is a hash, the given options will be applied to all specified fields. See Sunspot::Search#facet and Sunspot::Facet for information on what is returned.
Parameters
- field_names…<Symbol>
-
fields for which to return field facets
Options
- :sort<Symbol>
-
Either :count (values matching the most terms first) or :index (lexical)
- :limit<Integer>
-
The maximum number of facet rows to return
- :minimum_count<Integer>
-
The minimum count a facet row must have to be returned
- :zeros<Boolean>
-
Return facet rows for which there are no matches (equivalent to :minimum_count => 0). Default is false.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/sunspot/dsl/field_query.rb', line 49 def facet(*field_names, &block) if block = if field_names.last.is_a?(Hash) field_names.pop else {} end if field_names.length != 1 raise( ArgumentError, "wrong number of arguments (#{field_names.length} for 1)" ) end name = field_names.first DSL::QueryFacet.new(@query.add_query_facet(name, )).instance_eval(&block) else = if field_names.last.is_a?(Hash) field_names.pop end for field_name in field_names @query.add_field_facet(field_name, ) end end end |
#order_by(field_name, direction = nil) ⇒ Object
Specify the order that results should be returned in. This method can be called multiple times; precedence will be in the order given.
Parameters
- field_name<Symbol>
-
the field to use for ordering
- direction<Symbol>
-
:asc or :desc (default :asc)
17 18 19 |
# File 'lib/sunspot/dsl/field_query.rb', line 17 def order_by(field_name, direction = nil) @query.order_by(field_name, direction) end |
#order_by_random ⇒ Object
DEPRECATED Use order_by(:random)
24 25 26 |
# File 'lib/sunspot/dsl/field_query.rb', line 24 def order_by_random @query.order_by(:random) end |