search_helper.rb
4.4 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
module SearchHelper
MAP_SEARCH_LIMIT = 2000
LIST_SEARCH_LIMIT = 20
BLOCKS_SEARCH_LIMIT = 24
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'}},
:name, {:label => _('Name'), :solr_opts => {:sort => 'solr_plugin_name_sortable asc'}},
:closest, {:label => _('Closest to me'), :if => proc{ logged_in? && (profile=current_user.person).lat && profile.lng },
:solr_opts => {:sort => "geodist() asc",
:latitude => proc{ current_user.person.lat }, :longitude => proc{ current_user.person.lng }}},
],
:events => ActiveSupport::OrderedHash[ :none, {:label => _('Relevance')},
:name, {:label => _('Name'), :solr_opts => {:sort => 'solr_plugin_name_sortable asc'}},
],
:articles => ActiveSupport::OrderedHash[ :none, {:label => _('Relevance')},
:name, {:label => _('Name'), :solr_opts => {:sort => 'solr_plugin_name_sortable asc'}},
:more_recent, {:label => _('More recent'), :solr_opts => {:sort => 'updated_at desc, score desc'}},
],
:enterprises => ActiveSupport::OrderedHash[ :none, {:label => _('Relevance')},
:name, {:label => _('Name'), :solr_opts => {:sort => 'solr_plugin_name_sortable asc'}},
],
:people => ActiveSupport::OrderedHash[ :none, {:label => _('Relevance')},
:name, {:label => _('Name'), :solr_opts => {:sort => 'solr_plugin_name_sortable asc'}},
],
:communities => ActiveSupport::OrderedHash[ :none, {:label => _('Relevance')},
:name, {:label => _('Name'), :solr_opts => {:sort => 'solr_plugin_name_sortable asc'}},
],
}
# FIXME remove it after search_controler refactored
include EventsHelper
def multiple_search?
['index', 'category_index'].include?(params[:action]) or @results.size > 1
end
def map_search?
!multiple_search? and params[:display] == 'map'
end
def search_page_title(title, category = nil)
title = "<h1>" + title
title += '<small>' + category.name + '</small>' if category
title + "</h1>"
end
def category_context(category, url)
content_tag('div', category.full_name + _(', ') +
link_to(_('search in all categories'),
url.merge(:category_path => [], :action => (params[:action] == 'category_index' ? 'index' : params[:action]) )),
:align => 'center', :class => 'search-category-context') if category
end
def map_capable?(asset)
[:enterprises, :products].include?(asset)
end
def display_results(asset)
if map_capable?(asset) and map_search?
partial = 'google_maps'
klass = 'map'
else
partial = 'display_results'
klass = 'list'
end
content_tag('div', render(:partial => partial), :class => "map-or-list-search-results #{klass}")
end
def city_with_state(city)
if city and city.kind_of?(City)
s = city.parent
if s and s.kind_of?(State) and s.acronym
city.name + ', ' + s.acronym
else
city.name
end
else
nil
end
end
def facet_javascript(input_id, facet, array)
array = [] if array.nil?
hintText = _('Type in an option')
text_field_tag('facet['+input_id+']', '', :id => input_id) +
javascript_tag("jQuery.TokenList(jQuery('##{input_id}'), #{array.to_json},
{searchDelay: 0, permanentDropdown: true, theme: 'facet', dontAdd: true, preventDuplicates: true,
#{jquery_token_input_messages_json(hintText)}});")
end
def asset_class(asset)
asset.to_s.singularize.camelize.constantize
end
def asset_table(asset)
asset_class(asset).table_name
end
def display_filter(asset, display, float = 'right')
if map_capable?(asset)
list_link = display == 'list' ? _('List') : link_to(_('List'), params.merge(:display => 'list'))
map_link = display == 'map' ? _('Map') : link_to(_('Map'), params.merge(:display => 'map'))
content_tag('div',
content_tag('strong', _('Display')) + ': ' +
list_link +
' | ' +
map_link,
:id => 'search-display-filter',
:style => "float: #{float}"
)
end
end
end