Commit 6ca2fe8d0881cf20d7ba83c11e22dd9dc2562499

Authored by Rodrigo Souto
2 parents 009e101d 2e0bb477

Merge commit 'refs/merge-requests/353' of git://gitorious.org/noosfero/noosfero …

…into merge-requests/353
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/class_methods.rb
@@ -208,7 +208,7 @@ module ActsAsSolr #:nodoc: @@ -208,7 +208,7 @@ module ActsAsSolr #:nodoc:
208 # using eager loading for indexed associations. 208 # using eager loading for indexed associations.
209 def rebuild_solr_index(batch_size=300, options = {}, &finder) 209 def rebuild_solr_index(batch_size=300, options = {}, &finder)
210 finder ||= lambda do |ar, sql_options| 210 finder ||= lambda do |ar, sql_options|
211 - ar.all sql_options.merge!({:order => self.primary_key, :include => configuration[:solr_includes].keys}) 211 + ar.all sql_options.merge!({:order => self.primary_key})
212 end 212 end
213 start_time = Time.now 213 start_time = Time.now
214 options[:offset] ||= 0 214 options[:offset] ||= 0
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/instance_methods.rb
1 module ActsAsSolr #:nodoc: 1 module ActsAsSolr #:nodoc:
2 - 2 +
3 module InstanceMethods 3 module InstanceMethods
4 4
5 # Solr id is <class.name>:<id> to be unique across all models 5 # Solr id is <class.name>:<id> to be unique across all models
@@ -10,7 +10,7 @@ module ActsAsSolr #:nodoc: @@ -10,7 +10,7 @@ module ActsAsSolr #:nodoc:
10 # saves to the Solr index 10 # saves to the Solr index
11 def solr_save 11 def solr_save
12 return true if indexing_disabled? 12 return true if indexing_disabled?
13 - if evaluate_condition(:if, self) 13 + if evaluate_condition(:if, self)
14 debug "solr_save: #{self.class.name} : #{record_id(self)}" 14 debug "solr_save: #{self.class.name} : #{record_id(self)}"
15 solr_add to_solr_doc 15 solr_add to_solr_doc
16 solr_commit if configuration[:auto_commit] 16 solr_commit if configuration[:auto_commit]
@@ -38,9 +38,9 @@ module ActsAsSolr #:nodoc: @@ -38,9 +38,9 @@ module ActsAsSolr #:nodoc:
38 debug "to_solr_doc: creating doc for class: #{self.class.name}, id: #{record_id(self)}" 38 debug "to_solr_doc: creating doc for class: #{self.class.name}, id: #{record_id(self)}"
39 doc = Solr::Document.new 39 doc = Solr::Document.new
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] => self.class.name, 43 + solr_configuration[:type_field] => Solr::Util.query_parser_escape(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,
@@ -50,7 +50,7 @@ module ActsAsSolr #:nodoc: @@ -50,7 +50,7 @@ module ActsAsSolr #:nodoc:
50 field_boost = options[:boost] || solr_configuration[:default_boost] 50 field_boost = options[:boost] || solr_configuration[:default_boost]
51 field_type = get_solr_field_type(options[:type]) 51 field_type = get_solr_field_type(options[:type])
52 solr_name = options[:as] || field_name 52 solr_name = options[:as] || field_name
53 - 53 +
54 value = self.send("#{field_name}_for_solr") rescue nil 54 value = self.send("#{field_name}_for_solr") rescue nil
55 next if value.nil? 55 next if value.nil?
56 56
@@ -63,18 +63,18 @@ module ActsAsSolr #:nodoc: @@ -63,18 +63,18 @@ module ActsAsSolr #:nodoc:
63 field.boost = processed_boost 63 field.boost = processed_boost
64 doc << field 64 doc << field
65 end 65 end
66 - 66 +
67 add_dynamic_attributes(doc) 67 add_dynamic_attributes(doc)
68 add_includes(doc) 68 add_includes(doc)
69 add_tags(doc) 69 add_tags(doc)
70 add_space(doc) 70 add_space(doc)
71 - 71 +
72 debug doc.to_json 72 debug doc.to_json
73 doc 73 doc
74 end 74 end
75 75
76 private 76 private
77 - 77 +
78 def debug(text) 78 def debug(text)
79 logger.debug text rescue nil 79 logger.debug text rescue nil
80 end 80 end
@@ -85,14 +85,14 @@ module ActsAsSolr #:nodoc: @@ -85,14 +85,14 @@ module ActsAsSolr #:nodoc:
85 doc << Solr::Field.new(:name => "lng_f", :value => local.longitude) 85 doc << Solr::Field.new(:name => "lng_f", :value => local.longitude)
86 end 86 end
87 end 87 end
88 - 88 +
89 def add_tags(doc) 89 def add_tags(doc)
90 taggings.each do |tagging| 90 taggings.each do |tagging|
91 doc << Solr::Field.new(:name => "tag_facet", :value => tagging.tag.name) 91 doc << Solr::Field.new(:name => "tag_facet", :value => tagging.tag.name)
92 doc << Solr::Field.new(:name => "tag_t", :value => tagging.tag.name) 92 doc << Solr::Field.new(:name => "tag_t", :value => tagging.tag.name)
93 end if configuration[:taggable] 93 end if configuration[:taggable]
94 end 94 end
95 - 95 +
96 def add_dynamic_attributes(doc) 96 def add_dynamic_attributes(doc)
97 dynamic_attributes.each do |attribute| 97 dynamic_attributes.each do |attribute|
98 value = ERB::Util.html_escape(attribute.value) 98 value = ERB::Util.html_escape(attribute.value)
@@ -130,7 +130,7 @@ module ActsAsSolr #:nodoc: @@ -130,7 +130,7 @@ module ActsAsSolr #:nodoc:
130 end 130 end
131 end 131 end
132 end 132 end
133 - 133 +
134 def include_value(record, options) 134 def include_value(record, options)
135 if options[:using].is_a? Proc 135 if options[:using].is_a? Proc
136 options[:using].call(record) 136 options[:using].call(record)
@@ -159,14 +159,14 @@ module ActsAsSolr #:nodoc: @@ -159,14 +159,14 @@ module ActsAsSolr #:nodoc:
159 self.send(boost) 159 self.send(boost)
160 end 160 end
161 end 161 end
162 - 162 +
163 boost_value || solr_configuration[:default_boost] 163 boost_value || solr_configuration[:default_boost]
164 end 164 end
165 - 165 +
166 def condition_block?(condition) 166 def condition_block?(condition)
167 condition.respond_to?("call") && (condition.arity == 1 || condition.arity == -1) 167 condition.respond_to?("call") && (condition.arity == 1 || condition.arity == -1)
168 end 168 end
169 - 169 +
170 def evaluate_condition(which_condition, field) 170 def evaluate_condition(which_condition, field)
171 condition = configuration[which_condition] 171 condition = configuration[which_condition]
172 case condition 172 case condition
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]}:\"#{klass.name}\"" 130 + "#{solr_configuration[:type_field]}:\"#{Solr::Util.query_parser_escape 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/request/select.rb
@@ -12,22 +12,22 @@ @@ -12,22 +12,22 @@
12 12
13 # "Abstract" base class, only useful with subclasses that add parameters 13 # "Abstract" base class, only useful with subclasses that add parameters
14 class Solr::Request::Select < Solr::Request::Base 14 class Solr::Request::Select < Solr::Request::Base
15 - 15 +
16 attr_reader :query_type 16 attr_reader :query_type
17 - 17 +
18 def initialize(qt=nil, params={}) 18 def initialize(qt=nil, params={})
19 @query_type = qt 19 @query_type = qt
20 @select_params = params 20 @select_params = params
21 end 21 end
22 - 22 +
23 def response_format 23 def response_format
24 :ruby 24 :ruby
25 end 25 end
26 - 26 +
27 def handler 27 def handler
28 'select' 28 'select'
29 end 29 end
30 - 30 +
31 def content_type 31 def content_type
32 'application/x-www-form-urlencoded; charset=utf-8' 32 'application/x-www-form-urlencoded; charset=utf-8'
33 end 33 end
@@ -35,7 +35,7 @@ class Solr::Request::Select &lt; Solr::Request::Base @@ -35,7 +35,7 @@ class Solr::Request::Select &lt; Solr::Request::Base
35 def to_hash 35 def to_hash
36 return {:qt => query_type, :wt => 'ruby', 'json.nl' => 'arrarr'}.merge(@select_params) 36 return {:qt => query_type, :wt => 'ruby', 'json.nl' => 'arrarr'}.merge(@select_params)
37 end 37 end
38 - 38 +
39 def to_s 39 def to_s
40 raw_params = self.to_hash 40 raw_params = self.to_hash
41 41
@@ -50,5 +50,5 @@ class Solr::Request::Select &lt; Solr::Request::Base @@ -50,5 +50,5 @@ class Solr::Request::Select &lt; Solr::Request::Base
50 50
51 http_params.join("&") 51 http_params.join("&")
52 end 52 end
53 - 53 +
54 end 54 end
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake
@@ -177,7 +177,7 @@ namespace :solr do @@ -177,7 +177,7 @@ namespace :solr do
177 models.each do |model| 177 models.each do |model|
178 if clear_first 178 if clear_first
179 puts "Clearing index for #{model}..." 179 puts "Clearing index for #{model}..."
180 - ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "#{model.solr_configuration[:type_field]}:#{Solr::Util.query_parser_escape(model.name)}")) 180 + ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "#{model.solr_configuration[:type_field]}:#{model.name.gsub ':', "\\:"}"))
181 ActsAsSolr::Post.execute(Solr::Request::Commit.new) 181 ActsAsSolr::Post.execute(Solr::Request::Commit.new)
182 end 182 end
183 183