honkster-acts_as_solr 0.2.5 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rake'
3
3
  require 'rake/testtask'
4
4
  require 'rake/rdoctask'
5
5
 
6
- Dir["#{File.dirname(__FILE__)}/lib/tasks/**/*.rake"].sort.each { |ext| load ext }
6
+ Dir["#{File.dirname(__FILE__)}/lib/acts_as_solr/tasks/**/*.rake"].sort.each { |ext| load ext }
7
7
 
8
8
  desc "Default Task"
9
9
  task :default => [:test]
@@ -13,7 +13,9 @@ task :test => "test:unit"
13
13
 
14
14
  namespace :test do
15
15
  task :setup do
16
+ RAILS_ROOT = File.expand_path("#{File.dirname(__FILE__)}/test") unless defined? RAILS_ROOT
16
17
  ENV['RAILS_ENV'] = "test"
18
+ ENV["ACTS_AS_SOLR_TEST"] = "true"
17
19
  require File.expand_path("#{File.dirname(__FILE__)}/config/solr_environment")
18
20
  puts "Using " + DB
19
21
  %x(mysql -u#{MYSQL_USER} < #{File.dirname(__FILE__) + "/test/fixtures/db_definitions/mysql.sql"}) if DB == 'mysql'
@@ -56,12 +58,14 @@ begin
56
58
  require 'jeweler'
57
59
  Jeweler::Tasks.new do |s|
58
60
  s.name = "acts_as_solr"
59
- s.summary = "This plugin adds full text search capabilities and many other nifty features from Apache�s Solr to any Rails model. I'm currently rearranging the test suite to include a real unit test suite, and adding a few features I need myself."
61
+ #s.name = "honkster-acts_as_solr"
62
+ s.summary = "This plugin adds full text search capabilities and many other nifty features from Apache�s Solr to any Rails model. I'm currently rearranging the test suite to include a real unit test suite, and adding a few features I need myself."
60
63
  s.email = "meyer@paperplanes.de"
61
64
  s.homepage = "http://github.com/mattmatt/acts_as_solr"
62
- s.description = "This plugin adds full text search capabilities and many other nifty features from Apache�s Solr to any Rails model. I'm currently rearranging the test suite to include a real unit test suite, and adding a few features I need myself."
65
+ s.description = "This plugin adds full text search capabilities and many other nifty features from Apache�s Solr to any Rails model. I'm currently rearranging the test suite to include a real unit test suite, and adding a few features I need myself."
63
66
  s.authors = ["Mathias Meyer"]
64
- s.files = FileList["[A-Z]*", "{bin,generators,config,lib,solr,test}/**/*"]
67
+ s.files = FileList["[A-Z]*", "{bin,generators,config,lib,solr}/**/*"] +
68
+ FileList["test/**/*"].reject {|f| f.include?("test/log")}.reject {|f| f.include?("test/tmp")}
65
69
  end
66
70
  rescue LoadError
67
71
  puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :patch: 4
3
+ :major: 0
4
+ :minor: 3
@@ -1,17 +1,32 @@
1
1
  ENV['RAILS_ENV'] = (ENV['RAILS_ENV'] || 'development').dup
2
2
  # RAILS_ROOT isn't defined yet, so figure it out.
3
3
  require "uri"
4
+ require "fileutils"
4
5
  dir = File.dirname(__FILE__)
5
6
  SOLR_PATH = File.expand_path("#{dir}/../solr") unless defined? SOLR_PATH
6
7
 
7
- SOLR_LOGS_PATH = "#{RAILS_ROOT}/log" unless defined? SOLR_LOGS_PATH
8
- SOLR_PIDS_PATH = "#{RAILS_ROOT}/tmp/pids" unless defined? SOLR_PIDS_PATH
9
- SOLR_DATA_PATH = "#{RAILS_ROOT}/solr/#{ENV['RAILS_ENV']}" unless defined? SOLR_DATA_PATH
8
+ RAILS_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../test") unless defined? RAILS_ROOT
9
+ unless defined? SOLR_LOGS_PATH
10
+ SOLR_LOGS_PATH = ENV["SOLR_LOGS_PATH"] || "#{RAILS_ROOT}/log"
11
+ end
12
+ unless defined? SOLR_PIDS_PATH
13
+ SOLR_PIDS_PATH = ENV["SOLR_PIDS_PATH"] || "#{RAILS_ROOT}/tmp/pids"
14
+ end
15
+ unless defined? SOLR_DATA_PATH
16
+ SOLR_DATA_PATH = ENV["SOLR_DATA_PATH"] || "#{RAILS_ROOT}/solr/#{ENV['RAILS_ENV']}"
17
+ end
10
18
 
11
19
  unless defined? SOLR_PORT
12
20
  config = YAML::load_file(RAILS_ROOT+'/config/solr.yml')
13
-
21
+ raise("No solr environment defined for RAILS_ENV the #{ENV['RAILS_ENV'].inspect}") unless config[ENV['RAILS_ENV']]
14
22
  SOLR_PORT = ENV['PORT'] || URI.parse(config[ENV['RAILS_ENV']]['url']).port
15
23
  end
16
24
 
17
25
  SOLR_JVM_OPTIONS = config[ENV['RAILS_ENV']]['jvm_options'] unless defined? SOLR_JVM_OPTIONS
26
+
27
+ if ENV["ACTS_AS_SOLR_TEST"]
28
+ require "activerecord"
29
+ DB = (ENV['DB'] ? ENV['DB'] : 'sqlite') unless defined?(DB)
30
+ MYSQL_USER = (ENV['MYSQL_USER'].nil? ? 'root' : ENV['MYSQL_USER']) unless defined? MYSQL_USER
31
+ require File.join(File.dirname(File.expand_path(__FILE__)), '..', 'test', 'db', 'connections', DB, 'connection.rb')
32
+ end
@@ -158,17 +158,92 @@ module ActsAsSolr #:nodoc:
158
158
  # acts_as_solr :auto_commit => false
159
159
  # end
160
160
  #
161
- def acts_as_solr(options={}, solr_options={})
162
-
161
+ def acts_as_solr(options={}, solr_options={}, &deferred_solr_configuration)
162
+
163
163
  extend ClassMethods
164
164
  include InstanceMethods
165
165
  include CommonMethods
166
166
  include ParserMethods
167
+
168
+ define_solr_configuration_methods
169
+
170
+ after_save :solr_save
171
+ after_destroy :solr_destroy
172
+
173
+ if deferred_solr_configuration
174
+ self.deferred_solr_configuration = deferred_solr_configuration
175
+ else
176
+ process_acts_as_solr(options, solr_options)
177
+ end
178
+ end
179
+
180
+ def process_acts_as_solr(options, solr_options)
181
+ process_solr_options(options, solr_options)
182
+ end
183
+
184
+ def define_solr_configuration_methods
185
+ # I'd like to use cattr_accessor, but it does not support lazy loaders and delegation to the class in the instance methods.
186
+ # TODO: Reconcile with cattr_accessor, or a more appropriate method.
187
+ class_eval(<<-EOS, __FILE__, __LINE__)
188
+ @@configuration = nil unless defined?(@@configuration)
189
+ @@solr_configuration = nil unless defined?(@@solr_configuration)
190
+ @@deferred_solr_configuration = nil unless defined?(@@deferred_solr_configuration)
167
191
 
168
- cattr_accessor :configuration
169
- cattr_accessor :solr_configuration
170
-
171
- self.configuration = {
192
+ def self.configuration
193
+ return @@configuration if @@configuration
194
+ process_deferred_solr_configuration
195
+ @@configuration
196
+ end
197
+ def configuration
198
+ self.class.configuration
199
+ end
200
+ def self.configuration=(value)
201
+ @@configuration = value
202
+ end
203
+ def configuration=(value)
204
+ self.class.configuration = value
205
+ end
206
+
207
+ def self.solr_configuration
208
+ return @@solr_configuration if @@solr_configuration
209
+ process_deferred_solr_configuration
210
+ @@solr_configuration
211
+ end
212
+ def solr_configuration
213
+ self.class.solr_configuration
214
+ end
215
+ def self.solr_configuration=(value)
216
+ @@solr_configuration = value
217
+ end
218
+ def solr_configuration=(value)
219
+ self.class.solr_configuration = value
220
+ end
221
+
222
+ def self.deferred_solr_configuration
223
+ return @@deferred_solr_configuration if @@deferred_solr_configuration
224
+ @@deferred_solr_configuration
225
+ end
226
+ def deferred_solr_configuration
227
+ self.class.deferred_solr_configuration
228
+ end
229
+ def self.deferred_solr_configuration=(value)
230
+ @@deferred_solr_configuration = value
231
+ end
232
+ def deferred_solr_configuration=(value)
233
+ self.class.deferred_solr_configuration = value
234
+ end
235
+ EOS
236
+ end
237
+
238
+ def process_deferred_solr_configuration
239
+ return unless deferred_solr_configuration
240
+ options, solr_options = deferred_solr_configuration.call
241
+ self.deferred_solr_configuration = nil
242
+ self.process_solr_options(options, solr_options)
243
+ end
244
+
245
+ def process_solr_options(options={}, solr_options={})
246
+ self.configuration = {
172
247
  :fields => nil,
173
248
  :additional_fields => nil,
174
249
  :exclude_fields => [],
@@ -178,22 +253,19 @@ module ActsAsSolr #:nodoc:
178
253
  :boost => nil,
179
254
  :if => "true",
180
255
  :offline => false
181
- }
256
+ }
182
257
  self.solr_configuration = {
183
258
  :type_field => "type_s",
184
259
  :primary_key_field => "pk_i",
185
260
  :default_boost => 1.0
186
261
  }
187
-
262
+
188
263
  configuration.update(options) if options.is_a?(Hash)
189
264
  solr_configuration.update(solr_options) if solr_options.is_a?(Hash)
190
265
  Deprecation.validate_index(configuration)
191
-
266
+
192
267
  configuration[:solr_fields] = {}
193
268
  configuration[:solr_includes] = {}
194
-
195
- after_save :solr_save
196
- after_destroy :solr_destroy
197
269
 
198
270
  if configuration[:fields].respond_to?(:each)
199
271
  process_fields(configuration[:fields])
@@ -206,8 +278,9 @@ module ActsAsSolr #:nodoc:
206
278
  process_includes(configuration[:include])
207
279
  end
208
280
  end
209
-
281
+
210
282
  private
283
+
211
284
  def get_field_value(field)
212
285
  field_name, options = determine_field_name_and_options(field)
213
286
  configuration[:solr_fields][field_name] = options
@@ -168,7 +168,7 @@ module ActsAsSolr #:nodoc:
168
168
  result << k[0].constantize.find_by_id(k[1])
169
169
  end
170
170
  elsif options[:results_format] == :ids
171
- data.hits.each{|doc| result << {"id" => doc.values.pop.to_s}}
171
+ data.hits.each{|doc| result << {"id" => doc["id"].to_s}}
172
172
  end
173
173
  result
174
174
  end
@@ -161,6 +161,5 @@ module ActsAsSolr #:nodoc:
161
161
  end
162
162
  end
163
163
  end
164
-
165
164
  end
166
165
  end
@@ -72,7 +72,8 @@ module ActsAsSolr #:nodoc:
72
72
  query_options[:field_list] = [field_list, 'score']
73
73
  query = "(#{query.gsub(/ *: */,"_t:")}) #{models}"
74
74
  order = options[:order].split(/\s*,\s*/).collect{|e| e.gsub(/\s+/,'_t ').gsub(/\bscore_t\b/, 'score') }.join(',') if options[:order]
75
- query_options[:query] = replace_types([query])[0] # TODO adjust replace_types to work with String or Array
75
+ query_options[:query] = replace_types([query])[0] # TODO adjust replace_types to work with String or Array
76
+ query_options[:query] = quote_values_with_spaces(query_options[:query])
76
77
 
77
78
  if options[:order]
78
79
  # TODO: set the sort parameter instead of the old ;order. style.
@@ -166,6 +167,10 @@ module ActsAsSolr #:nodoc:
166
167
  end
167
168
  strings
168
169
  end
170
+
171
+ def quote_values_with_spaces(string)
172
+ string.gsub(/:([^\s\)]*)\s([^\s\)]*)\)/, ':"\1 \2")')
173
+ end
169
174
 
