supernova-core 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +22 -0
  4. data/README.md +29 -0
  5. data/Rakefile +10 -0
  6. data/bin/solr_admin +5 -0
  7. data/lib/functional_delegator.rb +44 -0
  8. data/lib/supernova-core.rb +7 -0
  9. data/lib/supernova-core/version.rb +5 -0
  10. data/lib/supernova.rb +18 -0
  11. data/lib/supernova/batch_indexer.rb +40 -0
  12. data/lib/supernova/solr/cli.rb +169 -0
  13. data/lib/supernova/solr/core.rb +41 -0
  14. data/lib/supernova/solr/mapper.rb +31 -0
  15. data/lib/supernova/solr/server.rb +108 -0
  16. data/solr/conf/admin-extra.html +31 -0
  17. data/solr/conf/elevate.xml +36 -0
  18. data/solr/conf/mapping-FoldToASCII.txt +3813 -0
  19. data/solr/conf/mapping-ISOLatin1Accent.txt +246 -0
  20. data/solr/conf/protwords.txt +21 -0
  21. data/solr/conf/schema.xml +477 -0
  22. data/solr/conf/scripts.conf +24 -0
  23. data/solr/conf/solrconfig.xml +1508 -0
  24. data/solr/conf/spellings.txt +2 -0
  25. data/solr/conf/stopwords.txt +58 -0
  26. data/solr/conf/synonyms.txt +29 -0
  27. data/solr/conf/velocity/VM_global_library.vm +184 -0
  28. data/solr/conf/velocity/browse.vm +45 -0
  29. data/solr/conf/velocity/cluster.vm +26 -0
  30. data/solr/conf/velocity/clusterResults.vm +29 -0
  31. data/solr/conf/velocity/doc.vm +29 -0
  32. data/solr/conf/velocity/facet_dates.vm +0 -0
  33. data/solr/conf/velocity/facet_fields.vm +12 -0
  34. data/solr/conf/velocity/facet_queries.vm +3 -0
  35. data/solr/conf/velocity/facet_ranges.vm +30 -0
  36. data/solr/conf/velocity/facets.vm +7 -0
  37. data/solr/conf/velocity/footer.vm +17 -0
  38. data/solr/conf/velocity/head.vm +45 -0
  39. data/solr/conf/velocity/header.vm +3 -0
  40. data/solr/conf/velocity/hit.vm +5 -0
  41. data/solr/conf/velocity/jquery.autocomplete.css +48 -0
  42. data/solr/conf/velocity/jquery.autocomplete.js +762 -0
  43. data/solr/conf/velocity/layout.vm +20 -0
  44. data/solr/conf/velocity/main.css +184 -0
  45. data/solr/conf/velocity/query.vm +56 -0
  46. data/solr/conf/velocity/querySpatial.vm +40 -0
  47. data/solr/conf/velocity/suggest.vm +3 -0
  48. data/solr/conf/velocity/tabs.vm +22 -0
  49. data/solr/conf/xslt/example.xsl +132 -0
  50. data/solr/conf/xslt/example_atom.xsl +67 -0
  51. data/solr/conf/xslt/example_rss.xsl +66 -0
  52. data/solr/conf/xslt/luke.xsl +337 -0
  53. data/spec/fixtures/cores_create.json +1 -0
  54. data/spec/fixtures/cores_status.json +1 -0
  55. data/spec/integration/supernova_core_spec.rb +95 -0
  56. data/spec/spec_helper.rb +30 -0
  57. data/spec/supernova/batch_indexer_spec.rb +69 -0
  58. data/spec/supernova/solr/cli_spec.rb +26 -0
  59. data/spec/supernova/solr/core_spec.rb +81 -0
  60. data/spec/supernova/solr/mapper_spec.rb +25 -0
  61. data/spec/supernova/solr/server_spec.rb +144 -0
  62. data/spec/supernova_spec.rb +31 -0
  63. data/supernova-core.gemspec +25 -0
  64. metadata +237 -0
