search_helper.rb
2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
module SearchHelper
STOP_WORDS = {
'pt_BR' => Ferret::Analysis::FULL_PORTUGUESE_STOP_WORDS,
'en' => Ferret::Analysis::FULL_ENGLISH_STOP_WORDS,
}
def relevance_for(hit)
n = (hit.ferret_score if hit.respond_to?(:ferret_score))
n ||= 1.0
(n * 100.0).round
end
def remove_stop_words(query)
(query.downcase.scan(/"[^"]*"?|'[^']*'?|[^'"\s]+/) - (STOP_WORDS[locale] || [])).join(' ')
end
def display_results
unless GoogleMaps.enabled?
return render(:partial => 'display_results')
end
data =
if params[:display] == 'map'
{
:partial => 'google_maps',
:toggle => button(:search, _('Display in list'), params.merge(:display => 'list'), :class => "map-toggle-button" ),
:class => 'map' ,
}
else
{
:partial => 'display_results',
:toggle => button(:search, _('Display in map'), params.merge(:display => 'map'), :class => "map-toggle-button" ),
:class => 'list' ,
}
end
content_tag('div', data[:toggle] + (render :partial => data[:partial]), :class => "map-or-list-search-results #{data[:class]}")
end
def display_item_map_info(item)
if item.kind_of?(Profile)
display_profile_info
elsif item.kind_of?(Product)
display_product_info
end
end
def display_profile_info(profile)
data = ''
unless profile.contact_email.nil?
data << content_tag('strong', _('E-Mail: ')) + profile.contact_email + '<br/>'
end
unless profile.contact_phone.nil?
data << content_tag('strong', _('Phone(s): ')) + profile.contact_phone + '<br/>'
end
unless profile.region.nil?
data << content_tag('strong', _('Location: ')) + profile.region.name + '<br/>'
end
unless profile.address.nil?
data << content_tag('strong', _('Address: ')) + profile.address + '<br/>'
end
unless profile.products.empty?
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/>'
end
if profile.respond_to?(:distance) and !profile.distance.nil?
data << content_tag('strong', _('Distance: ')) + "%.2f%" % profile.distance + '<br/>'
end
content_tag('table',
content_tag('tr',
content_tag('td', content_tag('div', profile_image(profile, :thumb), :class => 'profile-info-picture')) +
content_tag('td', content_tag('strong', link_to(profile.name, url_for(profile.url))) + '<br/>' + data
)
),
:class => 'profile-info'
)
end
def pagination_links(collection, options={})
options = {:prev_label => '« ' + _('Previous'), :next_label => _('Next') + ' »'}.merge(options)
will_paginate(collection, options)
end
end