170
175
  # Adds the score to each one of the instances found
171
176
  def add_scores(results, solr_data)
@@ -3,6 +3,9 @@ namespace :solr do
3
3
  desc 'Starts Solr. Options accepted: RAILS_ENV=your_env, PORT=XX. Defaults to development if none.'
4
4
  task :start do
5
5
  require File.expand_path("#{File.dirname(__FILE__)}/../../../config/solr_environment")
6
+ FileUtils.mkdir_p(SOLR_LOGS_PATH)
7
+ FileUtils.mkdir_p(SOLR_DATA_PATH)
8
+ FileUtils.mkdir_p(SOLR_PIDS_PATH)
6
9
  begin
7
10
  n = Net::HTTP.new('127.0.0.1', SOLR_PORT)
8
11
  n.request_head('/').value
@@ -47,7 +50,7 @@ namespace :solr do
47
50
  require File.expand_path("#{File.dirname(__FILE__)}/../../../config/solr_environment")
48
51
  raise "In production mode. I'm not going to delete the index, sorry." if ENV['RAILS_ENV'] == "production"
49
52
  if File.exists?("#{SOLR_DATA_PATH}")
50
- Dir["#{SOLR_DATA_PATH}/index/*"].each{|f| File.unlink(f)}
53
+ Dir["#{SOLR_DATA_PATH}/index/*"].each{|f| File.unlink(f) if File.exists?(f)}
51
54
  Dir.rmdir("#{SOLR_DATA_PATH}/index")
