Commit b4d274ac026384670984bf265046549a9d3c39e6
1 parent
6e82bdc7
Exists in
master
and in
29 other branches
[otw] Deicinding whether to keed index or not... =(
Showing
15 changed files
with
52 additions
and
210 deletions
Show diff stats
app/controllers/public/search_controller.rb
... | ... | @@ -4,7 +4,7 @@ class SearchController < PublicController |
4 | 4 | include SearchHelper |
5 | 5 | include ActionView::Helpers::NumberHelper |
6 | 6 | |
7 | - before_filter :redirect_asset_param, :except => [:facets_browse, :assets] | |
7 | + before_filter :redirect_asset_param, :except => :assets | |
8 | 8 | before_filter :load_category |
9 | 9 | before_filter :load_search_assets |
10 | 10 | before_filter :load_query |
... | ... | @@ -18,19 +18,6 @@ class SearchController < PublicController |
18 | 18 | |
19 | 19 | no_design_blocks |
20 | 20 | |
21 | - def facets_browse | |
22 | - @asset = params[:asset].to_sym | |
23 | - @asset_class = asset_class(@asset) | |
24 | - | |
25 | - @facets_only = true | |
26 | - send(@asset) | |
27 | - | |
28 | - @facet = @asset_class.map_facets_for(environment).find { |facet| facet[:id] == params[:facet_id] } | |
29 | - raise 'Facet not found' if @facet.nil? | |
30 | - | |
31 | - render :layout => false | |
32 | - end | |
33 | - | |
34 | 21 | def articles |
35 | 22 | if @search_engine && !@empty_query |
36 | 23 | full_text_search |
... | ... | @@ -54,21 +41,10 @@ class SearchController < PublicController |
54 | 41 | end |
55 | 42 | |
56 | 43 | def products |
57 | - if @search_engine && !@empty_query | |
44 | + if @search_engine | |
58 | 45 | full_text_search |
59 | 46 | else |
60 | - @geosearch = logged_in? && current_user.person.lat && current_user.person.lng | |
61 | - | |
62 | - extra_limit = LIST_SEARCH_LIMIT*5 | |
63 | - sql_options = {:limit => LIST_SEARCH_LIMIT, :order => 'random()'} | |
64 | - if @geosearch | |
65 | - full_text_search :sql_options => sql_options, :extra_limit => extra_limit, | |
66 | - :alternate_query => "{!boost b=recip(geodist(),#{"%e" % (1.to_f/DistBoost)},1,1)}", | |
67 | - :radius => DistFilt, :latitude => current_user.person.lat, :longitude => current_user.person.lng | |
68 | - else | |
69 | - full_text_search :sql_options => sql_options, :extra_limit => extra_limit, | |
70 | - :boost_functions => ['recip(ms(NOW/HOUR,updated_at),1.3e-10,1,1)'] | |
71 | - end | |
47 | + @results[@asset] = @environment.products.send(@filter).paginate(paginate_options) | |
72 | 48 | end |
73 | 49 | render :template => 'search/search_page' |
74 | 50 | end |
... | ... | @@ -120,52 +96,12 @@ class SearchController < PublicController |
120 | 96 | @next_calendar = populate_calendar(date + 1.month, events) |
121 | 97 | end |
122 | 98 | |
123 | - def index | |
124 | - @results = {} | |
125 | - @order = [] | |
126 | - @names = {} | |
127 | - @results_only = true | |
128 | - | |
129 | - @enabled_searches.select { |key,description| @searching[key] }.each do |key, description| | |
130 | - load_query | |
131 | - @asset = key | |
132 | - send(key) | |
133 | - @order << key | |
134 | - @names[key] = getterm(description) | |
135 | - end | |
136 | - @asset = nil | |
137 | - @facets = {} | |
138 | - | |
139 | - render :action => @results.keys.first if @results.keys.size == 1 | |
140 | - end | |
141 | - | |
142 | 99 | # keep old URLs workings |
143 | 100 | def assets |
144 | 101 | params[:action] = params[:asset].is_a?(Array) ? :index : params.delete(:asset) |
145 | 102 | redirect_to params |
146 | 103 | end |
147 | 104 | |
148 | - # view the summary of one category | |
149 | - def category_index | |
150 | - @results = {} | |
151 | - @order = [] | |
152 | - @names = {} | |
153 | - limit = MULTIPLE_SEARCH_LIMIT | |
154 | - [ | |
155 | - [ :people, _('People'), :recent_people ], | |
156 | - [ :enterprises, _('Enterprises'), :recent_enterprises ], | |
157 | - [ :products, _('Products'), :recent_products ], | |
158 | - [ :events, _('Upcoming events'), :upcoming_events ], | |
159 | - [ :communities, _('Communities'), :recent_communities ], | |
160 | - [ :articles, _('Contents'), :recent_articles ] | |
161 | - ].each do |asset, name, filter| | |
162 | - @order << asset | |
163 | - @results[asset] = @category.send(filter, limit) | |
164 | - raise "No total_entries for: #{asset}" unless @results[asset].respond_to?(:total_entries) | |
165 | - @names[asset] = name | |
166 | - end | |
167 | - end | |
168 | - | |
169 | 105 | def tags |
170 | 106 | @tags_cache_key = "tags_env_#{environment.id.to_s}" |
171 | 107 | if is_cache_expired?(@tags_cache_key) |
... | ... | @@ -260,7 +196,7 @@ class SearchController < PublicController |
260 | 196 | @titles = {} |
261 | 197 | @enabled_searches.each do |key, name| |
262 | 198 | @titles[key] = _(name) |
263 | - @searching[key] = params[:action] == 'index' || params[:action] == key.to_s | |
199 | + @searching[key] = params[:action] == key.to_s | |
264 | 200 | end |
265 | 201 | @names = @titles if @names.nil? |
266 | 202 | end | ... | ... |
app/helpers/search_helper.rb
... | ... | @@ -4,8 +4,6 @@ module SearchHelper |
4 | 4 | LIST_SEARCH_LIMIT = 20 |
5 | 5 | BLOCKS_SEARCH_LIMIT = 24 |
6 | 6 | MULTIPLE_SEARCH_LIMIT = 8 |
7 | - DistFilt = 200 | |
8 | - DistBoost = 50 | |
9 | 7 | |
10 | 8 | Searches = ActiveSupport::OrderedHash[ |
11 | 9 | :articles, _('Contents'), |
... | ... | @@ -16,37 +14,11 @@ module SearchHelper |
16 | 14 | :events, _('Events'), |
17 | 15 | ] |
18 | 16 | |
19 | - SortOptions = { | |
20 | - :products => ActiveSupport::OrderedHash[ :none, {:label => _('Relevance')}, | |
21 | - :more_recent, {:label => _('More recent'), :solr_opts => {:sort => 'updated_at desc, score desc'}}, | |
22 | - :name, {:label => _('Name'), :solr_opts => {:sort => 'solr_plugin_name_sortable asc'}}, | |
23 | - :closest, {:label => _('Closest to me'), :if => proc{ logged_in? && (profile=current_user.person).lat && profile.lng }, | |
24 | - :solr_opts => {:sort => "geodist() asc", | |
25 | - :latitude => proc{ current_user.person.lat }, :longitude => proc{ current_user.person.lng }}}, | |
26 | - ], | |
27 | - :events => ActiveSupport::OrderedHash[ :none, {:label => _('Relevance')}, | |
28 | - :name, {:label => _('Name'), :solr_opts => {:sort => 'solr_plugin_name_sortable asc'}}, | |
29 | - ], | |
30 | - :articles => ActiveSupport::OrderedHash[ :none, {:label => _('Relevance')}, | |
31 | - :name, {:label => _('Name'), :solr_opts => {:sort => 'solr_plugin_name_sortable asc'}}, | |
32 | - :more_recent, {:label => _('More recent'), :solr_opts => {:sort => 'updated_at desc, score desc'}}, | |
33 | - ], | |
34 | - :enterprises => ActiveSupport::OrderedHash[ :none, {:label => _('Relevance')}, | |
35 | - :name, {:label => _('Name'), :solr_opts => {:sort => 'solr_plugin_name_sortable asc'}}, | |
36 | - ], | |
37 | - :people => ActiveSupport::OrderedHash[ :none, {:label => _('Relevance')}, | |
38 | - :name, {:label => _('Name'), :solr_opts => {:sort => 'solr_plugin_name_sortable asc'}}, | |
39 | - ], | |
40 | - :communities => ActiveSupport::OrderedHash[ :none, {:label => _('Relevance')}, | |
41 | - :name, {:label => _('Name'), :solr_opts => {:sort => 'solr_plugin_name_sortable asc'}}, | |
42 | - ], | |
43 | - } | |
44 | - | |
45 | 17 | # FIXME remove it after search_controler refactored |
46 | 18 | include EventsHelper |
47 | 19 | |
48 | 20 | def multiple_search? |
49 | - ['index', 'category_index'].include?(params[:action]) or @results.size > 1 | |
21 | + @results.size > 1 | |
50 | 22 | end |
51 | 23 | |
52 | 24 | def map_search? |
... | ... | @@ -95,23 +67,6 @@ module SearchHelper |
95 | 67 | end |
96 | 68 | end |
97 | 69 | |
98 | - def facet_javascript(input_id, facet, array) | |
99 | - array = [] if array.nil? | |
100 | - hintText = _('Type in an option') | |
101 | - text_field_tag('facet['+input_id+']', '', :id => input_id) + | |
102 | - javascript_tag("jQuery.TokenList(jQuery('##{input_id}'), #{array.to_json}, | |
103 | - {searchDelay: 0, permanentDropdown: true, theme: 'facet', dontAdd: true, preventDuplicates: true, | |
104 | - #{jquery_token_input_messages_json(hintText)}});") | |
105 | - end | |
106 | - | |
107 | - def asset_class(asset) | |
108 | - asset.to_s.singularize.camelize.constantize | |
109 | - end | |
110 | - | |
111 | - def asset_table(asset) | |
112 | - asset_class(asset).table_name | |
113 | - end | |
114 | - | |
115 | 70 | def display_filter(asset, display, float = 'right') |
116 | 71 | if map_capable?(asset) |
117 | 72 | list_link = display == 'list' ? _('List') : link_to(_('List'), params.merge(:display => 'list')) | ... | ... |
app/models/article.rb
... | ... | @@ -2,12 +2,6 @@ require 'hpricot' |
2 | 2 | |
3 | 3 | class Article < ActiveRecord::Base |
4 | 4 | |
5 | - # use for internationalizable human type names in search facets | |
6 | - # reimplement on subclasses | |
7 | - def self.type_name | |
8 | - _('Content') | |
9 | - end | |
10 | - | |
11 | 5 | track_actions :create_article, :after_create, :keep_params => [:name, :url, :lead, :first_image], :if => Proc.new { |a| a.is_trackable? && !a.image? } |
12 | 6 | |
13 | 7 | # xss_terminate plugin can't sanitize array fields | ... | ... |
app/models/environment.rb
... | ... | @@ -266,8 +266,6 @@ class Environment < ActiveRecord::Base |
266 | 266 | |
267 | 267 | settings_items :search_hints, :type => Hash, :default => {} |
268 | 268 | |
269 | - settings_items :top_level_category_as_facet_ids, :type => Array, :default => [] | |
270 | - | |
271 | 269 | def news_amount_by_folder=(amount) |
272 | 270 | settings[:news_amount_by_folder] = amount.to_i |
273 | 271 | end | ... | ... |
app/models/profile.rb
... | ... | @@ -3,12 +3,6 @@ |
3 | 3 | # which by default is the one returned by Environment:default. |
4 | 4 | class Profile < ActiveRecord::Base |
5 | 5 | |
6 | - # use for internationalizable human type names in search facets | |
7 | - # reimplement on subclasses | |
8 | - def self.type_name | |
9 | - _('Profile') | |
10 | - end | |
11 | - | |
12 | 6 | module Roles |
13 | 7 | def self.admin(env_id) |
14 | 8 | find_role('admin', env_id) | ... | ... |
app/views/search/_facets_unselect_menu.rhtml
app/views/search/_search_form.rhtml
... | ... | @@ -1,37 +0,0 @@ |
1 | -<div class='search-form'> | |
2 | - | |
3 | - <% form_tag( { :controller => 'search', :action => @asset ? @asset : 'index', :asset => nil, :category_path => ( @category ? @category.explode_path : [] ) }, | |
4 | - :method => 'get', :class => 'search_form' ) do %> | |
5 | - | |
6 | - <%= hidden_field_tag :display, params[:display] %> | |
7 | - | |
8 | - <% params_uri = CGI::unescape(request.request_uri) %> | |
9 | - <% if params_uri.index('?') %> | |
10 | - <% params_uri[(params_uri.index('?')+1)..-1].to_s.split("&").each do |part| %> | |
11 | - <% if part.start_with? "facet" %> | |
12 | - <% name_value = part.split("=") %> | |
13 | - <%= hidden_field_tag name_value[0], name_value[1] %> | |
14 | - <% end %> | |
15 | - <% end %> | |
16 | - <% end %> | |
17 | - | |
18 | - <div class="search-field"> | |
19 | - <span class="formfield"> | |
20 | - <%= text_field_tag 'query', @query, :id => 'search-input', :size => 50 %> | |
21 | - <%= javascript_tag "jQuery('#search-input').attr('title', \"#{hint}\").hint()" if defined?(hint) %> | |
22 | - </span> | |
23 | - | |
24 | - <%= submit_button(:search, _('Search')) %> | |
25 | - </div> | |
26 | - | |
27 | - <% end %> | |
28 | - | |
29 | - <% if @empty_query %> | |
30 | - <% hint = environment.search_hints[@asset] %> | |
31 | - <% if hint and !hint.blank? %> | |
32 | - <div class="search-hint"><%= hint %></div> | |
33 | - <% end %> | |
34 | - <% end %> | |
35 | - | |
36 | - <div style="clear: both"></div> | |
37 | -</div> |
app/views/search/category_index.rhtml
app/views/search/facets_browse.rhtml
... | ... | @@ -1,8 +0,0 @@ |
1 | -<% results = @asset_class.map_facet_results(@facet, params[:facet], @facets, @all_facets) %> | |
2 | - | |
3 | -<% array = [] %> | |
4 | -<% @asset_class.facet_result_sort(@facet, results, :alphabetically).each do |id, label, count| %> | |
5 | - <% array << {:id => id, :name => facet_link_html(@facet, params.merge(:controller => 'search', :action => @asset), id, label, count)} %> | |
6 | -<% end %> | |
7 | - | |
8 | -<%= facet_javascript('facet-input-'+@facet[:id].to_s, @facet, array) %> |
app/views/search/index.rhtml
... | ... | @@ -1,29 +0,0 @@ |
1 | -<div id="search-page" class="<%= "view-category" if @category %>"> | |
2 | - | |
3 | - <% if @category %> | |
4 | - <div id="category-image"><%= image_tag(@category.image.public_filename(:thumb), :id => 'category-image') if @category.image %></div> | |
5 | - <% end %> | |
6 | - | |
7 | - <%= search_page_title(_('Search Results'), @category) %> | |
8 | - <%= render :partial => 'search_form', :locals => { :hint => '' } %> | |
9 | - <%= category_context(@category, params) %> | |
10 | - <%= display_results(@asset) %> | |
11 | - | |
12 | - <div id="category-childs"> | |
13 | - <% if @category %> | |
14 | - <h2> <%= _('Sub-categories') %> </h2> | |
15 | - <% if @category.children.empty? %> | |
16 | - <strong id="cat-no-child"><%= _('No sub-categories') %></strong> | |
17 | - <% else %> | |
18 | - <ul> | |
19 | - <% @category.children.each do |c| %> | |
20 | - <li> <%= link_to_category c, false %> </li> | |
21 | - <% end %> | |
22 | - </ul> | |
23 | - <% end %> | |
24 | - <% end %> | |
25 | - </div> | |
26 | - | |
27 | -</div> | |
28 | - | |
29 | -<div style="clear: both"></div> |
plugins/solr/lib/ext/article.rb
... | ... | @@ -2,6 +2,12 @@ require_dependency 'article' |
2 | 2 | |
3 | 3 | class Article |
4 | 4 | |
5 | + # use for internationalizable human type names in search facets | |
6 | + # reimplement on subclasses | |
7 | + def self.type_name | |
8 | + _('Content') | |
9 | + end | |
10 | + | |
5 | 11 | acts_as_faceted :fields => { |
6 | 12 | :solr_plugin_f_type => {:label => _('Type'), :proc => proc{|klass| solr_plugin_f_type_proc(klass)}}, |
7 | 13 | :solr_plugin_f_published_at => {:type => :date, :label => _('Published date'), :queries => {'[* TO NOW-1YEARS/DAY]' => _("Older than one year"), | ... | ... |
plugins/solr/lib/ext/profile.rb
1 | 1 | require_dependency 'profile' |
2 | 2 | |
3 | 3 | class Profile |
4 | + | |
5 | + # use for internationalizable human type names in search facets | |
6 | + # reimplement on subclasses | |
7 | + def self.type_name | |
8 | + _('Profile') | |
9 | + end | |
10 | + | |
4 | 11 | after_save_reindex [:articles], :with => :delayed_job |
5 | 12 | |
6 | 13 | acts_as_faceted :fields => { |
... | ... | @@ -57,7 +64,7 @@ class Profile |
57 | 64 | private |
58 | 65 | |
59 | 66 | def self.solr_plugin_f_categories_label_proc(environment) |
60 | - ids = environment.top_level_category_as_facet_ids | |
67 | + ids = environment.solr_plugin_top_level_category_as_facet_ids | |
61 | 68 | r = Category.find(ids) |
62 | 69 | map = {} |
63 | 70 | ids.map{ |id| map[id.to_s] = r.detect{|c| c.id == id}.name } | ... | ... |
plugins/solr/lib/solr_plugin.rb
... | ... | @@ -19,6 +19,7 @@ class SolrPlugin < Noosfero::Plugin |
19 | 19 | def full_text_search(asset, query, category, paginate_options) |
20 | 20 | asset_class = asset_class(asset) |
21 | 21 | solr_options = solr_options(asset, category) |
22 | + solr_options.merge!(products_options(context.send(:user))) if asset == :products && empty_query?(query, category) | |
22 | 23 | asset_class.find_by_contents(query, paginate_options, solr_options) |
23 | 24 | end |
24 | 25 | ... | ... |
plugins/solr/lib/solr_plugin/results_helper.rb
... | ... | @@ -109,5 +109,14 @@ class SolrPlugin < Noosfero::Plugin |
109 | 109 | (count > 0 ? content_tag('span', " (#{count})", :class => 'facet-result-count') : ''), |
110 | 110 | :class => 'facet-menu-item' + (selected ? ' facet-result-link-selected' : '') |
111 | 111 | end |
112 | + | |
113 | + def facet_javascript(input_id, facet, array) | |
114 | + array = [] if array.nil? | |
115 | + hintText = _('Type in an option') | |
116 | + text_field_tag('facet['+input_id+']', '', :id => input_id) + | |
117 | + javascript_tag("jQuery.TokenList(jQuery('##{input_id}'), #{array.to_json}, | |
118 | + {searchDelay: 0, permanentDropdown: true, theme: 'facet', dontAdd: true, preventDuplicates: true, | |
119 | + #{jquery_token_input_messages_json(hintText)}});") | |
120 | + end | |
112 | 121 | end |
113 | 122 | end | ... | ... |
plugins/solr/lib/solr_plugin/search_helper.rb
1 | 1 | class SolrPlugin < Noosfero::Plugin |
2 | 2 | |
3 | + LIST_SEARCH_LIMIT = 20 | |
4 | + DistFilt = 200 | |
5 | + DistBoost = 50 | |
6 | + | |
3 | 7 | SortOptions = { |
4 | 8 | :products => ActiveSupport::OrderedHash[ :none, {:label => _('Relevance')}, |
5 | 9 | :more_recent, {:label => _('More recent'), :solr_opts => {:sort => 'updated_at desc, score desc'}}, |
... | ... | @@ -54,6 +58,10 @@ class SolrPlugin < Noosfero::Plugin |
54 | 58 | context.params[:action] == 'index' |
55 | 59 | end |
56 | 60 | |
61 | + def empty_query?(query, category) | |
62 | + category.nil? && query.blank? | |
63 | + end | |
64 | + | |
57 | 65 | def solr_options(asset, category) |
58 | 66 | asset_class = asset_class(asset) |
59 | 67 | solr_options = {} |
... | ... | @@ -79,5 +87,20 @@ class SolrPlugin < Noosfero::Plugin |
79 | 87 | end |
80 | 88 | solr_options |
81 | 89 | end |
90 | + | |
91 | + def products_options(person) | |
92 | + geosearch = person && person.lat && person.lng | |
93 | + | |
94 | + extra_limit = LIST_SEARCH_LIMIT*5 | |
95 | + sql_options = {:limit => LIST_SEARCH_LIMIT, :order => 'random()'} | |
96 | + if geosearch | |
97 | + {:sql_options => sql_options, :extra_limit => extra_limit, | |
98 | + :alternate_query => "{!boost b=recip(geodist(),#{"%e" % (1.to_f/DistBoost)},1,1)}", | |
99 | + :radius => DistFilt, :latitude => person.lat, :longitude => person.lng} | |
100 | + else | |
101 | + { :sql_options => sql_options, :extra_limit => extra_limit, | |
102 | + :boost_functions => ['recip(ms(NOW/HOUR,updated_at),1.3e-10,1,1)']} | |
103 | + end | |
104 | + end | |
82 | 105 | end |
83 | 106 | end | ... | ... |