Class: Sunspot::Query::QueryFacet
- Inherits:
-
Object
- Object
- Sunspot::Query::QueryFacet
- Defined in:
- lib/sunspot/query/query_facet.rb
Overview
QueryFacets encapsulate requests for Sunspot’s query faceting capability. They are created by the FieldQuery#add_query_facet method.
–
The actual concept of a QueryFacet is somewhat artificial - it provides a grouping for the facet at the Sunspot level, which provides a nicer and more consistent API in Sunspot; Solr does not provide any grouping for query facet rows, instead returning each requested row individually, keyed by the boolean phrase used in the facet query.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
:nodoc:.
-
#name ⇒ Object
readonly
:nodoc:.
-
#options ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#add_row(label) ⇒ Object
Add a QueryFacetRow to this facet.
-
#initialize(name, options, setup = nil) ⇒ QueryFacet
constructor
:nodoc:.
-
#rows ⇒ Object
Get query facet rows (used when constructing results).
-
#to_params ⇒ Object
Express this query facet as Solr parameters.
Constructor Details
#initialize(name, options, setup = nil) ⇒ QueryFacet
:nodoc:
20 21 22 23 |
# File 'lib/sunspot/query/query_facet.rb', line 20 def initialize(name, , setup = nil) #:nodoc: @name, @options, @setup = name, , setup @components = [] end |
Instance Attribute Details
#field ⇒ Object (readonly)
:nodoc:
17 18 19 |
# File 'lib/sunspot/query/query_facet.rb', line 17 def field @field end |
#name ⇒ Object (readonly)
:nodoc:
16 17 18 |
# File 'lib/sunspot/query/query_facet.rb', line 16 def name @name end |
#options ⇒ Object (readonly)
:nodoc:
18 19 20 |
# File 'lib/sunspot/query/query_facet.rb', line 18 def @options end |
Instance Method Details
#add_row(label) ⇒ Object
Add a QueryFacetRow to this facet. The label argument becomes the value of the Sunspot::QueryFacetRow object corresponding to this query facet row.
Parameters
- label<Object>
-
An object that will become the value of the result row. Use whatever type is most intuitive.
Returns
- QueryFacetRow
-
QueryFacetRow object containing scope for this row
40 41 42 43 |
# File 'lib/sunspot/query/query_facet.rb', line 40 def add_row(label) @components << row = QueryFacetRow.new(label, @setup) row end |
#rows ⇒ Object
Get query facet rows (used when constructing results)
Returns
- Array
-
Array of QueryFacetRow objects.
73 74 75 |
# File 'lib/sunspot/query/query_facet.rb', line 73 def rows #:nodoc: @components end |
#to_params ⇒ Object
Express this query facet as Solr parameters
Returns
- Hash
-
Solr params hash
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/sunspot/query/query_facet.rb', line 52 def to_params #:nodoc: components = @components.map { |component| component.to_boolean_phrase } components.compact! if components.empty? {} else components = components.first if components.length == 1 { :facet => 'true', :"facet.query" => components } end end |