Commit e1a0da0107e96192f877de78737ef41575ab94c4

Authored by Braulio Bhavamitra
1 parent af6235af

Restrict altBeautify fix and disabled searches

app/controllers/public/search_controller.rb
... ... @@ -44,8 +44,9 @@ class SearchController < PublicController
44 44 end
45 45  
46 46 def products
  47 + public_filters = ['public:true', 'enabled:true']
47 48 if !@empty_query
48   - full_text_search ['public:true', 'enabled:true']
  49 + full_text_search public_filters
49 50 else
50 51 @one_page = true
51 52 @geosearch = logged_in? && current_user.person.lat && current_user.person.lng
... ... @@ -53,11 +54,11 @@ class SearchController < PublicController
53 54 extra_limit = LIST_SEARCH_LIMIT*5
54 55 sql_options = {:limit => LIST_SEARCH_LIMIT, :order => 'random()'}
55 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 58 :alternate_query => "{!boost b=recip(geodist(),#{"%e" % (1.to_f/DistBoost)},1,1)}",
58 59 :radius => DistFilt, :latitude => current_user.person.lat, :longitude => current_user.person.lng
59 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 62 :boost_functions => ['recip(ms(NOW/HOUR,updated_at),1.3e-10,1,1)']
62 63 end
63 64 end
... ... @@ -190,7 +191,9 @@ class SearchController < PublicController
190 191 end
191 192  
192 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 197 path = params[:category_path].join('/')
195 198 @category = environment.categories.find_by_path(path)
196 199 if @category.nil?
... ... @@ -229,22 +232,19 @@ class SearchController < PublicController
229 232 end
230 233  
231 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 241 @searching = {}
242 242 @titles = {}
243 243 @enabled_searches.each do |key, name|
244 244 @titles[key] = name
245 245 @searching[key] = params[:action] == 'index' || params[:action] == key.to_s
246 246 end
247   - @names = @titles if @names.nil?
  247 + @names = @titles if @names.nil?
248 248 end
249 249  
250 250 def limit
... ...
app/helpers/search_helper.rb
... ... @@ -6,6 +6,16 @@ module SearchHelper
6 6 MULTIPLE_SEARCH_LIMIT = 8
7 7 DistFilt = 200
8 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 19 SortOptions = {
10 20 :products => ActiveSupport::OrderedHash[ :none, {:label => _('Relevance')},
11 21 :more_recent, {:label => _('More Recent'), :solr_opts => {:sort => 'updated_at desc, score desc'}},
... ... @@ -112,7 +122,7 @@ module SearchHelper
112 122  
113 123 if count > 0
114 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 127 else
118 128 # preserve others filters and change this filter
... ...
app/models/environment.rb
... ... @@ -281,6 +281,9 @@ class Environment < ActiveRecord::Base
281 281 def enabled?(feature)
282 282 self.settings["#{feature}_enabled".to_sym] == true
283 283 end
  284 + def disabled?(feature)
  285 + !self.enabled?(feature)
  286 + end
284 287  
285 288 # enables the features identified by <tt>features</tt>, which is expected to
286 289 # be an Enumarable object containing the identifiers of the desired features.
... ...
app/models/input.rb
... ... @@ -59,4 +59,7 @@ class Input &lt; ActiveRecord::Base
59 59 return 0 if self.amount_used.blank? || self.price_per_unit.blank?
60 60 self.amount_used * self.price_per_unit
61 61 end
  62 +
  63 + alias_method :price, :cost
  64 +
62 65 end
... ...
app/views/search/_product.rhtml
... ... @@ -27,15 +27,10 @@
27 27 <% end %>
28 28  
29 29 <% if product.price_described? %>
30   - <% title = product.inputs.map{ |i|
  30 + <% title = (product.inputs + product.price_details).map{ |i|
31 31 '<div class="search-product-input-dots-to-price">' +
32 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 34 '</div>' }.join('') %>
40 35 <%= link_to_function _("Open Price"), '', :title => title, :class => "search-product-price-details" %>
41 36 <% end %>
... ... @@ -80,10 +75,11 @@
80 75 </div>
81 76 </div>
82 77  
  78 + <div style="clear: both"></div>
  79 +
83 80 <%= extra_content.join('\n') %>
84 81 <% extra_properties.each do |property| %>
85 82 <div><%= property[:name] + ': ' + instance_eval(&property[:content]) %></div>
86 83 <% end %>
87 84  
88   - <br /><br />
89 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 24 <% end %>
27 25  
28 26 <div style="clear: both"></div>
... ...
public/javascripts/application.js
... ... @@ -756,6 +756,11 @@ $.fn.hint = function (blurClass) {
756 756  
757 757 })(jQuery);
758 758  
  759 +/*
  760 + * altBeautify: put a styled tooltip on elements with
  761 + * HTML on title and alt attributes.
  762 + */
  763 +
759 764 var altBeautify = jQuery('<div id="alt-beautify" style="display:none; position: absolute"/>')
760 765 .append('<div class="alt-beautify-content"/>')
761 766 .append('<div class="alt-beautify-arrow-border alt-beautify-arrow"/>')
... ... @@ -779,7 +784,7 @@ function altHide() {
779 784 altBeautify.hide();
780 785 }
781 786  
782   -jQuery('a[title]').live('mouseover', function (e) {
  787 +function altShow(e) {
783 788 alt = jQuery(this).attr('title');
784 789 if (alt != '') {
785 790 jQuery(this).attr('alt-beautify', alt);
... ... @@ -788,9 +793,27 @@ jQuery(&#39;a[title]&#39;).live(&#39;mouseover&#39;, function (e) {
788 793  
789 794 altTarget = this;
790 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 819 function facet_options_toggle(id, url) {
... ...
test/functional/search_controller_test.rb
... ... @@ -787,12 +787,12 @@ class SearchControllerTest &lt; ActionController::TestCase
787 787 prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent.id, :product_category_id => @product_category.id)
788 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 797 get :products, :query => 'product', :order_by => :more_recent
798 798  
... ... @@ -816,13 +816,13 @@ class SearchControllerTest &lt; ActionController::TestCase
816 816 prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent.id, :product_category_id => @product_category.id)
817 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 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 826 end
827 827  
828 828 should 'order product results by closest when requested' do
... ... @@ -871,16 +871,16 @@ class SearchControllerTest &lt; ActionController::TestCase
871 871 art2 = Article.create!(:name => 'review A', :profile_id => fast_create(Person).id)
872 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 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 884 end
885 885  
886 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 16 begin
17 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 20 query.strip!
23 21  
24 22 # using *:* disable index boosts, so use the type filter
... ... @@ -26,14 +24,20 @@ module ActsAsSolr #:nodoc:
26 24 query = solr_type_condition(options)
27 25 else
28 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 29 # put types on filtered fields
32 30 query = replace_types([*query], ':').first
33 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 37 query = "#{options[:alternate_query]} #{query}" unless options[:alternate_query].blank?
  38 +
36 39 query = add_relevance query, options[:relevance]
  40 +
37 41 query_options[:query] = query
38 42  
39 43 field_list = options[:models].nil? ? solr_configuration[:primary_key_field] : "id"
... ... @@ -46,8 +50,6 @@ module ActsAsSolr #:nodoc:
46 50  
47 51 query_options[:operator] = options[:operator]
48 52  
49   - query_options[:filter_queries] += replace_types([*options[:filter_queries]], '') if options[:filter_queries]
50   -
51 53 query_options[:boost_functions] = replace_types([*options[:boost_functions]], '').join(' ') if options[:boost_functions]
52 54  
53 55 # first steps on the facet parameter processing
... ...