Commit e8b77683bbc7199c32dacfe7099e79d540d4c3cd
1 parent
c0d3fa26
Exists in
master
and in
29 other branches
Add facets and order by for searches
Showing
13 changed files
with
163 additions
and
15 deletions
Show diff stats
app/models/article.rb
@@ -125,8 +125,6 @@ class Article < ActiveRecord::Base | @@ -125,8 +125,6 @@ class Article < ActiveRecord::Base | ||
125 | 125 | ||
126 | acts_as_versioned | 126 | acts_as_versioned |
127 | 127 | ||
128 | - acts_as_searchable :additional_fields => [ :comment_data ] | ||
129 | - | ||
130 | def comment_data | 128 | def comment_data |
131 | comments.map {|item| [item.title, item.body].join(' ') }.join(' ') | 129 | comments.map {|item| [item.title, item.body].join(' ') }.join(' ') |
132 | end | 130 | end |
@@ -560,6 +558,32 @@ class Article < ActiveRecord::Base | @@ -560,6 +558,32 @@ class Article < ActiveRecord::Base | ||
560 | end | 558 | end |
561 | 559 | ||
562 | private | 560 | private |
561 | + def f_type | ||
562 | + self.class.to_s | ||
563 | + end | ||
564 | + def f_publish_date | ||
565 | + self.published_at | ||
566 | + end | ||
567 | + def f_profile_type | ||
568 | + self.profile.class.to_s | ||
569 | + end | ||
570 | + def f_category | ||
571 | + self.categories.collect(&:name) | ||
572 | + end | ||
573 | + public | ||
574 | + | ||
575 | + acts_as_faceted :fields => { | ||
576 | + :f_type => {:label => _('Type')}, | ||
577 | + :f_publish_date => {:label => _('Published')}, | ||
578 | + :f_profile_type => {:label => _('Type of profile')}, | ||
579 | + :f_category => {:label => _('Categories')}}, | ||
580 | + :order => [:f_type, :f_publish_date, :f_profile_type, :f_category] | ||
581 | + | ||
582 | + acts_as_searchable :additional_fields => [ :comment_data, {:name => {:type => :string, :as => :name_sort, :boost => 5.0}} ] + facets.keys.map{|i| {i => :facet}}, | ||
583 | + :include => [:profile], | ||
584 | + :facets => facets.keys | ||
585 | + | ||
586 | + private | ||
563 | 587 | ||
564 | def sanitize_tag_list | 588 | def sanitize_tag_list |
565 | sanitizer = HTML::FullSanitizer.new | 589 | sanitizer = HTML::FullSanitizer.new |
app/models/category.rb
@@ -64,6 +64,10 @@ class Category < ActiveRecord::Base | @@ -64,6 +64,10 @@ class Category < ActiveRecord::Base | ||
64 | results | 64 | results |
65 | end | 65 | end |
66 | 66 | ||
67 | + def root_parent | ||
68 | + parent_id.nil? ? self : Category.find_by_id(parent_id).root_parent | ||
69 | + end | ||
70 | + | ||
67 | def is_leaf_displayable_in_menu? | 71 | def is_leaf_displayable_in_menu? |
68 | return false if self.display_in_menu == false | 72 | return false if self.display_in_menu == false |
69 | self.children.find(:all, :conditions => {:display_in_menu => true}).empty? | 73 | self.children.find(:all, :conditions => {:display_in_menu => true}).empty? |
app/models/community.rb
@@ -79,4 +79,25 @@ class Community < Organization | @@ -79,4 +79,25 @@ class Community < Organization | ||
79 | {:title => __('Community Info and settings'), :icon => 'edit-profile-group'} | 79 | {:title => __('Community Info and settings'), :icon => 'edit-profile-group'} |
80 | end | 80 | end |
81 | 81 | ||
82 | + private | ||
83 | + def f_territory | ||
84 | + categories.find(:all, :conditions => {:parent_id => 5}).collect(&:name) | ||
85 | + end | ||
86 | + def f_topic | ||
87 | + categories.find(:all, :conditions => {:parent_id => 1}).collect(&:name) | ||
88 | + end | ||
89 | + def f_network | ||
90 | + categories.find(:all, :conditions => {:parent_id => 9}).collect(&:name) | ||
91 | + end | ||
92 | + public | ||
93 | + | ||
94 | + acts_as_faceted :fields => { | ||
95 | + :f_territory => {:label => _('Territories')}, | ||
96 | + :f_topic => {:label => _('Thematics')}, | ||
97 | + :f_network => {:label => _('Networks')}}, | ||
98 | + :order => [:f_territory, :f_topic, :f_network] | ||
99 | + | ||
100 | + acts_as_searchable :additional_fields => [ :extra_data_for_index, {:name => {:type => :string, :as => :name_sort, :boost => 5.0}} ] + facets.keys.map{|i| {i => :facet}}, | ||
101 | + :facets => facets.keys | ||
102 | + | ||
82 | end | 103 | end |
app/models/enterprise.rb
@@ -164,6 +164,27 @@ class Enterprise < Organization | @@ -164,6 +164,27 @@ class Enterprise < Organization | ||
164 | 164 | ||
165 | settings_items :enable_contact_us, :type => :boolean, :default => true | 165 | settings_items :enable_contact_us, :type => :boolean, :default => true |
166 | 166 | ||
167 | + private | ||
168 | + def f_territory | ||
169 | + categories.find(:all, :conditions => {:parent_id => 5}).collect(&:name) | ||
170 | + end | ||
171 | + def f_topic | ||
172 | + categories.find(:all, :conditions => {:parent_id => 1}).collect(&:name) | ||
173 | + end | ||
174 | + def f_network | ||
175 | + categories.find(:all, :conditions => {:parent_id => 9}).collect(&:name) | ||
176 | + end | ||
177 | + public | ||
178 | + | ||
179 | + acts_as_faceted :fields => { | ||
180 | + :f_territory => {:label => _('Territories')}, | ||
181 | + :f_topic => {:label => _('Thematics')}, | ||
182 | + :f_network => {:label => _('Networks')}}, | ||
183 | + :order => [:f_territory, :f_topic, :f_network] | ||
184 | + | ||
185 | + acts_as_searchable :additional_fields => [ :extra_data_for_index, {:name => {:type => :string, :as => :name_sort, :boost => 5.0}} ] + facets.keys.map{|i| {i => :facet}}, | ||
186 | + :facets => facets.keys | ||
187 | + | ||
167 | def enable_contact? | 188 | def enable_contact? |
168 | enable_contact_us | 189 | enable_contact_us |
169 | end | 190 | end |
app/models/environment.rb
@@ -353,11 +353,11 @@ class Environment < ActiveRecord::Base | @@ -353,11 +353,11 @@ class Environment < ActiveRecord::Base | ||
353 | end | 353 | end |
354 | 354 | ||
355 | def terminology | 355 | def terminology |
356 | - if self.settings[:terminology] | ||
357 | - self.settings[:terminology].constantize.instance | ||
358 | - else | 356 | + #if self.settings[:terminology] |
357 | + #self.settings[:terminology].constantize.instance | ||
358 | + #else | ||
359 | Noosfero.terminology | 359 | Noosfero.terminology |
360 | - end | 360 | + #end |
361 | end | 361 | end |
362 | 362 | ||
363 | def terminology=(value) | 363 | def terminology=(value) |
app/models/person.rb
@@ -414,6 +414,27 @@ class Person < Profile | @@ -414,6 +414,27 @@ class Person < Profile | ||
414 | user.save! | 414 | user.save! |
415 | end | 415 | end |
416 | 416 | ||
417 | + private | ||
418 | + def f_territory | ||
419 | + categories.find(:all, :conditions => {:parent_id => 5}).collect(&:name) | ||
420 | + end | ||
421 | + def f_topic | ||
422 | + categories.find(:all, :conditions => {:parent_id => 1}).collect(&:name) | ||
423 | + end | ||
424 | + def f_network | ||
425 | + categories.find(:all, :conditions => {:parent_id => 9}).collect(&:name) | ||
426 | + end | ||
427 | + public | ||
428 | + | ||
429 | + acts_as_faceted :fields => { | ||
430 | + :f_territory => {:label => _('Territories')}, | ||
431 | + :f_topic => {:label => _('Thematics')}, | ||
432 | + :f_network => {:label => _('Networks')}}, | ||
433 | + :order => [:f_territory, :f_topic, :f_network] | ||
434 | + | ||
435 | + acts_as_searchable :additional_fields => [ :extra_data_for_index, {:name => {:type => :string, :as => :name_sort, :boost => 5.0}} ] + facets.keys.map{|i| {i => :facet}}, | ||
436 | + :facets => facets.keys | ||
437 | + | ||
417 | protected | 438 | protected |
418 | 439 | ||
419 | def followed_by?(profile) | 440 | def followed_by?(profile) |
app/models/profile.rb
@@ -70,8 +70,6 @@ class Profile < ActiveRecord::Base | @@ -70,8 +70,6 @@ class Profile < ActiveRecord::Base | ||
70 | 70 | ||
71 | acts_as_having_boxes | 71 | acts_as_having_boxes |
72 | 72 | ||
73 | - acts_as_searchable :additional_fields => [ :extra_data_for_index ] | ||
74 | - | ||
75 | acts_as_taggable | 73 | acts_as_taggable |
76 | 74 | ||
77 | def self.qualified_column_names | 75 | def self.qualified_column_names |
@@ -177,6 +175,15 @@ class Profile < ActiveRecord::Base | @@ -177,6 +175,15 @@ class Profile < ActiveRecord::Base | ||
177 | 175 | ||
178 | has_many :abuse_complaints, :foreign_key => 'requestor_id' | 176 | has_many :abuse_complaints, :foreign_key => 'requestor_id' |
179 | 177 | ||
178 | + def top_level_categorization | ||
179 | + ret = {} | ||
180 | + self.profile_categorizations.each do |c| | ||
181 | + p = c.category.root_parent | ||
182 | + ret[p] = (ret[p] || []) + [c.category] | ||
183 | + end | ||
184 | + ret | ||
185 | + end | ||
186 | + | ||
180 | def interests | 187 | def interests |
181 | categories.select {|item| !item.is_a?(Region)} | 188 | categories.select {|item| !item.is_a?(Region)} |
182 | end | 189 | end |
app/views/search/_article.rhtml
1 | -<li class="<%= icon_for_article(article) %>"> | ||
2 | - <strong><%= link_to(article.title, article.view_url) %></strong> | ||
3 | - <div class="item_meta"> | 1 | +<li class="article-item <%= icon_for_article(article) %>"> |
2 | + <strong><%= link_to(article.title, article.url) %></strong> | ||
3 | + <div class="article-item-meta"> | ||
4 | + <% if article.body %> | ||
5 | + <% body_stripped = strip_tags(article.body.to_s) %> | ||
6 | + <br /><span class="article-item-body"><%= excerpt(body_stripped, body_stripped.first(3), 300) %></span><br /> | ||
7 | + <% end %> | ||
8 | + | ||
9 | + <br /><span><%= _('Tags: ') + article.tags.join(', ') if !article.tags.empty? %></span> | ||
10 | + | ||
11 | + <br /><span><%=_('Author: ') %><%= link_to(article.profile.name, profile_path(:profile => article.profile)) %></span> | ||
12 | + | ||
13 | + <br /> | ||
4 | <% if article.last_changed_by %> | 14 | <% if article.last_changed_by %> |
5 | - <span class="cat_item_by"> | ||
6 | - <%= _('by %s') % link_to(article.last_changed_by.name, article.last_changed_by.url) %> | ||
7 | - </span> | 15 | + <span class="cat_item_by"><%= _('by %s') % link_to(article.last_changed_by.name, article.last_changed_by.url) %></span> |
8 | <% end %> | 16 | <% end %> |
9 | <span class="cat_item_update"><%= _('Last update: %s.') % show_date(article.updated_at) %></span> | 17 | <span class="cat_item_update"><%= _('Last update: %s.') % show_date(article.updated_at) %></span> |
18 | + | ||
19 | + <br /> | ||
10 | </div> | 20 | </div> |
11 | </li> | 21 | </li> |
@@ -0,0 +1,17 @@ | @@ -0,0 +1,17 @@ | ||
1 | +<% if params[:query].blank? %> | ||
2 | + <%= profile_image_link enterprise, :portrait %> | ||
3 | +<% else %> | ||
4 | + <div class="enterprise-result"> | ||
5 | + <%= profile_image_link enterprise, :portrait %> | ||
6 | + <span><%= enterprise.name %></span> | ||
7 | + <span><%= _("Region: ") + enterprise.region.name if enterprise.region %></span> | ||
8 | + <span><%= enterprise.description %></span> | ||
9 | + | ||
10 | + <div class="enterprise-categorization"> | ||
11 | + <% enterprise.top_level_categorization.each do |parent, children| %> | ||
12 | + <span class="enterprise-categorization-parent"><%= parent.name + ':' %></span> | ||
13 | + <span class="enterprise-categorization-children"><%= children.collect(&:name).join(', ') %></span> | ||
14 | + <% end %> | ||
15 | + </div> | ||
16 | + </div> | ||
17 | +<% end %> |
app/views/search/articles.rhtml
@@ -9,6 +9,12 @@ | @@ -9,6 +9,12 @@ | ||
9 | 9 | ||
10 | <%= render :partial => 'search_form', :locals => { :form_title => @query.blank? ? _('Search') : _("Refine your search"), :simple_search => true } %> | 10 | <%= render :partial => 'search_form', :locals => { :form_title => @query.blank? ? _('Search') : _("Refine your search"), :simple_search => true } %> |
11 | 11 | ||
12 | +<% if !@query.blank? %> | ||
13 | + <%= facets_menu(:articles, @facets[:articles]) %> | ||
14 | +<% end %> | ||
15 | + | ||
16 | +<%= render :partial => 'results_header', :locals => { :asset => :articles, :results => @results[:articles] } %> | ||
17 | + | ||
12 | <%# FIXME ARMENGUE %> | 18 | <%# FIXME ARMENGUE %> |
13 | <%= display_results(false) %> | 19 | <%= display_results(false) %> |
14 | 20 |
app/views/search/communities.rhtml
@@ -15,6 +15,11 @@ | @@ -15,6 +15,11 @@ | ||
15 | <% end %> | 15 | <% end %> |
16 | <% end %> | 16 | <% end %> |
17 | 17 | ||
18 | +<% if !@query.blank? %> | ||
19 | + <%= facets_menu(:communities, @facets[:communities]) %> | ||
20 | +<% end %> | ||
21 | +<%= render :partial => 'results_header', :locals => { :asset => :communities, :results => @results[:communities] } %> | ||
22 | + | ||
18 | <div id='search-results-and-pages'> | 23 | <div id='search-results-and-pages'> |
19 | <%# FIXME ARMENGUE %> | 24 | <%# FIXME ARMENGUE %> |
20 | <%= display_results(false) %> | 25 | <%= display_results(false) %> |
app/views/search/enterprises.rhtml
@@ -26,9 +26,15 @@ | @@ -26,9 +26,15 @@ | ||
26 | <% end %> | 26 | <% end %> |
27 | 27 | ||
28 | <% cache(:action => 'assets', :asset => 'enterprises', :category_path => params[:category_path], :query => @query, :product_category => @product_category, :region => @region, :radius => params[:radius]) do %> | 28 | <% cache(:action => 'assets', :asset => 'enterprises', :category_path => params[:category_path], :query => @query, :product_category => @product_category, :region => @region, :radius => params[:radius]) do %> |
29 | - <%= product_categories_menu(:enterprises, @product_category, @result_ids) %> | 29 | + <% if @query.blank? %> |
30 | + <%= product_categories_menu(:enterprises, @product_category, @result_ids) %> | ||
31 | + <% else %> | ||
32 | + <%= facets_menu(:enterprises, @facets[:enterprises]) %> | ||
33 | + <% end %> | ||
30 | <% end %> | 34 | <% end %> |
31 | 35 | ||
36 | +<%= render :partial => 'results_header', :locals => { :asset => :enterprises, :results => @results[:enterprises] } %> | ||
37 | + | ||
32 | <%= display_results %> | 38 | <%= display_results %> |
33 | 39 | ||
34 | <% if @categories_menu %> | 40 | <% if @categories_menu %> |
app/views/search/people.rhtml
@@ -9,6 +9,12 @@ | @@ -9,6 +9,12 @@ | ||
9 | 9 | ||
10 | <%= render :partial => 'search_form', :locals => { :form_title => @query.blank? ? _('Search') : _("Refine your search"), :simple_search => true } %> | 10 | <%= render :partial => 'search_form', :locals => { :form_title => @query.blank? ? _('Search') : _("Refine your search"), :simple_search => true } %> |
11 | 11 | ||
12 | +<% if !@query.blank? %> | ||
13 | + <%= facets_menu(:people, @facets[:people]) %> | ||
14 | +<% end %> | ||
15 | + | ||
16 | +<%= render :partial => 'results_header', :locals => { :asset => :people, :results => @results[:people] } %> | ||
17 | + | ||
12 | <%# FIXME ARMENGUE %> | 18 | <%# FIXME ARMENGUE %> |
13 | <%= display_results(false) %> | 19 | <%= display_results(false) %> |
14 | 20 |