Commit f132c4e1e7ff3d1af95ef7584af643ff321ba6dc
Exists in
master
and in
28 other branches
Merge branch 'ai3157' into 'stable'
Fix search of STI subclasses http://noosfero.org/Development/ActionItem3157
Showing
9 changed files
with
24 additions
and
7 deletions
Show diff stats
plugins/solr/lib/ext/article.rb
@@ -40,6 +40,7 @@ class Article | @@ -40,6 +40,7 @@ class Article | ||
40 | :if => proc{ |a| ! ['RssFeed'].include?(a.class.name) } | 40 | :if => proc{ |a| ! ['RssFeed'].include?(a.class.name) } |
41 | 41 | ||
42 | handle_asynchronously :solr_save | 42 | handle_asynchronously :solr_save |
43 | + handle_asynchronously :solr_destroy | ||
43 | 44 | ||
44 | def solr_plugin_comments_updated | 45 | def solr_plugin_comments_updated |
45 | solr_save | 46 | solr_save |
plugins/solr/lib/ext/category.rb
plugins/solr/lib/ext/facets_browse.rb
plugins/solr/lib/ext/product.rb
@@ -43,6 +43,7 @@ class Product | @@ -43,6 +43,7 @@ class Product | ||
43 | :boost => proc{ |p| boost = 1; SolrPlugin::Boosts.each{ |b| boost = boost * (1 - ((1 - b[2].call(p)) * b[1])) }; boost} | 43 | :boost => proc{ |p| boost = 1; SolrPlugin::Boosts.each{ |b| boost = boost * (1 - ((1 - b[2].call(p)) * b[1])) }; boost} |
44 | 44 | ||
45 | handle_asynchronously :solr_save | 45 | handle_asynchronously :solr_save |
46 | + handle_asynchronously :solr_destroy | ||
46 | 47 | ||
47 | private | 48 | private |
48 | 49 |
plugins/solr/lib/ext/profile.rb
@@ -14,10 +14,11 @@ class Profile | @@ -14,10 +14,11 @@ class Profile | ||
14 | :solr_plugin_f_enabled => {:label => _('Situation'), :type_if => proc { |klass| klass.kind_of?(Enterprise) }, | 14 | :solr_plugin_f_enabled => {:label => _('Situation'), :type_if => proc { |klass| klass.kind_of?(Enterprise) }, |
15 | :proc => proc { |id| solr_plugin_f_enabled_proc(id) }}, | 15 | :proc => proc { |id| solr_plugin_f_enabled_proc(id) }}, |
16 | :solr_plugin_f_region => {:label => _('City'), :proc => proc { |id| solr_plugin_f_region_proc(id) }}, | 16 | :solr_plugin_f_region => {:label => _('City'), :proc => proc { |id| solr_plugin_f_region_proc(id) }}, |
17 | + :solr_plugin_f_profile_type => {:label => _('Type'), :proc => proc{|klass| solr_plugin_f_profile_type_proc(klass)}}, | ||
17 | :solr_plugin_f_categories => {:multi => true, :proc => proc {|facet, id| solr_plugin_f_categories_proc(facet, id)}, | 18 | :solr_plugin_f_categories => {:multi => true, :proc => proc {|facet, id| solr_plugin_f_categories_proc(facet, id)}, |
18 | :label => proc { |env| solr_plugin_f_categories_label_proc(env) }, :label_abbrev => proc{ |env| solr_plugin_f_categories_label_abbrev_proc(env) }}, | 19 | :label => proc { |env| solr_plugin_f_categories_label_proc(env) }, :label_abbrev => proc{ |env| solr_plugin_f_categories_label_abbrev_proc(env) }}, |
19 | }, :category_query => proc { |c| "solr_plugin_category_filter:#{c.id}" }, | 20 | }, :category_query => proc { |c| "solr_plugin_category_filter:#{c.id}" }, |
20 | - :order => [:solr_plugin_f_region, :solr_plugin_f_categories, :solr_plugin_f_enabled] | 21 | + :order => [:solr_plugin_f_region, :solr_plugin_f_categories, :solr_plugin_f_enabled, :solr_plugin_f_profile_type] |
21 | 22 | ||
22 | acts_as_searchable :fields => facets_fields_for_solr + [:solr_plugin_extra_data_for_index, | 23 | acts_as_searchable :fields => facets_fields_for_solr + [:solr_plugin_extra_data_for_index, |
23 | # searched fields | 24 | # searched fields |
@@ -39,6 +40,7 @@ class Profile | @@ -39,6 +40,7 @@ class Profile | ||
39 | :boost => proc{ |p| 10 if p.enabled } | 40 | :boost => proc{ |p| 10 if p.enabled } |
40 | 41 | ||
41 | handle_asynchronously :solr_save | 42 | handle_asynchronously :solr_save |
43 | + handle_asynchronously :solr_destroy | ||
42 | 44 | ||
43 | class_inheritable_accessor :solr_plugin_extra_index_methods | 45 | class_inheritable_accessor :solr_plugin_extra_index_methods |
44 | self.solr_plugin_extra_index_methods = [] | 46 | self.solr_plugin_extra_index_methods = [] |
@@ -116,4 +118,13 @@ class Profile | @@ -116,4 +118,13 @@ class Profile | ||
116 | def solr_plugin_name_sortable | 118 | def solr_plugin_name_sortable |
117 | name | 119 | name |
118 | end | 120 | end |
121 | + | ||
122 | + def solr_plugin_f_profile_type | ||
123 | + self.class.name | ||
124 | + end | ||
125 | + | ||
126 | + def self.solr_plugin_f_profile_type_proc klass | ||
127 | + klass.constantize.type_name | ||
128 | + end | ||
129 | + | ||
119 | end | 130 | end |
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/class_methods.rb
@@ -273,7 +273,8 @@ module ActsAsSolr #:nodoc: | @@ -273,7 +273,8 @@ module ActsAsSolr #:nodoc: | ||
273 | end | 273 | end |
274 | 274 | ||
275 | if items_processed > 0 | 275 | if items_processed > 0 |
276 | - solr_optimize | 276 | + # FIXME: not recommended, reenable with option |
277 | + #solr_optimize | ||
277 | time_elapsed = Time.now - start_time | 278 | time_elapsed = Time.now - start_time |
278 | logger.info "Index for #{self.name} has been rebuilt (took #{'%.3f' % time_elapsed}s)" | 279 | logger.info "Index for #{self.name} has been rebuilt (took #{'%.3f' % time_elapsed}s)" |
279 | else | 280 | else |
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/instance_methods.rb
@@ -40,7 +40,7 @@ module ActsAsSolr #:nodoc: | @@ -40,7 +40,7 @@ module ActsAsSolr #:nodoc: | ||
40 | doc.boost = validate_boost(configuration[:boost]) if configuration[:boost] | 40 | doc.boost = validate_boost(configuration[:boost]) if configuration[:boost] |
41 | 41 | ||
42 | doc << {:id => solr_id, | 42 | doc << {:id => solr_id, |
43 | - solr_configuration[:type_field] => Solr::Util.query_parser_escape(self.class.name), | 43 | + solr_configuration[:type_field] => self.class.name, |
44 | solr_configuration[:primary_key_field] => record_id(self).to_s} | 44 | solr_configuration[:primary_key_field] => record_id(self).to_s} |
45 | 45 | ||
46 | # iterate through the fields and add them to the document, | 46 | # iterate through the fields and add them to the document, |
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/parser_methods.rb
@@ -127,7 +127,7 @@ module ActsAsSolr #:nodoc: | @@ -127,7 +127,7 @@ module ActsAsSolr #:nodoc: | ||
127 | classes = [self] + (self.subclasses || []) + (options[:models] || []) | 127 | classes = [self] + (self.subclasses || []) + (options[:models] || []) |
128 | classes.map do |klass| | 128 | classes.map do |klass| |
129 | next if klass.name.empty? | 129 | next if klass.name.empty? |
130 | - "#{solr_configuration[:type_field]}:\"#{Solr::Util.query_parser_escape klass.name}\"" | 130 | + "#{solr_configuration[:type_field]}:\"#{klass.name}\"" |
131 | end.compact.join(' OR ') | 131 | end.compact.join(' OR ') |
132 | end | 132 | end |
133 | 133 |
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/util.rb
@@ -27,11 +27,12 @@ class Solr::Util | @@ -27,11 +27,12 @@ class Solr::Util | ||
27 | 27 | ||
28 | # from http://lucene.apache.org/core/old_versioned_docs/versions/3_0_0/queryparsersyntax.html#Escaping Special Characters | 28 | # from http://lucene.apache.org/core/old_versioned_docs/versions/3_0_0/queryparsersyntax.html#Escaping Special Characters |
29 | ESCAPES = %w[+ - && || ! ( ) { } \[ \] " ~ * ? \\] | 29 | ESCAPES = %w[+ - && || ! ( ) { } \[ \] " ~ * ? \\] |
30 | - | 30 | + |
31 | def self.query_parser_escape(string, fields = []) | 31 | def self.query_parser_escape(string, fields = []) |
32 | - string = string.split(' ').map do |str| | 32 | + string = string.split(' ').map do |str| |
33 | if /(\w+):(.*)/ =~ str # escape : considering fields | 33 | if /(\w+):(.*)/ =~ str # escape : considering fields |
34 | - (!$2.empty? and fields.include?($1.to_sym)) ? "#{$1}:#{$2}" : "#{$1}\\:#{$2}" | 34 | + field, value = $1, $2 |
35 | + if field.present? and fields.include?(field.to_sym) then "#{field}:#{value}" else "#{field}\\:#{value.gsub ':', "\\:"}" end | ||
35 | elsif /^\^(.*)/ =~ str # escape ^ | 36 | elsif /^\^(.*)/ =~ str # escape ^ |
36 | "\\^#{$1}" | 37 | "\\^#{$1}" |
37 | else | 38 | else |