Commit e1a0da0107e96192f877de78737ef41575ab94c4
1 parent
af6235af
Exists in
master
and in
29 other branches
Restrict altBeautify fix and disabled searches
Showing
9 changed files
with
105 additions
and
70 deletions
Show diff stats
app/controllers/public/search_controller.rb
@@ -44,8 +44,9 @@ class SearchController < PublicController | @@ -44,8 +44,9 @@ class SearchController < PublicController | ||
44 | end | 44 | end |
45 | 45 | ||
46 | def products | 46 | def products |
47 | + public_filters = ['public:true', 'enabled:true'] | ||
47 | if !@empty_query | 48 | if !@empty_query |
48 | - full_text_search ['public:true', 'enabled:true'] | 49 | + full_text_search public_filters |
49 | else | 50 | else |
50 | @one_page = true | 51 | @one_page = true |
51 | @geosearch = logged_in? && current_user.person.lat && current_user.person.lng | 52 | @geosearch = logged_in? && current_user.person.lat && current_user.person.lng |
@@ -53,11 +54,11 @@ class SearchController < PublicController | @@ -53,11 +54,11 @@ class SearchController < PublicController | ||
53 | extra_limit = LIST_SEARCH_LIMIT*5 | 54 | extra_limit = LIST_SEARCH_LIMIT*5 |
54 | sql_options = {:limit => LIST_SEARCH_LIMIT, :order => 'random()'} | 55 | sql_options = {:limit => LIST_SEARCH_LIMIT, :order => 'random()'} |
55 | if @geosearch | 56 | if @geosearch |
56 | - full_text_search ['public:true', "{!geofilt}"], :sql_options => sql_options, :extra_limit => extra_limit, | 57 | + full_text_search public_filters, :sql_options => sql_options, :extra_limit => extra_limit, |
57 | :alternate_query => "{!boost b=recip(geodist(),#{"%e" % (1.to_f/DistBoost)},1,1)}", | 58 | :alternate_query => "{!boost b=recip(geodist(),#{"%e" % (1.to_f/DistBoost)},1,1)}", |
58 | :radius => DistFilt, :latitude => current_user.person.lat, :longitude => current_user.person.lng | 59 | :radius => DistFilt, :latitude => current_user.person.lat, :longitude => current_user.person.lng |
59 | else | 60 | else |
60 | - full_text_search ['public:true'], :sql_options => sql_options, :extra_limit => extra_limit, | 61 | + full_text_search public_filters, :sql_options => sql_options, :extra_limit => extra_limit, |
61 | :boost_functions => ['recip(ms(NOW/HOUR,updated_at),1.3e-10,1,1)'] | 62 | :boost_functions => ['recip(ms(NOW/HOUR,updated_at),1.3e-10,1,1)'] |
62 | end | 63 | end |
63 | end | 64 | end |
@@ -190,7 +191,9 @@ class SearchController < PublicController | @@ -190,7 +191,9 @@ class SearchController < PublicController | ||
190 | end | 191 | end |
191 | 192 | ||
192 | def load_category | 193 | def load_category |
193 | - unless params[:category_path].blank? | 194 | + if params[:category_path].blank? |
195 | + render_not_found if params[:action] == 'category_index' | ||
196 | + else | ||
194 | path = params[:category_path].join('/') | 197 | path = params[:category_path].join('/') |
195 | @category = environment.categories.find_by_path(path) | 198 | @category = environment.categories.find_by_path(path) |
196 | if @category.nil? | 199 | if @category.nil? |
@@ -229,22 +232,19 @@ class SearchController < PublicController | @@ -229,22 +232,19 @@ class SearchController < PublicController | ||
229 | end | 232 | end |
230 | 233 | ||
231 | def load_search_assets | 234 | def load_search_assets |
232 | - @enabled_searches = [ | ||
233 | - [ :articles, _('Contents') ], | ||
234 | - [ :enterprises, _('Enterprises') ], | ||
235 | - [ :people, _('People') ], | ||
236 | - [ :communities, _('Communities') ], | ||
237 | - [ :products, _('Products and Services') ], | ||
238 | - [ :events, _('Events') ] | ||
239 | - ].select {|key, name| !environment.enabled?('disable_asset_' + key.to_s) } | 235 | + if Searches.keys.include?(params[:action].to_sym) and environment.enabled?("disable_asset_#{params[:action]}") |
236 | + render_not_found | ||
237 | + return | ||
238 | + end | ||
240 | 239 | ||
240 | + @enabled_searches = Searches.select {|key, name| environment.disabled?("disable_asset_#{params[:action]}") } | ||
241 | @searching = {} | 241 | @searching = {} |
242 | @titles = {} | 242 | @titles = {} |
243 | @enabled_searches.each do |key, name| | 243 | @enabled_searches.each do |key, name| |
244 | @titles[key] = name | 244 | @titles[key] = name |
245 | @searching[key] = params[:action] == 'index' || params[:action] == key.to_s | 245 | @searching[key] = params[:action] == 'index' || params[:action] == key.to_s |
246 | end | 246 | end |
247 | - @names = @titles if @names.nil? | 247 | + @names = @titles if @names.nil? |
248 | end | 248 | end |
249 | 249 | ||
250 | def limit | 250 | def limit |
app/helpers/search_helper.rb
@@ -6,6 +6,16 @@ module SearchHelper | @@ -6,6 +6,16 @@ module SearchHelper | ||
6 | MULTIPLE_SEARCH_LIMIT = 8 | 6 | MULTIPLE_SEARCH_LIMIT = 8 |
7 | DistFilt = 200 | 7 | DistFilt = 200 |
8 | DistBoost = 50 | 8 | DistBoost = 50 |
9 | + | ||
10 | + Searches = ActiveSupport::OrderedHash[ | ||
11 | + :articles, _('Contents'), | ||
12 | + :enterprises, _('Enterprises'), | ||
13 | + :people, _('People'), | ||
14 | + :communities, _('Communities'), | ||
15 | + :products, _('Products and Services'), | ||
16 | + :events, _('Events'), | ||
17 | + ] | ||
18 | + | ||
9 | SortOptions = { | 19 | SortOptions = { |
10 | :products => ActiveSupport::OrderedHash[ :none, {:label => _('Relevance')}, | 20 | :products => ActiveSupport::OrderedHash[ :none, {:label => _('Relevance')}, |
11 | :more_recent, {:label => _('More Recent'), :solr_opts => {:sort => 'updated_at desc, score desc'}}, | 21 | :more_recent, {:label => _('More Recent'), :solr_opts => {:sort => 'updated_at desc, score desc'}}, |
@@ -112,7 +122,7 @@ module SearchHelper | @@ -112,7 +122,7 @@ module SearchHelper | ||
112 | 122 | ||
113 | if count > 0 | 123 | if count > 0 |
114 | url = params.merge(:facet => params[:facet].merge( | 124 | url = params.merge(:facet => params[:facet].merge( |
115 | - id => facet[:label_id].nil? ? value : params[:facet][id].merge( facet[:label_id] => params[:facet][id][facet[:label_id]].to_a.push(value) ) | 125 | + id => facet[:label_id].nil? ? value : params[:facet][id].merge( facet[:label_id] => params[:facet][id][facet[:label_id]].to_a | [value] ) |
116 | )) | 126 | )) |
117 | else | 127 | else |
118 | # preserve others filters and change this filter | 128 | # preserve others filters and change this filter |
app/models/environment.rb
@@ -281,6 +281,9 @@ class Environment < ActiveRecord::Base | @@ -281,6 +281,9 @@ class Environment < ActiveRecord::Base | ||
281 | def enabled?(feature) | 281 | def enabled?(feature) |
282 | self.settings["#{feature}_enabled".to_sym] == true | 282 | self.settings["#{feature}_enabled".to_sym] == true |
283 | end | 283 | end |
284 | + def disabled?(feature) | ||
285 | + !self.enabled?(feature) | ||
286 | + end | ||
284 | 287 | ||
285 | # enables the features identified by <tt>features</tt>, which is expected to | 288 | # enables the features identified by <tt>features</tt>, which is expected to |
286 | # be an Enumarable object containing the identifiers of the desired features. | 289 | # be an Enumarable object containing the identifiers of the desired features. |
app/models/input.rb
@@ -59,4 +59,7 @@ class Input < ActiveRecord::Base | @@ -59,4 +59,7 @@ class Input < ActiveRecord::Base | ||
59 | return 0 if self.amount_used.blank? || self.price_per_unit.blank? | 59 | return 0 if self.amount_used.blank? || self.price_per_unit.blank? |
60 | self.amount_used * self.price_per_unit | 60 | self.amount_used * self.price_per_unit |
61 | end | 61 | end |
62 | + | ||
63 | + alias_method :price, :cost | ||
64 | + | ||
62 | end | 65 | end |
app/views/search/_product.rhtml
@@ -27,15 +27,10 @@ | @@ -27,15 +27,10 @@ | ||
27 | <% end %> | 27 | <% end %> |
28 | 28 | ||
29 | <% if product.price_described? %> | 29 | <% if product.price_described? %> |
30 | - <% title = product.inputs.map{ |i| | 30 | + <% title = (product.inputs + product.price_details).map{ |i| |
31 | '<div class="search-product-input-dots-to-price">' + | 31 | '<div class="search-product-input-dots-to-price">' + |
32 | '<div class="search-product-input-name">' + i.product_category.name + '</div>' + | 32 | '<div class="search-product-input-name">' + i.product_category.name + '</div>' + |
33 | - price_span(i.cost, :class => 'search-product-input-price') + | ||
34 | - '</div>' }.join('') %> | ||
35 | - <% title += product.price_details.map{ |p| | ||
36 | - '<div class="search-product-input-dots-to-price">' + | ||
37 | - '<div class="search-product-input-name">' + p.production_cost.name + '</div>' + | ||
38 | - price_span(p.price, :class => 'search-product-input-price') + | 33 | + price_span(i.price, :class => 'search-product-input-price') + |
39 | '</div>' }.join('') %> | 34 | '</div>' }.join('') %> |
40 | <%= link_to_function _("Open Price"), '', :title => title, :class => "search-product-price-details" %> | 35 | <%= link_to_function _("Open Price"), '', :title => title, :class => "search-product-price-details" %> |
41 | <% end %> | 36 | <% end %> |
@@ -80,10 +75,11 @@ | @@ -80,10 +75,11 @@ | ||
80 | </div> | 75 | </div> |
81 | </div> | 76 | </div> |
82 | 77 | ||
78 | + <div style="clear: both"></div> | ||
79 | + | ||
83 | <%= extra_content.join('\n') %> | 80 | <%= extra_content.join('\n') %> |
84 | <% extra_properties.each do |property| %> | 81 | <% extra_properties.each do |property| %> |
85 | <div><%= property[:name] + ': ' + instance_eval(&property[:content]) %></div> | 82 | <div><%= property[:name] + ': ' + instance_eval(&property[:content]) %></div> |
86 | <% end %> | 83 | <% end %> |
87 | 84 | ||
88 | - <br /><br /> | ||
89 | </li> | 85 | </li> |
app/views/search/products.rhtml
1 | -<% if @environment.settings[:disable_asset_products_enabled] %> | ||
2 | - Product search disabled | ||
3 | -<% else %> | 1 | +<%= search_page_title( @titles[:products], @category ) %> |
4 | 2 | ||
5 | - <%= search_page_title( @titles[:products], @category ) %> | ||
6 | - | ||
7 | - <div id="search-column-left"> | ||
8 | - <% if !@empty_query %> | ||
9 | - <% button_bar do %> | ||
10 | - <%= display_map_list_button %> | ||
11 | - <% end %> | ||
12 | - <%= facets_menu(:products, @facets) %> | ||
13 | - <% end %> | ||
14 | - </div> | 3 | +<div id="search-column-left"> |
4 | + <% if !@empty_query %> | ||
5 | + <% button_bar do %> | ||
6 | + <%= display_map_list_button %> | ||
7 | +<% end %> | ||
8 | + <%= facets_menu(:products, @facets) %> | ||
9 | +<% end %> | ||
10 | +</div> | ||
15 | 11 | ||
16 | - <div id="search-column-right"> | ||
17 | - <%= render :partial => 'search_form', :locals => { :hint => _('Type the product, service, city or qualifier desired') } %> | ||
18 | - <%= render :partial => 'results_header' %> | 12 | +<div id="search-column-right"> |
13 | + <%= render :partial => 'search_form', :locals => { :hint => _('Type the product, service, city or qualifier desired') } %> | ||
14 | + <%= render :partial => 'results_header' %> | ||
19 | 15 | ||
20 | - <%= display_results(true) %> | ||
21 | - <% if !@one_page and params[:display] != 'map' %> | ||
22 | - <%= pagination_links @results[:products] %> | ||
23 | - <% end %> | ||
24 | - </div> | 16 | + <%= display_results(true) %> |
17 | + <% if !@one_page and params[:display] != 'map' %> | ||
18 | + <%= pagination_links @results[:products] %> | ||
19 | +<% end %> | ||
20 | +</div> | ||
25 | 21 | ||
22 | +<% javascript_tag do %> | ||
23 | + jQuery('.search-product-price-details').altBeautify(); | ||
26 | <% end %> | 24 | <% end %> |
27 | 25 | ||
28 | <div style="clear: both"></div> | 26 | <div style="clear: both"></div> |
public/javascripts/application.js
@@ -756,6 +756,11 @@ $.fn.hint = function (blurClass) { | @@ -756,6 +756,11 @@ $.fn.hint = function (blurClass) { | ||
756 | 756 | ||
757 | })(jQuery); | 757 | })(jQuery); |
758 | 758 | ||
759 | +/* | ||
760 | + * altBeautify: put a styled tooltip on elements with | ||
761 | + * HTML on title and alt attributes. | ||
762 | + */ | ||
763 | + | ||
759 | var altBeautify = jQuery('<div id="alt-beautify" style="display:none; position: absolute"/>') | 764 | var altBeautify = jQuery('<div id="alt-beautify" style="display:none; position: absolute"/>') |
760 | .append('<div class="alt-beautify-content"/>') | 765 | .append('<div class="alt-beautify-content"/>') |
761 | .append('<div class="alt-beautify-arrow-border alt-beautify-arrow"/>') | 766 | .append('<div class="alt-beautify-arrow-border alt-beautify-arrow"/>') |
@@ -779,7 +784,7 @@ function altHide() { | @@ -779,7 +784,7 @@ function altHide() { | ||
779 | altBeautify.hide(); | 784 | altBeautify.hide(); |
780 | } | 785 | } |
781 | 786 | ||
782 | -jQuery('a[title]').live('mouseover', function (e) { | 787 | +function altShow(e) { |
783 | alt = jQuery(this).attr('title'); | 788 | alt = jQuery(this).attr('title'); |
784 | if (alt != '') { | 789 | if (alt != '') { |
785 | jQuery(this).attr('alt-beautify', alt); | 790 | jQuery(this).attr('alt-beautify', alt); |
@@ -788,9 +793,27 @@ jQuery('a[title]').live('mouseover', function (e) { | @@ -788,9 +793,27 @@ jQuery('a[title]').live('mouseover', function (e) { | ||
788 | 793 | ||
789 | altTarget = this; | 794 | altTarget = this; |
790 | setTimeout("altTimeout()", 500); | 795 | setTimeout("altTimeout()", 500); |
791 | -}); | ||
792 | -jQuery('a[title]').live('mouseout', altHide); | ||
793 | -jQuery('a[title]').live('click', altHide); | 796 | +} |
797 | + | ||
798 | +(function($) { | ||
799 | + | ||
800 | + jQuery.fn.altBeautify = function() { | ||
801 | + return this.each(function() { | ||
802 | + jQuery(this).bind('mouseover', altShow); | ||
803 | + jQuery(this).bind('mouseout', altHide); | ||
804 | + jQuery(this).bind('click', altHide); | ||
805 | + }); | ||
806 | + } | ||
807 | + | ||
808 | +})(jQuery); | ||
809 | + | ||
810 | +// enable it generally | ||
811 | +// jQuery('*[title]').live('mouseover', altShow); | ||
812 | +// jQuery('*[title]').live('mouseout', altHide); | ||
813 | +// jQuery('*[title]').live('click', altHide); | ||
814 | +// jQuery('image[alt]').live('mouseover', altShow); | ||
815 | +// jQuery('image[alt]').live('mouseout', altHide); | ||
816 | +// jQuery('image[alt]').live('click', altHide); | ||
794 | 817 | ||
795 | 818 | ||
796 | function facet_options_toggle(id, url) { | 819 | function facet_options_toggle(id, url) { |
test/functional/search_controller_test.rb
@@ -787,12 +787,12 @@ class SearchControllerTest < ActionController::TestCase | @@ -787,12 +787,12 @@ class SearchControllerTest < ActionController::TestCase | ||
787 | prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent.id, :product_category_id => @product_category.id) | 787 | prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent.id, :product_category_id => @product_category.id) |
788 | prod3 = Product.create!(:name => 'product 3', :enterprise_id => ent.id, :product_category_id => @product_category.id) | 788 | prod3 = Product.create!(:name => 'product 3', :enterprise_id => ent.id, :product_category_id => @product_category.id) |
789 | 789 | ||
790 | - prod3.name = 'product 4' | ||
791 | - prod3.save! | ||
792 | - prod1.name = 'product 5' | ||
793 | - prod1.save! | ||
794 | - prod2.name = 'product 6' | ||
795 | - prod2.save! | 790 | + # change others attrs will make updated_at = Time.now for all |
791 | + Product.record_timestamps = false | ||
792 | + prod3.update_attribute :updated_at, Time.now-2.days | ||
793 | + prod1.update_attribute :updated_at, Time.now-1.days | ||
794 | + prod2.update_attribute :updated_at, Time.now | ||
795 | + Product.record_timestamps = true | ||
796 | 796 | ||
797 | get :products, :query => 'product', :order_by => :more_recent | 797 | get :products, :query => 'product', :order_by => :more_recent |
798 | 798 | ||
@@ -816,13 +816,13 @@ class SearchControllerTest < ActionController::TestCase | @@ -816,13 +816,13 @@ class SearchControllerTest < ActionController::TestCase | ||
816 | prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent.id, :product_category_id => @product_category.id) | 816 | prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent.id, :product_category_id => @product_category.id) |
817 | prod3 = Product.create!(:name => 'product 3', :enterprise_id => ent.id, :product_category_id => @product_category.id) | 817 | prod3 = Product.create!(:name => 'product 3', :enterprise_id => ent.id, :product_category_id => @product_category.id) |
818 | 818 | ||
819 | - prod3.update_attribute! :name, 'product A' | ||
820 | - prod2.update_attribute! :name, 'product B' | ||
821 | - prod1.update_attribute! :name, 'product C' | 819 | + prod3.update_attribute :name, 'product A' |
820 | + prod2.update_attribute :name, 'product B' | ||
821 | + prod1.update_attribute :name, 'product C' | ||
822 | 822 | ||
823 | get :products, :query => 'product', :order_by => :name | 823 | get :products, :query => 'product', :order_by => :name |
824 | 824 | ||
825 | - assert_equal [prod3, prod1, prod2], assigns(:results)[:products].docs | 825 | + assert_equal [prod3, prod2, prod1], assigns(:results)[:products].docs |
826 | end | 826 | end |
827 | 827 | ||
828 | should 'order product results by closest when requested' do | 828 | should 'order product results by closest when requested' do |
@@ -871,16 +871,16 @@ class SearchControllerTest < ActionController::TestCase | @@ -871,16 +871,16 @@ class SearchControllerTest < ActionController::TestCase | ||
871 | art2 = Article.create!(:name => 'review A', :profile_id => fast_create(Person).id) | 871 | art2 = Article.create!(:name => 'review A', :profile_id => fast_create(Person).id) |
872 | art3 = Article.create!(:name => 'review B', :profile_id => fast_create(Person).id) | 872 | art3 = Article.create!(:name => 'review B', :profile_id => fast_create(Person).id) |
873 | 873 | ||
874 | - art1.name = 'review 10' | ||
875 | - art1.save! | ||
876 | - art3.name = 'review 87' | ||
877 | - art3.save! | ||
878 | - art2.name = 'review 54' | ||
879 | - art2.save! | 874 | + # change others attrs will make updated_at = Time.now for all |
875 | + Article.record_timestamps = false | ||
876 | + art3.update_attribute :updated_at, Time.now-2.days | ||
877 | + art1.update_attribute :updated_at, Time.now-1.days | ||
878 | + art2.update_attribute :updated_at, Time.now | ||
879 | + Article.record_timestamps = true | ||
880 | 880 | ||
881 | get :articles, :query => 'review', :order_by => :more_recent | 881 | get :articles, :query => 'review', :order_by => :more_recent |
882 | 882 | ||
883 | - assert_equal [art2, art3, art1], assigns(:results)[:articles].docs | 883 | + assert_equal [art2, art1, art3], assigns(:results)[:articles].docs |
884 | end | 884 | end |
885 | 885 | ||
886 | should 'order enterprise results by name when requested' do | 886 | should 'order enterprise results by name when requested' do |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/parser_methods.rb
@@ -16,9 +16,7 @@ module ActsAsSolr #:nodoc: | @@ -16,9 +16,7 @@ module ActsAsSolr #:nodoc: | ||
16 | begin | 16 | begin |
17 | Deprecation.validate_query(options) | 17 | Deprecation.validate_query(options) |
18 | 18 | ||
19 | - query_options[:filter_queries] ||= [] | ||
20 | - options[:alternate_query] ||= '' | ||
21 | - options[:alternate_query].strip! | 19 | + query_options[:filter_queries] = [] |
22 | query.strip! | 20 | query.strip! |
23 | 21 | ||
24 | # using *:* disable index boosts, so use the type filter | 22 | # using *:* disable index boosts, so use the type filter |
@@ -26,14 +24,20 @@ module ActsAsSolr #:nodoc: | @@ -26,14 +24,20 @@ module ActsAsSolr #:nodoc: | ||
26 | query = solr_type_condition(options) | 24 | query = solr_type_condition(options) |
27 | else | 25 | else |
28 | query = sanitize_query(query) | 26 | query = sanitize_query(query) |
29 | - query_options[:filter_queries] = [solr_type_condition(options)] | 27 | + query_options[:filter_queries] << solr_type_condition(options) |
30 | 28 | ||
31 | # put types on filtered fields | 29 | # put types on filtered fields |
32 | query = replace_types([*query], ':').first | 30 | query = replace_types([*query], ':').first |
33 | end | 31 | end |
34 | 32 | ||
33 | + query_options[:filter_queries] += replace_types([*options[:filter_queries]], '') if options[:filter_queries] | ||
34 | + | ||
35 | + options[:alternate_query] ||= '' | ||
36 | + options[:alternate_query].strip! | ||
35 | query = "#{options[:alternate_query]} #{query}" unless options[:alternate_query].blank? | 37 | query = "#{options[:alternate_query]} #{query}" unless options[:alternate_query].blank? |
38 | + | ||
36 | query = add_relevance query, options[:relevance] | 39 | query = add_relevance query, options[:relevance] |
40 | + | ||
37 | query_options[:query] = query | 41 | query_options[:query] = query |
38 | 42 | ||
39 | field_list = options[:models].nil? ? solr_configuration[:primary_key_field] : "id" | 43 | field_list = options[:models].nil? ? solr_configuration[:primary_key_field] : "id" |
@@ -46,8 +50,6 @@ module ActsAsSolr #:nodoc: | @@ -46,8 +50,6 @@ module ActsAsSolr #:nodoc: | ||
46 | 50 | ||
47 | query_options[:operator] = options[:operator] | 51 | query_options[:operator] = options[:operator] |
48 | 52 | ||
49 | - query_options[:filter_queries] += replace_types([*options[:filter_queries]], '') if options[:filter_queries] | ||
50 | - | ||
51 | query_options[:boost_functions] = replace_types([*options[:boost_functions]], '').join(' ') if options[:boost_functions] | 53 | query_options[:boost_functions] = replace_types([*options[:boost_functions]], '').join(' ') if options[:boost_functions] |
52 | 54 | ||
53 | # first steps on the facet parameter processing | 55 | # first steps on the facet parameter processing |