Class: Sunspot::Query::FieldQuery
- Defined in:
- lib/sunspot/query/field_query.rb
Overview
This class acts as a base class for query components that encapsulate operations on fields. It is subclassed by the Query::Query class and the Query::DynamicQuery class.
Direct Known Subclasses
Instance Method Summary collapse
-
#add_field_facet(field_name, options = nil) ⇒ Object
Add a field facet.
-
#add_query_facet(name) ⇒ Object
Add a query facet.
-
#order_by(field_name, direction = nil) ⇒ Object
Set result ordering.
Methods inherited from Scope
#add_conjunction, #add_disjunction, #add_negated_restriction, #add_negated_shorthand_restriction, #add_restriction, #add_shorthand_restriction, #dynamic_query, #exclude_instance
Instance Method Details
#add_field_facet(field_name, options = nil) ⇒ Object
Add a field facet. See Sunspot::Facet for more information.
Parameters
- field_name<Symbol>
-
Name of the field on which to get a facet
Returns
- FieldFacet
-
The field facet object
20 21 22 |
# File 'lib/sunspot/query/field_query.rb', line 20 def add_field_facet(field_name, = nil) add_component(FieldFacet.build(build_field(field_name), || {})) end |
#add_query_facet(name) ⇒ Object
Add a query facet.
Parameters
- name<Symbol>
-
The name associated with the query facet. This is not passed to Solr, but allows the user to retrieve the facet result by passing the name to the Search#facet method.
Returns
- QueryFacet
-
The query facet object
38 39 40 41 42 |
# File 'lib/sunspot/query/field_query.rb', line 38 def add_query_facet(name) add_component(facet = QueryFacet.new(name, setup)) query_facets[name.to_sym] = facet facet end |
#order_by(field_name, direction = nil) ⇒ Object
Set result ordering.
Parameters
- field_name<Symbol>
-
Name of the field on which to order
- direction<Symbol>
-
:asc or :desc (default :asc)
52 53 54 |
# File 'lib/sunspot/query/field_query.rb', line 52 def order_by(field_name, direction = nil) add_sort(Sort.new(build_field(field_name), direction)) end |