Class: ThinkingSphinx::FacetSearch
- Inherits:
-
Object
- Object
- ThinkingSphinx::FacetSearch
- Includes:
- Enumerable
- Defined in:
- lib/thinking_sphinx/facet_search.rb
Defined Under Namespace
Classes: Filter
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#query ⇒ Object
Returns the value of attribute query.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #each(&block) ⇒ Object
- #for(facet_values) ⇒ Object
-
#initialize(query = nil, options = {}) ⇒ FacetSearch
constructor
A new instance of FacetSearch.
- #populate ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(query = nil, options = {}) ⇒ FacetSearch
Returns a new instance of FacetSearch.
7 8 9 10 11 |
# File 'lib/thinking_sphinx/facet_search.rb', line 7 def initialize(query = nil, = {}) query, = nil, query if query.is_a?(Hash) @query, @options = query, @hash = {} end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/thinking_sphinx/facet_search.rb', line 4 def @options end |
#query ⇒ Object
Returns the value of attribute query.
5 6 7 |
# File 'lib/thinking_sphinx/facet_search.rb', line 5 def query @query end |
Instance Method Details
#[](key) ⇒ Object
13 14 15 16 17 |
# File 'lib/thinking_sphinx/facet_search.rb', line 13 def [](key) populate @hash[key] end |
#each(&block) ⇒ Object
19 20 21 22 23 |
# File 'lib/thinking_sphinx/facet_search.rb', line 19 def each(&block) populate @hash.each(&block) end |
#for(facet_values) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/thinking_sphinx/facet_search.rb', line 25 def for(facet_values) filter_facets = facet_values.keys.collect { |key| facets.detect { |facet| facet.name == key.to_s } } ThinkingSphinx::Search.new query, .merge( :indices => index_names_for(*filter_facets) ).merge(Filter.new(facets, facet_values).to_hash) end |
#populate ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/thinking_sphinx/facet_search.rb', line 35 def populate return if @populated batch = ThinkingSphinx::BatchedSearch.new facets.each do |facet| batch.searches << ThinkingSphinx::Search.new(query, (facet)) end batch.populate ThinkingSphinx::Middlewares::RAW_ONLY facets.each_with_index do |facet, index| @hash[facet.name.to_sym] = facet.results_from batch.searches[index].raw end @hash[:class] = @hash[:sphinx_internal_class] @populated = true end |
#to_hash ⇒ Object
54 55 56 57 58 |
# File 'lib/thinking_sphinx/facet_search.rb', line 54 def to_hash populate @hash end |