52
55
  puts "Index files removed under " + ENV['RAILS_ENV'] + " environment"
53
56
  end
@@ -4,7 +4,7 @@ splinter_cell:
4
4
  name: Splinter Cell
5
5
  author: Tom Clancy
6
6
  published_on: <%= Date.today - 1.year %>
7
-
7
+
8
8
  ruby:
9
9
  id: 2
10
10
  category_id: 2
@@ -5,9 +5,9 @@ ipod_video:
5
5
  features: iTunes, Podcasts, Audiobooks
6
6
  category: Electronics
7
7
  price: 599.00
8
- created_at: <%= Date.today - 1.year %>
9
- updated_at: <%= Date.today - 1.month %>
10
-
8
+ created_at: <%= (Time.now - 1.year).utc %>
9
+ updated_at: <%= (Time.now - 1.month).utc %>
10
+
11
11
  dell_monitor:
12
12
  id: 2
13
13
  name: Dell Widescreen UltraSharp 3007WFP
@@ -15,9 +15,9 @@ dell_monitor:
15
15
  features: 30" TFT active matrix LCD, 2560 x 1600, .25mm dot pitch, 700:1 contrast
16
16
  category: Electronics
17
17
  price: 750.00
18
- created_at: <%= Date.today - 1.year %>
19
- updated_at: <%= Date.today - 1.month %>
20
-
18
+ created_at: <%= (Time.now - 1.year).utc %>
19
+ updated_at: <%= (Time.now - 1.month).utc %>
20
+
21
21
  samsung_hd:
