Commit 577cdbee9d8db17ae5c7a3c97a65cd241716b2d8
1 parent
101926f1
Exists in
master
and in
28 other branches
Fix visibilty problems with full-text search
Showing
3 changed files
with
25 additions
and
29 deletions
Show diff stats
app/controllers/public/search_controller.rb
| @@ -32,7 +32,7 @@ class SearchController < PublicController | @@ -32,7 +32,7 @@ class SearchController < PublicController | ||
| 32 | @filter = params[:filter] ? filter : nil | 32 | @filter = params[:filter] ? filter : nil |
| 33 | @filter_title = params[:filter] ? filter_description(@asset, @filter) : nil | 33 | @filter_title = params[:filter] ? filter_description(@asset, @filter) : nil |
| 34 | if !@empty_query | 34 | if !@empty_query |
| 35 | - full_text_search | 35 | + full_text_search ['public:true'] |
| 36 | elsif params[:filter] | 36 | elsif params[:filter] |
| 37 | @results[@asset] = @environment.articles.more_recent.paginate(paginate_options) | 37 | @results[@asset] = @environment.articles.more_recent.paginate(paginate_options) |
| 38 | end | 38 | end |
| @@ -44,7 +44,7 @@ class SearchController < PublicController | @@ -44,7 +44,7 @@ class SearchController < PublicController | ||
| 44 | 44 | ||
| 45 | def people | 45 | def people |
| 46 | if !@empty_query | 46 | if !@empty_query |
| 47 | - full_text_search | 47 | + full_text_search ['visible:true'] |
| 48 | else | 48 | else |
| 49 | @results[@asset] = @environment.people.visible.send(@filter).paginate(paginate_options) | 49 | @results[@asset] = @environment.people.visible.send(@filter).paginate(paginate_options) |
| 50 | @facets = {} | 50 | @facets = {} |
| @@ -53,22 +53,22 @@ class SearchController < PublicController | @@ -53,22 +53,22 @@ class SearchController < PublicController | ||
| 53 | 53 | ||
| 54 | def products | 54 | def products |
| 55 | if !@empty_query | 55 | if !@empty_query |
| 56 | - full_text_search | 56 | + full_text_search ['visible:true'] |
| 57 | end | 57 | end |
| 58 | end | 58 | end |
| 59 | 59 | ||
| 60 | def enterprises | 60 | def enterprises |
| 61 | if !@empty_query | 61 | if !@empty_query |
| 62 | - full_text_search | 62 | + full_text_search ['visible:true'] |
| 63 | else | 63 | else |
| 64 | @filter_title = _('Enterprises from network') | 64 | @filter_title = _('Enterprises from network') |
| 65 | - @results[@asset] = asset_class(@asset).paginate(paginate_options) | 65 | + @results[@asset] = @environment.enterprises.visible.paginate(paginate_options) |
| 66 | end | 66 | end |
| 67 | end | 67 | end |
| 68 | 68 | ||
| 69 | def communities | 69 | def communities |
| 70 | if !@empty_query | 70 | if !@empty_query |
| 71 | - full_text_search | 71 | + full_text_search ['visible:true'] |
| 72 | else | 72 | else |
| 73 | @results[@asset] = @environment.communities.visible.send(@filter).paginate(paginate_options) | 73 | @results[@asset] = @environment.communities.visible.send(@filter).paginate(paginate_options) |
| 74 | end | 74 | end |
| @@ -277,31 +277,25 @@ class SearchController < PublicController | @@ -277,31 +277,25 @@ class SearchController < PublicController | ||
| 277 | { :per_page => limit, :page => page } | 277 | { :per_page => limit, :page => page } |
| 278 | end | 278 | end |
| 279 | 279 | ||
| 280 | - def full_text_search(paginate_options = nil) | ||
| 281 | - paginate_options ||= paginate_options(params[:page]) | ||
| 282 | - solr_options = solr_options(@asset, params[:facet], params[:order_by]) | 280 | + def full_text_search(filters = []) |
| 281 | + paginate_options = paginate_options(params[:page]) | ||
| 282 | + asset_class = asset_class(@asset) | ||
| 283 | 283 | ||
| 284 | - ret = asset_class(@asset).find_by_contents(@query, paginate_options, solr_options) | ||
| 285 | - @results[@asset] = ret[:results] | ||
| 286 | - @facets = ret[:facets] | ||
| 287 | - @all_facets = ret[:all_facets] | ||
| 288 | - end | ||
| 289 | - | ||
| 290 | - def solr_options(asset, facets_selected, solr_order = nil) | ||
| 291 | - result = {} | ||
| 292 | - | ||
| 293 | - asset_class = asset_class(asset) | 284 | + solr_options = {} |
| 294 | if !@results_only and asset_class.methods.include?('facets') | 285 | if !@results_only and asset_class.methods.include?('facets') |
| 295 | - result.merge! asset_class.facets_find_options(facets_selected) | ||
| 296 | - result[:all_facets] = true | ||
| 297 | - result[:limit] = 0 if @facets_only | ||
| 298 | - result[:facets][:browse] << asset_class.facet_category_query.call(@category) if @category | ||
| 299 | - puts result[:facets][:browse] | 286 | + solr_options.merge! asset_class.facets_find_options(params[:facet]) |
| 287 | + solr_options[:all_facets] = true | ||
| 288 | + solr_options[:limit] = 0 if @facets_only | ||
| 289 | + solr_options[:facets][:browse] << asset_class.facet_category_query.call(@category) if @category and asset_class.facet_category_query | ||
| 300 | end | 290 | end |
| 291 | + solr_options[:order] = params[:order_by] if params[:order_by] | ||
| 292 | + solr_options[:filter_queries] ||= [] | ||
| 293 | + solr_options[:filter_queries] += filters | ||
| 301 | 294 | ||
| 302 | - result[:order] = solr_order if solr_order | ||
| 303 | - | ||
| 304 | - result | 295 | + ret = asset_class.find_by_contents(@query, paginate_options, solr_options) |
| 296 | + @results[@asset] = ret[:results] | ||
| 297 | + @facets = ret[:facets] | ||
| 298 | + @all_facets = ret[:all_facets] | ||
| 305 | end | 299 | end |
| 306 | 300 | ||
| 307 | end | 301 | end |
app/models/article.rb
| @@ -624,6 +624,9 @@ class Article < ActiveRecord::Base | @@ -624,6 +624,9 @@ class Article < ActiveRecord::Base | ||
| 624 | def name_sort | 624 | def name_sort |
| 625 | name | 625 | name |
| 626 | end | 626 | end |
| 627 | + def public | ||
| 628 | + self.public? | ||
| 629 | + end | ||
| 627 | public | 630 | public |
| 628 | 631 | ||
| 629 | acts_as_faceted :fields => { | 632 | acts_as_faceted :fields => { |
| @@ -636,7 +639,7 @@ class Article < ActiveRecord::Base | @@ -636,7 +639,7 @@ class Article < ActiveRecord::Base | ||
| 636 | :category_query => proc { |c| "f_category:\"#{c.name}\"" }, | 639 | :category_query => proc { |c| "f_category:\"#{c.name}\"" }, |
| 637 | :order => [:f_type, :f_published_at, :f_profile_type, :f_category] | 640 | :order => [:f_type, :f_published_at, :f_profile_type, :f_category] |
| 638 | 641 | ||
| 639 | - acts_as_searchable :additional_fields => [ {:name => {:type => :string}} ] + facets_fields_for_solr, | 642 | + acts_as_searchable :additional_fields => [ {:name => {:type => :string}}, {:public => {:type => :boolean}}] + facets_fields_for_solr, |
| 640 | :exclude_fields => [:setting], | 643 | :exclude_fields => [:setting], |
| 641 | :include => [:profile], | 644 | :include => [:profile], |
| 642 | :facets => facets_option_for_solr, | 645 | :facets => facets_option_for_solr, |
app/views/search/_display_results.rhtml
| @@ -16,7 +16,6 @@ | @@ -16,7 +16,6 @@ | ||
| 16 | <div class="search-results-innerbox2"><!-- the innerbox2 is a workarround for MSIE --> | 16 | <div class="search-results-innerbox2"><!-- the innerbox2 is a workarround for MSIE --> |
| 17 | <ul> | 17 | <ul> |
| 18 | <% results.each do |hit| %> | 18 | <% results.each do |hit| %> |
| 19 | - <% next if hit.respond_to?(:visible) && !hit.visible? %> | ||
| 20 | <%= render :partial => partial_for_class(hit.class), :object => hit %> | 19 | <%= render :partial => partial_for_class(hit.class), :object => hit %> |
| 21 | <% end %> | 20 | <% end %> |
| 22 | </ul> | 21 | </ul> |