diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index f797c08..068a3cc 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -73,7 +73,7 @@ class SearchController < ApplicationController #nothing, just to enable end def enterprises - #nothing, just to enable + load_product_categories_menu(:enterprises) end def communities #nothing, just to enable @@ -82,6 +82,17 @@ class SearchController < ApplicationController #nothins, just to enable end + def products + load_product_categories_menu(:products) + end + + def load_product_categories_menu(asset) + @results[asset].uniq! + @categories_menu = ProductCategory.menu_categories(@product_category, environment).map do |cat| + [cat, @finder.count(:products, @filtered_query, calculate_find_options(asset, nil, cat, @region, params[:radius]))] + end.select{|cat, hits| hits > 0 } + end + def calculate_find_options(asset, limit, product_category, region, radius) result = { :limit => limit, :product_category => product_category} @@ -128,7 +139,7 @@ class SearchController < ApplicationController number_of_result_assets = @searching.values.select{|v| v}.size # apply limit when searching for only one type of asset - limit = (number_of_result_assets == 1) ? LIST_LIMIT : nil + limit = (number_of_result_assets == 1) ? nil: LIST_LIMIT # apply limit to all searches # limit = nil @@ -153,13 +164,6 @@ class SearchController < ApplicationController render :action => 'index' end - def products - @results[:products].uniq! - @categories_menu = ProductCategory.menu_categories(@product_category, environment).map do |cat| - [cat, @finder.count(:products, @filtered_query, calculate_find_options(:products, nil, cat, @region, params[:radius]))] - end.select{|cat, hits| hits > 0 } - end - alias :assets :index ####################################################### diff --git a/app/models/category_finder.rb b/app/models/category_finder.rb index 3e7e6b6..0ca264e 100644 --- a/app/models/category_finder.rb +++ b/app/models/category_finder.rb @@ -9,7 +9,7 @@ class CategoryFinder - def find(asset, query = nil, options={}) + def find(asset, query='', options={}) @region = Region.find_by_id(options.delete(:region)) if options.has_key?(:region) if @region && options[:within] options[:origin] = [@region.lat, @region.lng] @@ -17,9 +17,15 @@ class CategoryFinder options.delete(:within) end + # FIXME: can break if more things is added in the extra_data_for_index ferret field in enterprise + # this searches for enterprise using its products categories criteria + if options[:product_category] && asset.to_s == 'enterprises' + query = query.blank? ? "extra_data_for_index:#{options[:product_category].name}" : query + " +extra_data_for_index:#{options[:product_category].name}" + end + if query.blank? asset_class(asset).find(:all, options_for_find(asset_class(asset), {:order => "created_at desc, #{asset_table(asset)}.id desc"}.merge(options))) - else + else asset_class(asset).find_by_contents(query, {}, options_for_find(asset_class(asset), options)).uniq end end diff --git a/app/views/search/enterprises.rhtml b/app/views/search/enterprises.rhtml deleted file mode 120000 index aba8524..0000000 --- a/app/views/search/enterprises.rhtml +++ /dev/null @@ -1 +0,0 @@ -people.rhtml \ No newline at end of file diff --git a/app/views/search/enterprises.rhtml b/app/views/search/enterprises.rhtml new file mode 100644 index 0000000..24713b3 --- /dev/null +++ b/app/views/search/enterprises.rhtml @@ -0,0 +1,19 @@ +