Commit ec7c804d2898fbb50a508c7705a4b2953121b491
1 parent
5e791399
Exists in
master
and in
28 other branches
Faster and simples unfiltered facets treatment
Showing
1 changed file
with
23 additions
and
20 deletions
Show diff stats
lib/acts_as_faceted.rb
@@ -68,31 +68,30 @@ module ActsAsFaceted | @@ -68,31 +68,30 @@ module ActsAsFaceted | ||
68 | facets_data ||= {} | 68 | facets_data ||= {} |
69 | solr_facet = to_solr_fields_names[facet[:solr_field]] | 69 | solr_facet = to_solr_fields_names[facet[:solr_field]] |
70 | 70 | ||
71 | - if unfiltered_facets_data | ||
72 | - facets_data = unfiltered_facets_data.mash do |container, value| | ||
73 | - [container, value.mash do |field, value| | ||
74 | - facets_data[container] = {} if facets_data[container].nil? or facets_data[container] == [] | ||
75 | - f = Hash[Array(facets_data[container][field])] | ||
76 | - zeros = [] | ||
77 | - [field, Array(value).map do |id, count| | ||
78 | - count = f[id] | ||
79 | - if count.nil? | ||
80 | - zeros.push [id, 0] | ||
81 | - nil | ||
82 | - else | ||
83 | - [id, count] | ||
84 | - end | ||
85 | - end.compact + zeros] | ||
86 | - end] | ||
87 | - end | ||
88 | - end | ||
89 | - | ||
90 | if facet[:queries] | 71 | if facet[:queries] |
91 | container = facets_data[facets_results_containers[:queries]] | 72 | container = facets_data[facets_results_containers[:queries]] |
92 | facet_data = (container.nil? or container.empty?) ? [] : container.select{ |k,v| k.starts_with? solr_facet } | 73 | facet_data = (container.nil? or container.empty?) ? [] : container.select{ |k,v| k.starts_with? solr_facet } |
74 | + container = unfiltered_facets_data[facets_results_containers[:queries]] | ||
75 | + unfiltered_facet_data = (container.nil? or container.empty?) ? [] : container.select{ |k,v| k.starts_with? solr_facet } | ||
93 | else | 76 | else |
94 | container = facets_data[facets_results_containers[:fields]] | 77 | container = facets_data[facets_results_containers[:fields]] |
95 | facet_data = (container.nil? or container.empty?) ? [] : container[solr_facet] || [] | 78 | facet_data = (container.nil? or container.empty?) ? [] : container[solr_facet] || [] |
79 | + container = unfiltered_facets_data[facets_results_containers[:fields]] | ||
80 | + unfiltered_facet_data = (container.nil? or container.empty?) ? [] : container[solr_facet] || [] | ||
81 | + end | ||
82 | + | ||
83 | + if !unfiltered_facets_data.blank? and !facet_params.blank? | ||
84 | + f = Hash[Array(facet_data)] | ||
85 | + zeros = [] | ||
86 | + facet_data = unfiltered_facet_data.map do |id, count| | ||
87 | + count = f[id] | ||
88 | + if count.nil? | ||
89 | + zeros.push [id, 0] | ||
90 | + nil | ||
91 | + else | ||
92 | + [id, count] | ||
93 | + end | ||
94 | + end.compact + zeros | ||
96 | end | 95 | end |
97 | 96 | ||
98 | facet_count = facet_data.length | 97 | facet_count = facet_data.length |
@@ -158,6 +157,10 @@ module ActsAsFaceted | @@ -158,6 +157,10 @@ module ActsAsFaceted | ||
158 | end | 157 | end |
159 | end | 158 | end |
160 | 159 | ||
160 | + def facet_label(facet) | ||
161 | + _ facet[:label] | ||
162 | + end | ||
163 | + | ||
161 | def facets_find_options(facets_selected = {}, options = {}) | 164 | def facets_find_options(facets_selected = {}, options = {}) |
162 | browses = [] | 165 | browses = [] |
163 | facets_selected ||= {} | 166 | facets_selected ||= {} |
@@ -176,7 +179,7 @@ module ActsAsFaceted | @@ -176,7 +179,7 @@ module ActsAsFaceted | ||
176 | {:facets => {:zeros => false, :sort => :count, | 179 | {:facets => {:zeros => false, :sort => :count, |
177 | :fields => facets_option_for_solr, | 180 | :fields => facets_option_for_solr, |
178 | :browse => browses, | 181 | :browse => browses, |
179 | - :query => facets.map { |f, options| options[:queries].keys.map { |q| f.to_s + ':' + q } if options[:queries]}.compact.flatten, | 182 | + :query => facets.map { |f, options| options[:queries].keys.map { |q| f.to_s + ':' + q } if options[:queries] }.compact.flatten, |
180 | } | 183 | } |
181 | } | 184 | } |
182 | end | 185 | end |