| Module | SearchHelper |
| In: |
app/helpers/search_helper.rb
|
| STOP_WORDS | = | { 'pt_BR' => Ferret::Analysis::FULL_PORTUGUESE_STOP_WORDS, 'en' => Ferret::Analysis::FULL_ENGLISH_STOP_WORDS, } |
# File app/helpers/search_helper.rb, line 42
42: def display_item_map_info(item)
43: if item.kind_of?(Profile)
44: display_profile_info(item)
45: elsif item.kind_of?(Product)
46: display_product_info(item)
47: end
48: end
# File app/helpers/search_helper.rb, line 80
80: def display_product_info(product)
81: data = ''
82: unless product.price.nil?
83: data << content_tag('strong', _('Price: ')) + product.price + '<br/>'
84: end
85: unless product.enterprise.nil?
86: data << content_tag('strong', _('Provider: ')) + link_to_profile(product.enterprise.name, product.enterprise.identifier)
87: end
88: unless product.product_category.nil?
89: data << content_tag('strong', _('Category: ')) + link_to(product.product_category.name, :controller => 'search', :action => 'assets', :asset => 'products', :product_category => product.product_category.id)
90: end
91: content_tag('table',
92: content_tag('tr',
93: content_tag('td', content_tag('div', image_tag(product.image ? product.image.public_filename(:thumb) : '/images/icons-app/product-default-pic-portrait.png'), :class => 'profile-info-picture')) +
94: content_tag('td', content_tag('strong', link_to(product.name, :controller => 'catalog', :profile => product.enterprise.identifier, :action => 'show', :id => product)) + '<br/>' + data)
95: ), :class => 'profile-info')
96: end
# File app/helpers/search_helper.rb, line 50
50: def display_profile_info(profile)
51: data = ''
52: unless profile.contact_email.nil?
53: data << content_tag('strong', _('E-Mail: ')) + profile.contact_email + '<br/>'
54: end
55: unless profile.contact_phone.nil?
56: data << content_tag('strong', _('Phone(s): ')) + profile.contact_phone + '<br/>'
57: end
58: unless profile.region.nil?
59: data << content_tag('strong', _('Location: ')) + profile.region.name + '<br/>'
60: end
61: unless profile.address.nil?
62: data << content_tag('strong', _('Address: ')) + profile.address + '<br/>'
63: end
64: unless profile.products.empty?
65: data << content_tag('strong', _('Products/Services: ')) + profile.products.map{|i| link_to(i.name, :controller => 'catalog', :profile => profile.identifier, :action => 'show', :id => i)}.join(', ') + '<br/>'
66: end
67: if profile.respond_to?(:distance) and !profile.distance.nil?
68: data << content_tag('strong', _('Distance: ')) + "%.2f%" % profile.distance + '<br/>'
69: end
70: content_tag('table',
71: content_tag('tr',
72: content_tag('td', content_tag('div', profile_image(profile, :thumb), :class => 'profile-info-picture')) +
73: content_tag('td', content_tag('strong', link_to(profile.name, url_for(profile.url))) + '<br/>' + data
74: )
75: ),
76: :class => 'profile-info'
77: )
78: end
# File app/helpers/search_helper.rb, line 18
18: def display_results(use_map = true)
19:
20: unless use_map && GoogleMaps.enabled?
21: return render(:partial => 'display_results')
22: end
23:
24: data =
25: if params[:display] == 'map'
26: {
27: :partial => 'google_maps',
28: :toggle => button(:search, _('Display in list'), params.merge(:display => 'list'), :class => "map-toggle-button" ),
29: :class => 'map' ,
30: }
31: else
32: {
33: :partial => 'display_results',
34: :toggle => button(:search, _('Display in map'), params.merge(:display => 'map'), :class => "map-toggle-button" ),
35: :class => 'list' ,
36: }
37: end
38:
39: content_tag('div', data[:toggle] + (render :partial => data[:partial]), :class => "map-or-list-search-results #{data[:class]}")
40: end
# File app/helpers/search_helper.rb, line 98
98: def pagination_links(collection, options={})
99: options = {:prev_label => '« ' + _('Previous'), :next_label => _('Next') + ' »'}.merge(options)
100: will_paginate(collection, options)
101: end
# File app/helpers/search_helper.rb, line 103
103: def product_categories_menu(asset, product_category, object_ids = nil)
104: cats = ProductCategory.menu_categories(@product_category, environment)
105: cats += cats.select { |c| c.children_count > 0 }.map(&:children).flatten
106: product_categories_ids = cats.map(&:id)
107:
108: counts = @finder.product_categories_count(asset, product_categories_ids, object_ids)
109:
110: product_categories_menu = ProductCategory.menu_categories(product_category, environment).map do |cat|
111: hits = counts[cat.id]
112: childs = []
113: if hits
114: if cat.children_count > 0
115: childs = cat.children.map do |child|
116: child_hits = counts[child.id]
117: [child, child_hits]
118: end.select{|child, child_hits| child_hits }
119: else
120: childs = []
121: end
122: end
123: [cat, hits, childs]
124: end.select{|cat, hits| hits }
125:
126: render(:partial => 'product_categories_menu', :object => product_categories_menu)
127: end
# File app/helpers/search_helper.rb, line 8
8: def relevance_for(hit)
9: n = (hit.ferret_score if hit.respond_to?(:ferret_score))
10: n ||= 1.0
11: (n * 100.0).round
12: end