22
22
  id: 3
23
23
  name: Samsung SpinPoint P120 SP2514N - hard drive - 250 GB of Memory Storage - ATA-133
@@ -25,9 +25,9 @@ samsung_hd:
25
25
  features: 7200RPM, 8MB cache, IDE Ultra ATA-133
26
26
  category: Hard Drive
27
27
  price: 319.00
28
- created_at: <%= Date.today - 2.years %>
29
- updated_at: <%= Date.today - 2.months %>
30
-
28
+ created_at: <%= (Time.now - 2.years).utc %>
29
+ updated_at: <%= (Time.now - 2.months).utc %>
30
+
31
31
  corsair_ram:
32
32
  id: 4
33
33
  name: CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) Dual Channel Kit System Memory - Retail
@@ -35,9 +35,9 @@ corsair_ram:
35
35
  features: CAS latency 2, 2-3-3-6 timing, 2.75v, unbuffered, heat-spreader
36
36
  category: Memory
37
37
  price: 155.00
38
- created_at: <%= Date.today - 6.years %>
39
- updated_at: <%= Date.today - 3.months %>
40
-
38
+ created_at: <%= (Time.now - 6.years).utc %>
39
+ updated_at: <%= (Time.now - 3.months).utc %>
40
+
41
41
  a_data_ram:
