acts_as_solr_reloaded 1.3.0 → 1.4.0

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/acts_as_solr/tasks/**/*.rake"].sort.each { |ext| load ext }
6
+ Dir["#{File.dirname(__FILE__)}/lib/tasks/*.rake"].sort.each { |ext| load ext }
7
7
 
8
8
  desc "Default Task"
9
9
  task :default => [:test]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.0
1
+ 1.4.0
@@ -119,6 +119,7 @@ module ActsAsSolr #:nodoc:
119
119
  configuration = {
120
120
  :format => :objects
121
121
  }
122
+ results.update(:spellcheck => solr_data.data['spellcheck']) unless solr_data.nil?
122
123
  results.update(:facets => {'facet_fields' => []}) if options[:facets]
123
124
  return SearchResults.new(results) if (solr_data.nil? || solr_data.total_hits == 0)
124
125
 
@@ -62,6 +62,10 @@ module ActsAsSolr #:nodoc:
62
62
  def highlights
63
63
  @solr_data[:highlights]
64
64
  end
65
+
66
+ def suggest
67
+ @solr_data[:spellcheck]['suggestions']['collation'].match(/\((.+)\) /)[1]
68
+ end
65
69
 
66
70
  alias docs results
67
71
  alias records results
@@ -14,7 +14,7 @@ class Solr::Request::Standard < Solr::Request::Select
14
14
 
15
15
  VALID_PARAMS = [:query, :sort, :default_field, :operator, :start, :rows, :shards, :date_facets,
16
16
  :filter_queries, :field_list, :debug_query, :explain_other, :facets, :highlighting, :mlt, :radius,
17
- :latitude, :longitude]
17
+ :latitude, :longitude, :spellcheck]
18
18
 
19
19
  def initialize(params)
20
20
  super(params[:radius].nil? ? 'standard' : 'geo')
@@ -400,6 +400,9 @@ class Solr::Request::Standard < Solr::Request::Select
400
400
  hash["mlt.boost"] = @params[:mlt][:boost]
401
401
  end
402
402
 
403
+ hash[:spellcheck] = true
404
+ hash['spellcheck.collate'] = true
405
+
403
406
  hash.merge(super.to_hash)
404
407
  end
405
408
 
File without changes
@@ -2,7 +2,7 @@ namespace :solr do
2
2
 
3
3
  desc 'Starts Solr. Options accepted: RAILS_ENV=your_env, PORT=XX. Defaults to development if none.'
4
4
  task :start => :environment do
5
- require File.expand_path("#{File.dirname(__FILE__)}/../../../config/solr_environment")
5
+ require File.expand_path("#{File.dirname(__FILE__)}/../../config/solr_environment")
6
6
  FileUtils.mkdir_p(SOLR_LOGS_PATH)
7
7
  FileUtils.mkdir_p(SOLR_DATA_PATH)
8
8
  FileUtils.mkdir_p(SOLR_PIDS_PATH)
@@ -13,7 +13,9 @@ namespace :solr do
13
13
  rescue Net::HTTPServerException #responding
14
14
  puts "Port #{SOLR_PORT} in use" and return
15
15
 
16
- rescue Errno::ECONNREFUSED, Errno::EBADF #not responding
16
+ rescue Errno::ECONNREFUSED, Errno::EBADF, NoMethodError #not responding
17
+ # there's an issue with Net::HTTP.request where @socket is nil and raises a NoMethodError
18
+ # http://redmine.ruby-lang.org/issues/show/2708
17
19
  Dir.chdir(SOLR_PATH) do
18
20
  cmd = "java #{SOLR_JVM_OPTIONS} -Djetty.logs=\"#{SOLR_LOGS_PATH}\" -Dsolr.solr.home=\"#{SOLR_CONFIG_PATH}\" -Dsolr.data.dir=\"#{SOLR_DATA_PATH}\" -Djetty.port=#{SOLR_PORT} -jar start.jar"
19
21
  puts "Executing: " + cmd
@@ -35,7 +37,7 @@ namespace :solr do
35
37
 
36
38
  desc 'Stops Solr. Specify the environment by using: RAILS_ENV=your_env. Defaults to development if none.'
37
39
  task :stop=> :environment do
38
- require File.expand_path("#{File.dirname(__FILE__)}/../../../config/solr_environment")
40
+ require File.expand_path("#{File.dirname(__FILE__)}/../../config/solr_environment")
39
41
  fork do
