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