42
42
  id: 5
43
43
  name: A-DATA V-Series 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - OEM
@@ -45,5 +45,5 @@ a_data_ram:
45
45
  features: CAS latency 3, 2.7v
46
46
  category: Memory
47
47
  price: 65.79
48
- created_at: <%= Date.today - 9.years %>
49
- updated_at: <%= Date.today - 4.months %>
48
+ created_at: <%= (Time.now - 9.years).utc %>
49
+ updated_at: <%= (Time.now - 4.months).utc %>
@@ -312,11 +312,11 @@ class ActsAsSolrTest < Test::Unit::TestCase
312
312
  def test_find_by_solr_with_score
313
313
  books = Book.find_by_solr 'ruby^10 OR splinter', :scores => true
314
314
  assert_equal 2, books.total
315
- assert_equal 0.41763234, books.max_score
316
-
315
+ assert (books.max_score >= 0.3 && books.max_score <= 0.6)
316
+
317
317
  books.records.each { |book| assert_not_nil book.solr_score }
318
- assert_equal 0.41763234, books.docs.first.solr_score
319
- assert_equal 0.14354616, books.docs.last.solr_score
318
+ assert (books.docs.first.solr_score >= 0.3 && books.docs.first.solr_score <= 0.6)
319
+ assert (books.docs.last.solr_score >= 0.1 && books.docs.last.solr_score <= 0.2)
320
320
  end
321
321
 
322
322
  # Making sure nothing breaks when html entities are inside
@@ -386,11 +386,11 @@ class ActsAsSolrTest < Test::Unit::TestCase
386
386
  def test_find_by_solr_order_by_score
387
387
  books = Book.find_by_solr 'ruby^10 OR splinter', {:scores => true, :order => 'score asc' }
388
388
  assert (books.docs.collect(&:solr_score).compact.size == books.docs.size), "Each book should have a score"
389
- assert_equal 0.41763234, books.docs.last.solr_score
390
-
389
+ assert (books.docs.last.solr_score >= 0.3 && books.docs.last.solr_score <= 0.6)
390
+
391
391
  books = Book.find_by_solr 'ruby^10 OR splinter', {:scores => true, :order => 'score desc' }
392
- assert_equal 0.41763234, books.docs.first.solr_score
393
- assert_equal 0.14354616, books.docs.last.solr_score
392
+ assert (books.docs.first.solr_score >= 0.3 && books.docs.first.solr_score <= 0.6)
393
+ assert (books.docs.last.solr_score >= 0.1 && books.docs.last.solr_score <= 0.2)
394
394
  end
395
395
 
396
396
  # Search based on fields with the :date format
@@ -8,8 +8,9 @@ class ActsAsSolrTest < Test::Unit::TestCase
8
8
  def test_multi_solr_search_return_objects
9
9
  records = Book.multi_solr_search "Napoleon OR Tom", :models => [Movie], :results_format => :objects
10
10
  assert_equal 2, records.total
11
- assert_equal Movie, records.docs.first.class
12
- assert_equal Book, records.docs.last.class
11
+ classes = records.docs.map {|d| d.class}
12
+ assert classes.include?(Book)
13
+ assert classes.include?(Movie)
13
14
  end
14
15
 
15
16
  # Testing the multi_solr_search with the returning results being ids
@@ -22,11 +23,16 @@ class ActsAsSolrTest < Test::Unit::TestCase
22
23
 
23
24
  # Testing the multi_solr_search with multiple models
24
25
  def test_multi_solr_search_multiple_models
