diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb
index 128a32e..65a0d31 100644
--- a/app/controllers/public/search_controller.rb
+++ b/app/controllers/public/search_controller.rb
@@ -44,8 +44,9 @@ class SearchController < PublicController
end
def products
+ public_filters = ['public:true', 'enabled:true']
if !@empty_query
- full_text_search ['public:true', 'enabled:true']
+ full_text_search public_filters
else
@one_page = true
@geosearch = logged_in? && current_user.person.lat && current_user.person.lng
@@ -53,11 +54,11 @@ class SearchController < PublicController
extra_limit = LIST_SEARCH_LIMIT*5
sql_options = {:limit => LIST_SEARCH_LIMIT, :order => 'random()'}
if @geosearch
- full_text_search ['public:true', "{!geofilt}"], :sql_options => sql_options, :extra_limit => extra_limit,
+ full_text_search public_filters, :sql_options => sql_options, :extra_limit => extra_limit,
:alternate_query => "{!boost b=recip(geodist(),#{"%e" % (1.to_f/DistBoost)},1,1)}",
:radius => DistFilt, :latitude => current_user.person.lat, :longitude => current_user.person.lng
else
- full_text_search ['public:true'], :sql_options => sql_options, :extra_limit => extra_limit,
+ full_text_search public_filters, :sql_options => sql_options, :extra_limit => extra_limit,
:boost_functions => ['recip(ms(NOW/HOUR,updated_at),1.3e-10,1,1)']
end
end
@@ -190,7 +191,9 @@ class SearchController < PublicController
end
def load_category
- unless params[:category_path].blank?
+ if params[:category_path].blank?
+ render_not_found if params[:action] == 'category_index'
+ else
path = params[:category_path].join('/')
@category = environment.categories.find_by_path(path)
if @category.nil?
@@ -229,22 +232,19 @@ class SearchController < PublicController
end
def load_search_assets
- @enabled_searches = [
- [ :articles, _('Contents') ],
- [ :enterprises, _('Enterprises') ],
- [ :people, _('People') ],
- [ :communities, _('Communities') ],
- [ :products, _('Products and Services') ],
- [ :events, _('Events') ]
- ].select {|key, name| !environment.enabled?('disable_asset_' + key.to_s) }
+ if Searches.keys.include?(params[:action].to_sym) and environment.enabled?("disable_asset_#{params[:action]}")
+ render_not_found
+ return
+ end
+ @enabled_searches = Searches.select {|key, name| environment.disabled?("disable_asset_#{params[:action]}") }
@searching = {}
@titles = {}
@enabled_searches.each do |key, name|
@titles[key] = name
@searching[key] = params[:action] == 'index' || params[:action] == key.to_s
end
- @names = @titles if @names.nil?
+ @names = @titles if @names.nil?
end
def limit
diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb
index 1ce7df2..da79499 100644
--- a/app/helpers/search_helper.rb
+++ b/app/helpers/search_helper.rb
@@ -6,6 +6,16 @@ module SearchHelper
MULTIPLE_SEARCH_LIMIT = 8
DistFilt = 200
DistBoost = 50
+
+ Searches = ActiveSupport::OrderedHash[
+ :articles, _('Contents'),
+ :enterprises, _('Enterprises'),
+ :people, _('People'),
+ :communities, _('Communities'),
+ :products, _('Products and Services'),
+ :events, _('Events'),
+ ]
+
SortOptions = {
:products => ActiveSupport::OrderedHash[ :none, {:label => _('Relevance')},
:more_recent, {:label => _('More Recent'), :solr_opts => {:sort => 'updated_at desc, score desc'}},
@@ -112,7 +122,7 @@ module SearchHelper
if count > 0
url = params.merge(:facet => params[:facet].merge(
- id => facet[:label_id].nil? ? value : params[:facet][id].merge( facet[:label_id] => params[:facet][id][facet[:label_id]].to_a.push(value) )
+ id => facet[:label_id].nil? ? value : params[:facet][id].merge( facet[:label_id] => params[:facet][id][facet[:label_id]].to_a | [value] )
))
else
# preserve others filters and change this filter
diff --git a/app/models/environment.rb b/app/models/environment.rb
index 4425906..d2593fb 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -281,6 +281,9 @@ class Environment < ActiveRecord::Base
def enabled?(feature)
self.settings["#{feature}_enabled".to_sym] == true
end
+ def disabled?(feature)
+ !self.enabled?(feature)
+ end
# enables the features identified by features, which is expected to
# be an Enumarable object containing the identifiers of the desired features.
diff --git a/app/models/input.rb b/app/models/input.rb
index 541fbc4..006dc5a 100644
--- a/app/models/input.rb
+++ b/app/models/input.rb
@@ -59,4 +59,7 @@ class Input < ActiveRecord::Base
return 0 if self.amount_used.blank? || self.price_per_unit.blank?
self.amount_used * self.price_per_unit
end
+
+ alias_method :price, :cost
+
end
diff --git a/app/views/search/_product.rhtml b/app/views/search/_product.rhtml
index 142b511..6d1bf20 100644
--- a/app/views/search/_product.rhtml
+++ b/app/views/search/_product.rhtml
@@ -27,15 +27,10 @@
<% end %>
<% if product.price_described? %>
- <% title = product.inputs.map{ |i|
+ <% title = (product.inputs + product.price_details).map{ |i|
'
' }.join('') %>
- <% title += product.price_details.map{ |p|
- '' }.join('') %>
<%= link_to_function _("Open Price"), '', :title => title, :class => "search-product-price-details" %>
<% end %>
@@ -80,10 +75,11 @@
+
+
<%= extra_content.join('\n') %>
<% extra_properties.each do |property| %>
<%= property[:name] + ': ' + instance_eval(&property[:content]) %>
<% end %>
-
diff --git a/app/views/search/products.rhtml b/app/views/search/products.rhtml
index ddec0b3..74e8f02 100644
--- a/app/views/search/products.rhtml
+++ b/app/views/search/products.rhtml
@@ -1,28 +1,26 @@
-<% if @environment.settings[:disable_asset_products_enabled] %>
- Product search disabled
-<% else %>
+<%= search_page_title( @titles[:products], @category ) %>
- <%= search_page_title( @titles[:products], @category ) %>
-
-
- <% if !@empty_query %>
- <% button_bar do %>
- <%= display_map_list_button %>
- <% end %>
- <%= facets_menu(:products, @facets) %>
- <% end %>
-
+
+ <% if !@empty_query %>
+ <% button_bar do %>
+ <%= display_map_list_button %>
+<% end %>
+ <%= facets_menu(:products, @facets) %>
+<% end %>
+
-
- <%= render :partial => 'search_form', :locals => { :hint => _('Type the product, service, city or qualifier desired') } %>
- <%= render :partial => 'results_header' %>
+
+ <%= render :partial => 'search_form', :locals => { :hint => _('Type the product, service, city or qualifier desired') } %>
+ <%= render :partial => 'results_header' %>
- <%= display_results(true) %>
- <% if !@one_page and params[:display] != 'map' %>
- <%= pagination_links @results[:products] %>
- <% end %>
-
+ <%= display_results(true) %>
+ <% if !@one_page and params[:display] != 'map' %>
+ <%= pagination_links @results[:products] %>
+<% end %>
+
+<% javascript_tag do %>
+ jQuery('.search-product-price-details').altBeautify();
<% end %>
diff --git a/public/javascripts/application.js b/public/javascripts/application.js
index a89fe9a..2576362 100644
--- a/public/javascripts/application.js
+++ b/public/javascripts/application.js
@@ -756,6 +756,11 @@ $.fn.hint = function (blurClass) {
})(jQuery);
+/*
+ * altBeautify: put a styled tooltip on elements with
+ * HTML on title and alt attributes.
+ */
+
var altBeautify = jQuery('')
.append('')
.append('')
@@ -779,7 +784,7 @@ function altHide() {
altBeautify.hide();
}
-jQuery('a[title]').live('mouseover', function (e) {
+function altShow(e) {
alt = jQuery(this).attr('title');
if (alt != '') {
jQuery(this).attr('alt-beautify', alt);
@@ -788,9 +793,27 @@ jQuery('a[title]').live('mouseover', function (e) {
altTarget = this;
setTimeout("altTimeout()", 500);
-});
-jQuery('a[title]').live('mouseout', altHide);
-jQuery('a[title]').live('click', altHide);
+}
+
+(function($) {
+
+ jQuery.fn.altBeautify = function() {
+ return this.each(function() {
+ jQuery(this).bind('mouseover', altShow);
+ jQuery(this).bind('mouseout', altHide);
+ jQuery(this).bind('click', altHide);
+ });
+ }
+
+})(jQuery);
+
+// enable it generally
+// jQuery('*[title]').live('mouseover', altShow);
+// jQuery('*[title]').live('mouseout', altHide);
+// jQuery('*[title]').live('click', altHide);
+// jQuery('image[alt]').live('mouseover', altShow);
+// jQuery('image[alt]').live('mouseout', altHide);
+// jQuery('image[alt]').live('click', altHide);
function facet_options_toggle(id, url) {
diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb
index 2dcf7f0..d7b21ee 100644
--- a/test/functional/search_controller_test.rb
+++ b/test/functional/search_controller_test.rb
@@ -787,12 +787,12 @@ class SearchControllerTest < ActionController::TestCase
prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent.id, :product_category_id => @product_category.id)
prod3 = Product.create!(:name => 'product 3', :enterprise_id => ent.id, :product_category_id => @product_category.id)
- prod3.name = 'product 4'
- prod3.save!
- prod1.name = 'product 5'
- prod1.save!
- prod2.name = 'product 6'
- prod2.save!
+ # change others attrs will make updated_at = Time.now for all
+ Product.record_timestamps = false
+ prod3.update_attribute :updated_at, Time.now-2.days
+ prod1.update_attribute :updated_at, Time.now-1.days
+ prod2.update_attribute :updated_at, Time.now
+ Product.record_timestamps = true
get :products, :query => 'product', :order_by => :more_recent
@@ -816,13 +816,13 @@ class SearchControllerTest < ActionController::TestCase
prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent.id, :product_category_id => @product_category.id)
prod3 = Product.create!(:name => 'product 3', :enterprise_id => ent.id, :product_category_id => @product_category.id)
- prod3.update_attribute! :name, 'product A'
- prod2.update_attribute! :name, 'product B'
- prod1.update_attribute! :name, 'product C'
+ prod3.update_attribute :name, 'product A'
+ prod2.update_attribute :name, 'product B'
+ prod1.update_attribute :name, 'product C'
get :products, :query => 'product', :order_by => :name
- assert_equal [prod3, prod1, prod2], assigns(:results)[:products].docs
+ assert_equal [prod3, prod2, prod1], assigns(:results)[:products].docs
end
should 'order product results by closest when requested' do
@@ -871,16 +871,16 @@ class SearchControllerTest < ActionController::TestCase
art2 = Article.create!(:name => 'review A', :profile_id => fast_create(Person).id)
art3 = Article.create!(:name => 'review B', :profile_id => fast_create(Person).id)
- art1.name = 'review 10'
- art1.save!
- art3.name = 'review 87'
- art3.save!
- art2.name = 'review 54'
- art2.save!
+ # change others attrs will make updated_at = Time.now for all
+ Article.record_timestamps = false
+ art3.update_attribute :updated_at, Time.now-2.days
+ art1.update_attribute :updated_at, Time.now-1.days
+ art2.update_attribute :updated_at, Time.now
+ Article.record_timestamps = true
get :articles, :query => 'review', :order_by => :more_recent
- assert_equal [art2, art3, art1], assigns(:results)[:articles].docs
+ assert_equal [art2, art1, art3], assigns(:results)[:articles].docs
end
should 'order enterprise results by name when requested' do
diff --git a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/parser_methods.rb b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/parser_methods.rb
index 0602332..d3c4dbe 100644
--- a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/parser_methods.rb
+++ b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/parser_methods.rb
@@ -16,9 +16,7 @@ module ActsAsSolr #:nodoc:
begin
Deprecation.validate_query(options)
- query_options[:filter_queries] ||= []
- options[:alternate_query] ||= ''
- options[:alternate_query].strip!
+ query_options[:filter_queries] = []
query.strip!
# using *:* disable index boosts, so use the type filter
@@ -26,14 +24,20 @@ module ActsAsSolr #:nodoc:
query = solr_type_condition(options)
else
query = sanitize_query(query)
- query_options[:filter_queries] = [solr_type_condition(options)]
+ query_options[:filter_queries] << solr_type_condition(options)
# put types on filtered fields
query = replace_types([*query], ':').first
end
+ query_options[:filter_queries] += replace_types([*options[:filter_queries]], '') if options[:filter_queries]
+
+ options[:alternate_query] ||= ''
+ options[:alternate_query].strip!
query = "#{options[:alternate_query]} #{query}" unless options[:alternate_query].blank?
+
query = add_relevance query, options[:relevance]
+
query_options[:query] = query
field_list = options[:models].nil? ? solr_configuration[:primary_key_field] : "id"
@@ -46,8 +50,6 @@ module ActsAsSolr #:nodoc:
query_options[:operator] = options[:operator]
- query_options[:filter_queries] += replace_types([*options[:filter_queries]], '') if options[:filter_queries]
-
query_options[:boost_functions] = replace_types([*options[:boost_functions]], '').join(' ') if options[:boost_functions]
# first steps on the facet parameter processing
--
libgit2 0.21.2