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
plugins/solr/lib/ext/category.rb
plugins/solr/lib/ext/facets_browse.rb
plugins/solr/lib/ext/product.rb
plugins/solr/lib/ext/profile.rb
... | ... | @@ -14,10 +14,11 @@ class Profile |
14 | 14 | :solr_plugin_f_enabled => {:label => _('Situation'), :type_if => proc { |klass| klass.kind_of?(Enterprise) }, |
15 | 15 | :proc => proc { |id| solr_plugin_f_enabled_proc(id) }}, |
16 | 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 | 18 | :solr_plugin_f_categories => {:multi => true, :proc => proc {|facet, id| solr_plugin_f_categories_proc(facet, id)}, |
18 | 19 | :label => proc { |env| solr_plugin_f_categories_label_proc(env) }, :label_abbrev => proc{ |env| solr_plugin_f_categories_label_abbrev_proc(env) }}, |
19 | 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 | 23 | acts_as_searchable :fields => facets_fields_for_solr + [:solr_plugin_extra_data_for_index, |
23 | 24 | # searched fields |
... | ... | @@ -39,6 +40,7 @@ class Profile |
39 | 40 | :boost => proc{ |p| 10 if p.enabled } |
40 | 41 | |
41 | 42 | handle_asynchronously :solr_save |
43 | + handle_asynchronously :solr_destroy | |
42 | 44 | |
43 | 45 | class_inheritable_accessor :solr_plugin_extra_index_methods |
44 | 46 | self.solr_plugin_extra_index_methods = [] |
... | ... | @@ -116,4 +118,13 @@ class Profile |
116 | 118 | def solr_plugin_name_sortable |
117 | 119 | name |
118 | 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 | 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 | 273 | end |
274 | 274 | |
275 | 275 | if items_processed > 0 |
276 | - solr_optimize | |
276 | + # FIXME: not recommended, reenable with option | |
277 | + #solr_optimize | |
277 | 278 | time_elapsed = Time.now - start_time |
278 | 279 | logger.info "Index for #{self.name} has been rebuilt (took #{'%.3f' % time_elapsed}s)" |
279 | 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 | 40 | doc.boost = validate_boost(configuration[:boost]) if configuration[:boost] |
41 | 41 | |
42 | 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 | 44 | solr_configuration[:primary_key_field] => record_id(self).to_s} |
45 | 45 | |
46 | 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 | 127 | classes = [self] + (self.subclasses || []) + (options[:models] || []) |
128 | 128 | classes.map do |klass| |
129 | 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 | 131 | end.compact.join(' OR ') |
132 | 132 | end |
133 | 133 | ... | ... |
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/util.rb
... | ... | @@ -27,11 +27,12 @@ class Solr::Util |
27 | 27 | |
28 | 28 | # from http://lucene.apache.org/core/old_versioned_docs/versions/3_0_0/queryparsersyntax.html#Escaping Special Characters |
29 | 29 | ESCAPES = %w[+ - && || ! ( ) { } \[ \] " ~ * ? \\] |
30 | - | |
30 | + | |
31 | 31 | def self.query_parser_escape(string, fields = []) |
32 | - string = string.split(' ').map do |str| | |
32 | + string = string.split(' ').map do |str| | |
33 | 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 | 36 | elsif /^\^(.*)/ =~ str # escape ^ |
36 | 37 | "\\^#{$1}" |
37 | 38 | else | ... | ... |