@@ -0,0 +1 @@
1
+ {"responseHeader":{"status":0,"QTime":665},"core":"test_core","saved":"/opt/solr/solr.xml"}
@@ -0,0 +1 @@
1
+ {"responseHeader":{"status":0,"QTime":3},"status":{"project_test":{"name":"project_test","instanceDir":"/Users/tobias/Projects/project/solr/","dataDir":"/opt/solr/project_test/","startTime":"2012-03-26T21:03:51.633Z","uptime":295157,"index":{"numDocs":1013,"maxDoc":1013,"version":1326491264175,"optimized":true,"current":true,"hasDeletions":false,"directory":"org.apache.lucene.store.NIOFSDirectory:org.apache.lucene.store.NIOFSDirectory@/opt/solr/project_test/index lockFactory=org.apache.lucene.store.NativeFSLockFactory@32b3a5a0","lastModified":"2012-03-07T15:32:31Z"}},"supernova_test":{"name":"supernova_test","instanceDir":"/Users/tobias/Projects/supernova/solr/","dataDir":"/opt/solr/supernova_test/","startTime":"2012-03-26T21:03:52.455Z","uptime":294337,"index":{"numDocs":4,"maxDoc":4,"version":1330931224856,"optimized":true,"current":true,"hasDeletions":false,"directory":"org.apache.lucene.store.NIOFSDirectory:org.apache.lucene.store.NIOFSDirectory@/opt/solr/supernova_test/index lockFactory=org.apache.lucene.store.NativeFSLockFactory@303ec561","lastModified":"2012-03-05T12:14:35Z"}}}}
@@ -0,0 +1,95 @@
1
+ require "spec_helper"
2
+ require "supernova/solr/core"
3
+ require "supernova/solr/mapper"
4
+ require "supernova/batch_indexer"
5
+
6
+ describe "Supernova Core Spec" do
7
+ let(:core) { Supernova::Solr::Core.new("http://localhost:8983/solr", "supernova_core") }
8
+
9
+ before(:each) do
10
+ WebMock.disable!
11
+ core.create("/opt/solr", "/opt/solr/supernova_core")
12
+ core.truncate
13
+ core.commit
14
+ end
15
+
16
+ class LogCatcher
17
+ def initialize
18
+ @messages ||= { :info => [] }
19
+ end
20
+
21
+ def messages
22
+ @messages
23
+ end
24
+
25
+ def method_missing(method, message)
26
+ @messages[method] ||= []
27
+ @messages[method] << message
28
+ end
29
+ end
30
+
31
+ describe "BatchIndexer" do
32
+ it "should work" do
33
+ Supernova::BatchIndexer.new(core, 10_000) do |indexer|
34
+ indexer.index_doc(:id => 1, :title_s => "Hello World")
35
+ end
36
+ core.commit
37
+ core.select["response"]["docs"].should == [{ "id" => "1", "title_s" => "Hello World"}]
38
+ end
39
+ end
40
+
41
+ describe "managing cores" do
42
+ it "allows managing cores" do
43
+ core.exists?.should == true
44
+ core.unload
45
+ core.exists?.should == false
46
+ core.create("/opt/solr", "/opt/solr/supernova_core")
47
+ core.exists?.should == true
48
+ end
49
+ end
50
+
51
+
52
+
53
+ it "uses the correct logging" do
54
+ catcher = LogCatcher.new
55
+ Supernova.logger = catcher
56
+ core.select
57
+ catcher.messages[:info].first.should match(/^SUPERNOVA REQUEST: GET/)
58
+ end
59
+
60
+ it "indexes docs" do
61
+ core.truncate
62
+ core.commit
63
+ core.index_docs([{ :id => 1, :title_s => "Title 1" }, { :id => 3, :title_s => "Title 3" }])
64
+ core.select["response"]["docs"].should be_empty
65
+ core.commit
66
+ core.select["response"]["docs"].should == [
67
+ { "id" => "1", "title_s" => "Title 1" },
68
+ { "id" => "3", "title_s" => "Title 3" },
69
+ ]
70
+ end
71
+
72
+ it "indexes single docs" do
73
+ core.truncate
74
+ core.commit
75
+ core.index_doc({ :id => 1, :title_s => "Title 1" })
76
+ core.select["response"]["docs"].should be_empty
77
+ core.commit
78
+ core.select["response"]["docs"].should == [
79
+ { "id" => "1", "title_s" => "Title 1" }
80
+ ]
81
+ end
82
+
83
+ it "raises an error when core does not exist" do
84
+ core.unload
85
+ lambda {
86
+ core.index_docs([{ :id => 1, :title_s => "Title 1" }, { :id => 3, :title_s => "Title 3" }])
87
+ }.should raise_error
88
+ end
89
+
90
+ it "raises an error when not able to index" do
91
+ lambda {
92
+ core.index_docs([{ :id => 1, :title_s => "Title 1" }, { :title_s => "Title 3" }])
93
+ }.should raise_error
94
+ end
95
+ end
@@ -0,0 +1,30 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib/supernova'))
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ require 'rspec'
5
+ require File.expand_path("../../lib/supernova.rb", __FILE__)
6
+ require "logger"
7
+ require "fileutils"
8
+ require "webmock/rspec"
9
+
10
+ def project_root
11
+ Pathname.new(File.expand_path("..", File.dirname(__FILE__)))
12
+ end
13
+
14
+ if defined?(Debugger) && Debugger.respond_to?(:settings)
15
+ Debugger.settings[:autolist] = 1
16
+ Debugger.settings[:autoeval] = true
17
+ end
18
+
19
+ # Requires supporting files with custom matchers and macros, etc,
20
+ # in ./support/ and its subdirectories.
21
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
22
+
23
+ RSpec.configure do |config|
24
+ config.run_all_when_everything_filtered = true
25
+ config.treat_symbols_as_metadata_keys_with_true_values = true
26
+
27
+ config.before(:each) do
28
+ WebMock.enable!
29
+ end
30
+ end
@@ -0,0 +1,69 @@
1
+ require "spec_helper"
2
+ require "supernova/batch_indexer"
3
+
4
+ describe "Supernova::BatchIndexer" do
5
+ let(:core) { double("core") }
6
+ let(:batch_indexer) { Supernova::BatchIndexer.new(core, 1000) }
7
+
8
+ it "can be initialized" do
9
+ indexer = Supernova::BatchIndexer.new(core)
10
+ indexer.instance_variable_get("@index").should == core
11
+ indexer.instance_variable_get("@batch_size").should == 1_000
12
+ indexer = Supernova::BatchIndexer.new(core, 2000)
13
+ indexer.instance_variable_get("@batch_size").should == 2_000
14
+ end
15
+
16
+ it "calls index docs with the correct amount of docs" do
17
+ doc1 = { :a => 1 }
18
+ doc2 = { :a => 2 }
19
+ doc3 = { :a => 3 }
20
+
21
+ core.should_receive(:index_docs).with([doc1, doc2])
22
+ core.should_receive(:index_docs).with([doc3])
23
+
24
+ indexer = Supernova::BatchIndexer.new(core, 2)
25
+ indexer.index_doc(doc1)
26
+ indexer.index_doc(doc2)
27
+ indexer.index_doc(doc3)
28
+ indexer.finish
29
+ end
30
+
31
+ it "calls index_docs when called with block" do
32
+ doc1 = { :a => 1 }
33
+ doc2 = { :a => 2 }
34
+ doc3 = { :a => 3 }
35
+
36
+ core.should_receive(:index_docs).with([doc1, doc2])
37
+ core.should_receive(:index_docs).with([doc3])
38
+
39
+ Supernova::BatchIndexer.new(core, 2) do |indexer|
40
+ indexer.index_doc(doc1)
41
+ indexer.index_doc(doc2)
42
+ indexer.index_doc(doc3)
43
+ end
44
+ end
45
+
46
+ describe "#do_index" do
47
+ it "calls index_docs" do
48
+ doc1 = { :a => 1 }
49
+ doc2 = { :a => 2 }
50
+ started = Time.now
51
+ finished = Time.now + 60
52
+ Time.stub(:now).and_return(started, finished)
53
+ batch_indexer.index_doc(doc1)
54
+ batch_indexer.index_doc(doc2)
55
+ core.should_receive(:index_docs).with([doc1, doc2])
56
+ batch_indexer.should_receive(:do_index_log_message).with(started, finished, [doc1, doc2]).and_return("log message")
57
+
58
+ Supernova.should_receive(:log).with("log message")
59
+ batch_indexer.send(:do_index)
60
+ end
61
+ end
62
+
63
+ it "generates the correct log message" do
64
+ started = Time.now
65
+ finished = Time.now + 2
66
+ docs = [1, 2, 3, 4, 5, 6]
67
+ batch_indexer.send(:do_index_log_message, started, finished, docs).should == "indexed 6 docs in 2.000 seconds (3.0 docs/second)"
68
+ end
69
+ end
@@ -0,0 +1,26 @@
1
+ require "spec_helper"
2
+ require "supernova/solr/cli"
3
+
4
+ describe "Supernova::Solr::CLI" do
5
+ let(:cli) { Supernova::Solr::CLI.new([]) }
6
+
7
+ it "can be initialized" do
8
+ cli = Supernova::Solr::CLI.new([])
9
+ end
10
+
11
+ describe "#start_solr_cmd" do
12
+ it "returns a string" do
13
+ cli.send(:start_solr_cmd).should be_kind_of(String)
14
+ end
15
+
16
+ it "returns the correct command" do
17
+ # >> #{log_path} 2>&1
18
+ cli.send(:start_solr_cmd).should include("cd /usr/local/Cellar/solr/3.5.0/libexec/example && /usr/bin/env java -Dsolr.solr.home=/opt/solr -jar start.jar > /opt/solr/solr.log 2>&1")
19
+ end
20
+
21
+ it "uses a custom solr bin when provided" do
22
+ cli = Supernova::Solr::CLI.new(["--solr-bin", "/path/to/solr/start.jar"])
23
+ cli.send(:start_solr_cmd).should include("cd /path/to/solr")
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,81 @@
1
+ require File.expand_path("../../../../spec/spec_helper", __FILE__)
2
+ require "solr/core"
3
+
4
+
5
+ describe "Supernova::Solr::Core" do
6
+ let(:url) { "http://path.to.solr:1122" }
7
+ let(:core_url) { "http://path.to.solr:1122/solr/my_core" }
8
+ let(:body) { { :a => 1 }.to_json }
9
+
10
+ describe "#initialize" do
11
+ it "can be initialized" do
12
+ core = Supernova::Solr::Core.new(url, "my_name")
13
+ core.solr_url.should == url
14
+ core.name.should == "my_name"
15
+ end
16
+
17
+ it "removes trailing slashes for the solr_url" do
18
+ Supernova::Solr::Core.new("http://path.to.solr:1122/solr/", "my_name").url.should == "http://path.to.solr:1122/solr/my_name"
19
+ end
20
+ end
21
+
22
+ it "returns the correct url" do
23
+ Supernova::Solr::Core.new(url, "my_name").url.should == "#{url}/my_name"
24
+ end
25
+
26
+ describe "#create" do
27
+ it "creates the correct core" do
28
+ instance_path = "/path/to/instance"
29
+ data_path = "/path/to/data"
30
+ stub_request(:get, "http://path.to.solr:1122/admin/cores?action=CREATE&dataDir=/path/to/data&instanceDir=/path/to/instance&name=my_name&wt=json")
31
+ .to_return(:status => 200, :body => body, :headers => {})
32
+ Supernova::Solr::Core.create(url, "my_name", instance_path, data_path)
33
+ end
34
+
35
+ it "creates the correct core" do
36
+ stub_request(:get, "http://path.to.solr:1122/admin/cores?action=CREATE&dataDir=/opt/solr/data/my_other_name&instanceDir=/opt/solr&name=my_other_name&wt=json")
37
+ .to_return(:status => 200, :body => body, :headers => {})
38
+ Supernova::Solr::Core.create(url, "my_other_name")
39
+ end
40
+ end
41
+
42
+ it "correctly queries for core status" do
43
+ instance_path = "/path/to/instance"
44
+ data_path = "/path/to/data"
45
+ stub_request(:get, "http://path.to.solr:1122/admin/cores?action=STATUS&core=my_name&wt=json")
46
+ .to_return(:status => 200, :body => body, :headers => {})
47
+ Supernova::Solr::Core.status(url, "my_name")
48
+ end
49
+
50
+ it "unloads the correct core" do
51
+ instance_path = "/path/to/instance"
52
+ data_path = "/path/to/data"
53
+ stub_request(:get, "http://path.to.solr:1122/admin/cores?action=UNLOAD&core=my_name&deleteIndex=true&wt=json")
54
+ .to_return(:status => 200, :body => body, :headers => {})
55
+ Supernova::Solr::Core.unload(url, "my_name")
56
+ end
57
+
58
+ it "delegates unload for instance methods" do
59
+ instance_path = "/path/to/instance"
60
+ data_path = "/path/to/data"
61
+ stub_request(:get, "http://path.to.solr:1122/admin/cores?action=UNLOAD&core=my_name&deleteIndex=true&wt=json")
62
+ .to_return(:status => 200, :body => body, :headers => {})
63
+ Supernova::Solr::Core.new(url, "my_name").unload
64
+ end
65
+
66
+ describe "#exists?" do
67
+ it "true when returned hash points to core" do
68
+ response = { "status" => { "my_name" => { "some" => "entry" } } }
69
+ stub_request(:get, "http://path.to.solr:1122/admin/cores?action=STATUS&core=my_name&wt=json").
70
+ to_return(:status => 200, :body => response.to_json, :headers => {})
71
+ Supernova::Solr::Core.new(url, "my_name").exists?.should == true
72
+ end
73
+
74
+ it "true when returned hash points to core" do
75
+ response = { "status" => { "my_name" => { } } }
76
+ stub_request(:get, "http://path.to.solr:1122/admin/cores?action=STATUS&core=my_name&wt=json").
77
+ to_return(:status => 200, :body => response.to_json, :headers => {})
78
+ Supernova::Solr::Core.new(url, "my_name").exists?.should == false
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+ require "supernova/solr/mapper"
3
+
4
+ describe "Supernova::Solr::Mapper" do
5
+ let(:mapping) do
6
+ { :name => :name_s, :login_count => :login_count_i }
7
+ end
8
+
9
+ it "sets the mapping" do
10
+ mapper = Supernova::Solr::Mapper.new(mapping)
11
+ mapper.send(:mapping).should == mapping.merge(:id => :id)
12
+ end
13
+
14
+ it "allows using integer, string et al" do
15
+ mapper = Supernova::Solr::Mapper.new(:name => :string, :number => :number_i)
16
+ mapper.send(:mapping).should == { :id => :id, :name => :name_s, :number => :number_i }
17
+ end
18
+
19
+ describe "#map" do
20
+ it "returns the correct hash" do
21
+ mapper = Supernova::Solr::Mapper.new(mapping)
22
+ mapper.map(:name => "Hans", :login_count => 10, :a => 1, :id => 11).should == { :name_s => "Hans", :login_count_i => 10, :id => 11 }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,144 @@
1
+ require File.expand_path("../../../../spec/spec_helper", __FILE__)
2
+ require "solr/server"
3
+
4
+ describe "Supernova::Solr::Server" do
5
+ let(:url) { "http://path.to.solr:112" }
6
+ let(:body) { "{\"responseHeader\":{\"status\":0,\"QTime\":3}}" }
7
+
8
+ describe "#initialize" do
9
+ it "can be initialized" do
10
+ Supernova::Solr::Server.new(url).url.should == url
11
+ end
12
+
13
+ it "strips the trailing slash" do
14
+ Supernova::Solr::Server.new("http://path.to.solr:112/").url.should == "http://path.to.solr:112"
15
+ end
16
+ end
17
+
18
+ describe "#core_names" do
19
+ it "returns the correct array" do
20
+ stub_request(:get, "http://path.to.solr:112/admin/cores?action=STATUS&wt=json")
21
+ .to_return(:status => 200, :body => project_root.join("spec/fixtures/cores_status.json").read, :headers => {})
22
+ Supernova::Solr::Server.core_names(url).should == %w(project_test supernova_test)
23
+ end
24
+ end
25
+
26
+ describe "post_update" do
27
+ it "returns a hash" do
28
+ response = { "a" => 1 }
29
+ stub_request(:post, "http://path.to.solr:112/update/update/json?wt=json")
30
+ .with(:headers => {'Content-Type'=>'application/json'})
31
+ .to_return(:status => 200, :body => response.to_json, :headers => {})
32
+ Supernova::Solr::Server.send(:post_update, "http://path.to.solr:112/update", "").should == response
33
+ end
34
+ end
35
+
36
+ it "indexes single docs" do
37
+ doc = { "id" => 1, "title_s" => "Peter" }
38
+ stub_request(:post, "http://path.to.solr:112/update/json?wt=json")
39
+ .with(
40
+ :body => "{\"add\":{\"doc\":{\"id\":1,\"title_s\":\"Peter\"}}}",
41
+ :headers => {'Content-Type'=>'application/json'}
42
+ )
43
+ .to_return(:status => 200, :body => body, :headers => {})
44
+ Supernova::Solr::Server.index_doc(url, doc)
45
+ end
46
+
47
+ describe "index_docs" do
48
+ it "indexes the correct rows" do
49
+ rows = [
50
+ { "id" => 1, "title_s" => "Peter" },
51
+ { "id" => 2, "title_s" => "Thomas" },
52
+ ]
53
+ stub_request(:post, "http://path.to.solr:112/update/json?wt=json")
54
+ .with(
55
+ :body => "{\"add\":{\"doc\":{\"id\":1,\"title_s\":\"Peter\"}}}\n{\"add\":{\"doc\":{\"id\":2,\"title_s\":\"Thomas\"}}}",
56
+ :headers => {'Content-Type'=>'application/json'}
57
+ )
58
+ .to_return(:status => 200, :body => body, :headers => {})
59
+ Supernova::Solr::Server.index_docs(url, rows)
60
+ end
61
+
62
+ it "indexes the correct rows with commit" do
63
+ rows = [
64
+ { "id" => 1, "title_s" => "Peter" },
65
+ { "id" => 2, "title_s" => "Thomas" },
66
+ ]
67
+ stub_request(:post, "http://path.to.solr:112/update/json?wt=json&commit=true")
68
+ .with(
69
+ :body => "{\"add\":{\"doc\":{\"id\":1,\"title_s\":\"Peter\"}}}\n{\"add\":{\"doc\":{\"id\":2,\"title_s\":\"Thomas\"}}}",
70
+ :headers => {'Content-Type'=>'application/json'}
71
+ )
72
+ .to_return(:status => 200, :body => body, :headers => {})
73
+ Supernova::Solr::Server.index_docs(url, rows, true)
74
+ end
75
+
76
+ it "indexes the correct rows with commitWithin" do
77
+ rows = [
78
+ { "id" => 1, "title_s" => "Peter" },
79
+ { "id" => 2, "title_s" => "Thomas" },
80
+ ]
81
+ stub_request(:post, "http://path.to.solr:112/update/json?wt=json&commitWithin=10000")
82
+ .with(
83
+ :body => "{\"add\":{\"doc\":{\"id\":1,\"title_s\":\"Peter\"}}}\n{\"add\":{\"doc\":{\"id\":2,\"title_s\":\"Thomas\"}}}",
84
+ :headers => {'Content-Type'=>'application/json'}
85
+ )
86
+ .to_return(:status => 200, :body => body, :headers => {})
87
+ Supernova::Solr::Server.index_docs(url, rows, 10_000)
88
+ end
89
+ end
90
+
91
+ describe "#select" do
92
+ let(:body) { { "a" => 1 }.to_json }
93
+ it "selects with default parameters" do
94
+ stub_request(:get, "http://path.to.solr:112/select?q=*:*&wt=json")
95
+ .to_return(:status => 200, :body => body, :headers => {})
96
+ Supernova::Solr::Server.select(url).should == { "a" => 1 }
97
+ end
98
+
99
+ it "delegates for instance methods" do
100
+ stub_request(:get, "http://path.to.solr:112/select?q=*:*&wt=json")
101
+ .to_return(:status => 200, :body => body, :headers => {})
102
+ Supernova::Solr::Server.new("http://path.to.solr:112").select.should == { "a" => 1 }
103
+ end
104
+ end
105
+
106
+ it "calls the commit statement" do
107
+ stub_request(:post, "http://path.to.solr:112/update/json?wt=json")
108
+ .with(:body => "{\"commit\":{}}", :headers => {'Content-Type'=>'application/json'})
109
+ .to_return(:status => 200, :body => body, :headers => {})
110
+ Supernova::Solr::Server.commit(url)
111
+ end
112
+
113
+ it "delegates commit for instance methods" do
114
+ stub_request(:post, "http://path.to.solr:112/my_name/update/json?wt=json")
115
+ .with(:body => "{\"commit\":{}}", :headers => {'Content-Type'=>'application/json'})
116
+ .to_return(:status => 200, :body => body, :headers => {})
117
+ core = Supernova::Solr::Server.new("#{url}/my_name")
118
+ core.url.should == "#{url}/my_name"
119
+ core.commit
120
+ end
121
+
122
+ it "calls the optimize statement" do
123
+ stub_request(:post, "http://path.to.solr:112/update/json?wt=json")
124
+ .with(:body => "{\"optimize\":{}}", :headers => {'Content-Type'=>'application/json'})
125
+ .to_return(:status => 200, :body => body, :headers => {})
126
+ Supernova::Solr::Server.optimize(url)
127
+ end
128
+
129
+ describe "#delete" do
130
+ it "deletes by query" do
131
+ stub_request(:post, "http://path.to.solr:112/update/json?wt=json")
132
+ .with(:body => "{\"delete\":{\"query\":\"id:1\"}}", :headers => {'Content-Type'=>'application/json'})
133
+ .to_return(:status => 200, :body => body, :headers => {})
134
+ Supernova::Solr::Server.delete_by_query(url, "id:1")
135
+ end
136
+
137
+ it "truncates the index" do
138
+ stub_request(:post, "http://path.to.solr:112/update/json?wt=json&commit=true")
139
+ .with(:body => "{\"delete\":{\"query\":\"*:*\"}}", :headers => {'Content-Type'=>'application/json'})
140
+ .to_return(:status => 200, :body => body, :headers => {})
141
+ Supernova::Solr::Server.truncate(url, true)
142
+ end
143
+ end
144
+ end