26
+ # TODO: Generalize me
27
+ ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => 'type_s:Author AND NOT id:"Author:1" AND NOT id:"Author:2"'))
28
+ ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => 'type_s:Book AND NOT id:"Book:1" AND NOT id:"Book:2"'))
29
+ ActsAsSolr::Post.execute(Solr::Request::Commit.new)
30
+
25
31
  records = Book.multi_solr_search "Napoleon OR Tom OR Thriller", :models => [Movie, Category], :results_format => :ids
26
- assert_equal 4, records.total
27
- [{"id" => "Category:1"}, {"id" =>"Book:1"}, {"id" => "Movie:1"}, {"id" =>"Book:3"}].each do |result|
28
- assert records.docs.include?(result)
29
- end
32
+ assert_equal 3, records.total
33
+ assert records.docs.include?({"id" => "Category:1"})
34
+ assert records.docs.include?({"id" =>"Book:1"})
35
+ assert records.docs.include?({"id" => "Movie:1"})
30
36
  end
31
37
 
32
38
  # Testing empty result set format
@@ -45,7 +51,7 @@ class ActsAsSolrTest < Test::Unit::TestCase
45
51
 
46
52
  def test_search_with_score_should_set_score
47
53
  records = Book.multi_solr_search "Napoleon OR Tom", :models => [Movie], :results_format => :objects, :scores => true
48
- assert_equal 1.0112731, records.docs.first.solr_score
49
- assert_equal 0.6723396, records.docs.last.solr_score
54
+ assert records.docs.first.solr_score.is_a?(Float)
55
+ assert records.docs.last.solr_score.is_a?(Float)
50
56
  end
51
57
  end
@@ -8,10 +8,14 @@
8
8
  # - created_on
9
9
 
10
10
  class Electronic < ActiveRecord::Base
11
- acts_as_solr :facets => [:category, :manufacturer],
12
- :fields => [:name, :manufacturer, :features, :category, {:created_at => :date}, {:updated_at => :date}, {:price => {:type => :range_float, :boost => 10.0}}],
13
- :boost => 5.0,
14
- :exclude_fields => [:features]
11
+ acts_as_solr do
12
+ {
13
+ :facets => [:category, :manufacturer],
14
+ :fields => [:name, :manufacturer, :features, :category, {:created_at => :date}, {:updated_at => :date}, {:price => {:type => :range_float, :boost => 10.0}}],
15
+ :boost => 5.0,
16
+ :exclude_fields => [:features]
17
+ }
18
+ end
15
19
 
16
20
  # The following example would also convert the :price field type to :range_float
17
21
  #
data/test/test_helper.rb CHANGED
@@ -10,12 +10,15 @@ end
10
10
 
11
11
  RAILS_ROOT = File.dirname(__FILE__) unless defined? RAILS_ROOT
12
12
  RAILS_ENV = 'test' unless defined? RAILS_ENV
13
+ ENV["RAILS_ENV"] = "test"
14
+ ENV["ACTS_AS_SOLR_TEST"] = "true"
13
15
 
14
16
  require File.expand_path(File.dirname(__FILE__) + '/../lib/acts_as_solr')
15
17
  require File.expand_path(File.dirname(__FILE__) + '/../config/solr_environment.rb')
16
18
 
17
19
  # Load Models
18
20
  models_dir = File.join(File.dirname( __FILE__ ), 'models')
21
+ require "#{models_dir}/book.rb"
19
22
  Dir[ models_dir + '/*.rb'].each { |m| require m }
20
23
 
21
24
  if defined?(ActiveSupport::TestCase)
@@ -13,7 +13,7 @@ class InstanceMethodsTest < Test::Unit::TestCase
13
13
  setup do
14
14
  @instance.configuration = {:if => true}
15
15
  end
16
-
16
+
17
17
  should "return true if the specified proc returns true " do
18
18
  @instance.configuration[:offline] = proc {|record| true}
19
19
  assert @instance.indexing_disabled?
@@ -2,7 +2,7 @@ class ActsAsSolr::ParserInstance
2
2
  include ActsAsSolr::ParserMethods
3
3
  include ActsAsSolr::CommonMethods
4
4
  attr_accessor :configuration, :solr_configuration
5
-
5
+
6
6
  def table_name
7
7
  "documents"