40
42
  file_path = "#{SOLR_PIDS_PATH}/#{ENV['RAILS_ENV']}_pid"
41
43
  if File.exists?(file_path)
@@ -54,7 +56,7 @@ namespace :solr do
54
56
 
55
57
  desc 'Remove Solr index'
56
58
  task :destroy_index => :environment do
57
- require File.expand_path("#{File.dirname(__FILE__)}/../../../config/solr_environment")
59
+ require File.expand_path("#{File.dirname(__FILE__)}/../../config/solr_environment")
58
60
  raise "In production mode. I'm not going to delete the index, sorry." if ENV['RAILS_ENV'] == "production"
59
61
  if File.exists?("#{SOLR_DATA_PATH}")
60
62
  Dir["#{SOLR_DATA_PATH}/index/*"].each{|f| File.unlink(f) if File.exists?(f)}
@@ -67,7 +69,7 @@ namespace :solr do
67
69
  # http://henrik.nyh.se/2007/06/rake-task-to-reindex-models-for-acts_as_solr
68
70
  desc %{Reindexes data for all acts_as_solr models. Clears index first to get rid of orphaned records and optimizes index afterwards. RAILS_ENV=your_env to set environment. ONLY=book,person,magazine to only reindex those models; EXCEPT=book,magazine to exclude those models. START_SERVER=true to solr:start before and solr:stop after. BATCH=123 to post/commit in batches of that size: default is 300. CLEAR=false to not clear the index first; OPTIMIZE=false to not optimize the index afterwards.}
69
71
  task :reindex => :environment do
70
- require File.expand_path("#{File.dirname(__FILE__)}/../../../config/solr_environment")
72
+ require File.expand_path("#{File.dirname(__FILE__)}/../../config/solr_environment")
71
73
 
72
74
  includes = env_array_to_constants('ONLY')
73
75
  if includes.empty?
File without changes
data/test/db/test.db CHANGED
Binary file
@@ -461,6 +461,10 @@ class ActsAsSolrTest < Test::Unit::TestCase
461
461
  expected = {"name"=>["<em>Ruby</em> for Dummies"]}
462
462
  assert_equal expected, records.highlights.values.first
463
463
  end
464
+
465
+ def test_spellcheck
466
+ assert_equal "ruby for dummies", Book.search("rubi for dumies").suggest
467
+ end
464
468
 
465
469
  def test_mongo_mappers_documents_are_found
466
470
  Document.new(:name => "mapper").save
@@ -242,7 +242,20 @@ class ParserMethodsTest < Test::Unit::TestCase
242
242
  }
243
243
  @parser.parse_query "foo", :operator => :or
244
244
  end
245
-
245
+
246
+ should "activate spellcheck" do
247
+ ActsAsSolr::Post.expects(:execute).with {|request, core|
248
+ request.to_hash[:spellcheck] == true
249
+ }
250
+ @parser.parse_query "foo"
251
+ end
252
+
253
+ should "activate spellcheck collation" do
254
+ ActsAsSolr::Post.expects(:execute).with {|request, core|
255
+ request.to_hash['spellcheck.collate'] == true
256
+ }
257
+ @parser.parse_query "foo"
258
+ end
246
259
 
247
260
  context "with the around option" do
248
261
  should "set the qt as geo" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_solr_reloaded
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego Carrion
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-31 00:00:00 -02:00
12
+ date: 2010-02-25 00:00:00 -03:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -50,9 +50,6 @@ files:
50
50
  - lib/acts_as_solr/search_results.rb
51
51
  - lib/acts_as_solr/solr_fixtures.rb
52
52
  - lib/acts_as_solr/tasks.rb
53
- - lib/acts_as_solr/tasks/database.rake
54
- - lib/acts_as_solr/tasks/solr.rake
55
- - lib/acts_as_solr/tasks/test.rake
56
53
  - lib/acts_as_solr_reloaded.rb
57
54
  - lib/solr.rb
58
55
  - lib/solr/connection.rb
@@ -99,6 +96,9 @@ files:
99
96
  - lib/solr/solrtasks.rb
100
97
  - lib/solr/util.rb
101
98
  - lib/solr/xml.rb
99
+ - lib/tasks/database.rake
100
+ - lib/tasks/solr.rake
101
+ - lib/tasks/test.rake
102
102
  - test/config/solr.yml
103
103
  - test/db/connections/mysql/connection.rb
104
104
  - test/db/connections/sqlite/connection.rb