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
- #populated? ⇒ Boolean
- #to_hash ⇒ Object
Constructor Details
#initialize(query = nil, options = {}) ⇒ FacetSearch
Returns a new instance of FacetSearch.
9 10 11 12 13 |
# File 'lib/thinking_sphinx/facet_search.rb', line 9 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.
6 7 8 |
# File 'lib/thinking_sphinx/facet_search.rb', line 6 def @options end |
#query ⇒ Object
Returns the value of attribute query.
7 8 9 |
# File 'lib/thinking_sphinx/facet_search.rb', line 7 def query @query end |
Instance Method Details
#[](key) ⇒ Object
15 16 17 18 19 |
# File 'lib/thinking_sphinx/facet_search.rb', line 15 def [](key) populate @hash[key] end |
#each(&block) ⇒ Object
21 22 23 24 25 |
# File 'lib/thinking_sphinx/facet_search.rb', line 21 def each(&block) populate @hash.each(&block) end |
#for(facet_values) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/thinking_sphinx/facet_search.rb', line 27 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
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/thinking_sphinx/facet_search.rb', line 37 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 |
#populated? ⇒ Boolean
56 57 58 |
# File 'lib/thinking_sphinx/facet_search.rb', line 56 def populated? @populated end |
#to_hash ⇒ Object
60 61 62 63 64 |
# File 'lib/thinking_sphinx/facet_search.rb', line 60 def to_hash populate @hash end |