8
8
  end
@@ -15,5 +15,5 @@ class ActsAsSolr::ParserInstance
15
15
  []
16
16
  end
17
17
 
18
- public :parse_results, :reorder, :parse_query, :add_scores, :replace_types
18
+ public :parse_results, :reorder, :parse_query, :add_scores, :replace_types, :quote_values_with_spaces
19
19
  end
@@ -245,6 +245,18 @@ class ParserMethodsTest < Test::Unit::TestCase
245
245
  end
246
246
  end
247
247
  end
248
+
249
+ context "When quoting strings" do
250
+
251
+ should "quote values that have spaces" do
252
+ assert_equal '(some_facet:"One Fish") AND (other_t:"Two Fish")', @parser.quote_values_with_spaces("(some_facet:One Fish) AND (other_t:Two Fish)")
253
+ end
254
+
255
+ should "not quote values that do not have spaces" do
256
+ assert_equal '(age_i:21) OR (some_facet:foo)', @parser.quote_values_with_spaces("(age_i:21) OR (some_facet:foo)")
257
+ end
258
+
259
+ end
248
260
 
249
261
  context "When adding scores" do
250
262
  setup do
@@ -2,6 +2,11 @@ class SolrInstance
2
2
  include ActsAsSolr::InstanceMethods
3
3
  attr_accessor :configuration, :solr_configuration, :name
4
4
 
5
+ class << self
6
+ include ActsAsSolr::ActsMethods
7
+ include ActsAsSolr::ClassMethods
8
+ end
9
+
5
10
  def initialize(name = "Chunky bacon!")
6
11
  @name = name
7
12
  end
@@ -1,13 +1,15 @@
1
- $:.unshift(File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "lib"))
1
+ dir = File.dirname(__FILE__)
2
+ $:.unshift(File.join(File.expand_path(dir), "..", "..", "lib"))
2
3
 
3
4
  require 'rubygems'
4
5
  require 'test/unit'
5
6
  require 'acts_as_solr'
7
+ require 'activesupport'
6
8
  require 'mocha'
7
9
  require 'active_support'
8
10
  require 'logger'
9
- require 'solr_instance'
10
- require 'parser_instance'
11
+ require File.expand_path("#{dir}/solr_instance")
12
+ require File.expand_path("#{dir}/parser_instance")
11
13
  require 'erb'
12
14
  require 'ostruct'
13
15
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: honkster-acts_as_solr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathias Meyer
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-21 00:00:00 -07:00
12
+ date: 2009-06-02 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: "This plugin adds full text search capabilities and many other nifty features from Apache\xD4s Solr to any Rails model. I'm currently rearranging the test suite to include a real unit test suite, and adding a few features I need myself."
16
+ description: "This plugin adds full text search capabilities and many other nifty features from Apache\xEF\xBF\xBDs Solr to any Rails model. I'm currently rearranging the test suite to include a real unit test suite, and adding a few features I need myself."
17
17
  email: meyer@paperplanes.de
18
18
  executables: []
19
19
 
@@ -30,7 +30,7 @@ files:
30
30
  - README.rdoc
31
31
  - Rakefile
32
32
  - TESTING_THE_PLUGIN
33
- - VERSION
33
+ - VERSION.yml
34
34
  - config/solr.yml
35
35
  - config/solr_environment.rb
36
36
  - lib/acts_as_solr.rb
@@ -204,7 +204,7 @@ rubyforge_project:
204
204
  rubygems_version: 1.2.0
205
205
  signing_key:
206
206
  specification_version: 3
207
- summary: "This plugin adds full text search capabilities and many other nifty features from Apache\xD4s Solr to any Rails model. I'm currently rearranging the test suite to include a real unit test suite, and adding a few features I need myself."
207
+ summary: "This plugin adds full text search capabilities and many other nifty features from Apache\xEF\xBF\xBDs Solr to any Rails model. I'm currently rearranging the test suite to include a real unit test suite, and adding a few features I need myself."
208
208
  test_files:
209
209
  - test/db/connections/mysql/connection.rb
210
210
  - test/db/connections/sqlite/connection.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.2.5