backupify-rsolr-nokogiri 0.12.1.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.
- data/LICENSE +13 -0
- data/README.rdoc +129 -0
- data/Rakefile +14 -0
- data/VERSION +1 -0
- data/lib/rsolr.rb +50 -0
- data/lib/rsolr/client.rb +114 -0
- data/lib/rsolr/connection.rb +9 -0
- data/lib/rsolr/connection/net_http.rb +48 -0
- data/lib/rsolr/connection/requestable.rb +43 -0
- data/lib/rsolr/connection/utils.rb +73 -0
- data/lib/rsolr/message.rb +8 -0
- data/lib/rsolr/message/document.rb +48 -0
- data/lib/rsolr/message/field.rb +20 -0
- data/lib/rsolr/message/generator.rb +91 -0
- data/spec/api/client_spec.rb +93 -0
- data/spec/api/connection/net_http_spec.rb +148 -0
- data/spec/api/connection/requestable_spec.rb +92 -0
- data/spec/api/connection/utils_spec.rb +84 -0
- data/spec/api/message_spec.rb +120 -0
- data/spec/api/rsolr_spec.rb +29 -0
- data/spec/spec_helper.rb +1 -0
- data/tasks/rdoc.rake +9 -0
- data/tasks/spec.rake +42 -0
- metadata +91 -0
@@ -0,0 +1,84 @@
|
|
1
|
+
describe RSolr::Connection::Utils do
|
2
|
+
|
3
|
+
# calls #let to set "utils" as a method accessor
|
4
|
+
module UtilsHelper
|
5
|
+
def self.included base
|
6
|
+
base.let(:utils){ nil.extend RSolr::Connection::Utils }
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'hash_to_query method' do
|
11
|
+
|
12
|
+
include UtilsHelper
|
13
|
+
|
14
|
+
it "should build a query string from a hash, converting arrays to multi-params and removing nils/emptys" do
|
15
|
+
test_params = {
|
16
|
+
:z=>'should be whatever',
|
17
|
+
:q=>'test',
|
18
|
+
:item => [1, 2, 3, nil],
|
19
|
+
:nil=>nil
|
20
|
+
}
|
21
|
+
result = utils.hash_to_query(test_params)
|
22
|
+
[/z=should\+be\+whatever/, /q=test/, /item=1/, /item=2/, /item=3/].each do |regexp|
|
23
|
+
result.should match(regexp)
|
24
|
+
end
|
25
|
+
result.split('&').size.should == 5
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should escape &' do
|
29
|
+
utils.hash_to_query(:fq => "&").should == 'fq=%26'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should convert spaces to +' do
|
33
|
+
utils.hash_to_query(:fq => "me and you").should == 'fq=me+and+you'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should escape comlex queries, part 1' do
|
37
|
+
my_params = {'fq' => '{!raw f=field_name}crazy+\"field+value'}
|
38
|
+
expected = 'fq=%7B%21raw+f%3Dfield_name%7Dcrazy%2B%5C%22field%2Bvalue'
|
39
|
+
utils.hash_to_query(my_params).should == expected
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should escape comlex queries, part 2' do
|
43
|
+
my_params = {'q' => '+popularity:[10 TO *] +section:0'}
|
44
|
+
expected = 'q=%2Bpopularity%3A%5B10+TO+%2A%5D+%2Bsection%3A0'
|
45
|
+
utils.hash_to_query(my_params).should == expected
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'escape method' do
|
51
|
+
|
52
|
+
include UtilsHelper
|
53
|
+
|
54
|
+
it 'should escape properly' do
|
55
|
+
utils.escape('+').should == '%2B'
|
56
|
+
utils.escape('This is a test').should == 'This+is+a+test'
|
57
|
+
utils.escape('<>/\\').should == '%3C%3E%2F%5C'
|
58
|
+
utils.escape('"').should == '%22'
|
59
|
+
utils.escape(':').should == '%3A'
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should escape brackets' do
|
63
|
+
utils.escape('{').should == '%7B'
|
64
|
+
utils.escape('}').should == '%7D'
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should escape exclamation marks!' do
|
68
|
+
utils.escape('!').should == '%21'
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'build_url method' do
|
74
|
+
|
75
|
+
include UtilsHelper
|
76
|
+
|
77
|
+
it 'should build correctly' do
|
78
|
+
url = utils.build_url '/solr/select', {:q=>'test'}, 'blah=blah'
|
79
|
+
url.should == '/solr/select?blah=blah&q=test'
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
describe RSolr::Message do
|
2
|
+
|
3
|
+
let(:generator){ RSolr::Message::Generator.new }
|
4
|
+
|
5
|
+
# call all of the simple methods...
|
6
|
+
# make sure the xml string is valid
|
7
|
+
# ensure the class is actually Solr::XML
|
8
|
+
[:optimize, :rollback, :commit].each do |meth|
|
9
|
+
it "#{meth} should generator xml" do
|
10
|
+
result = generator.send(meth)
|
11
|
+
result.should match(Regexp.escape("<#{meth}/>"))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context :add do
|
16
|
+
|
17
|
+
it 'should yield a Message::Document object when #add is called with a block' do
|
18
|
+
documents = [{:id=>1, :name=>'sam', :cat=>['cat 1', 'cat 2']}]
|
19
|
+
add_attrs = {:boost=>200.00}
|
20
|
+
result = generator.add(documents, add_attrs) do |doc|
|
21
|
+
doc.field_by_name(:name).attrs[:boost] = 10
|
22
|
+
doc.fields.size.should == 4
|
23
|
+
doc.fields_by_name(:cat).size.should == 2
|
24
|
+
end
|
25
|
+
result.should match(%r(name="cat">cat 1</field>))
|
26
|
+
result.should match(%r(name="cat">cat 2</field>))
|
27
|
+
result.should match(%r(<add boost="200.0">))
|
28
|
+
result.should match(%r(boost="10"))
|
29
|
+
result.should match(%r(<field name="id">1</field>))
|
30
|
+
end
|
31
|
+
|
32
|
+
# add a single hash ("doc")
|
33
|
+
it 'should create an add from a hash' do
|
34
|
+
data = {
|
35
|
+
:id=>1,
|
36
|
+
:name=>'matt'
|
37
|
+
}
|
38
|
+
result = generator.add(data)
|
39
|
+
result.should match(/<field name="name">matt<\/field>/)
|
40
|
+
result.should match(/<field name="id">1<\/field>/)
|
41
|
+
end
|
42
|
+
|
43
|
+
# add an array of hashes
|
44
|
+
it 'should create many adds from an array of hashes' do
|
45
|
+
data = [
|
46
|
+
{
|
47
|
+
:id=>1,
|
48
|
+
:name=>'matt'
|
49
|
+
},
|
50
|
+
{
|
51
|
+
:id=>2,
|
52
|
+
:name=>'sam'
|
53
|
+
}
|
54
|
+
]
|
55
|
+
message = generator.add(data)
|
56
|
+
expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><add><doc><field name=\"id\">1</field><field name=\"name\">matt</field></doc><doc><field name=\"id\">2</field><field name=\"name\">sam</field></doc></add>"
|
57
|
+
message.should match(/<field name="name">matt<\/field>/)
|
58
|
+
message.should match(/<field name="name">sam<\/field>/)
|
59
|
+
end
|
60
|
+
|
61
|
+
# multiValue field support test, thanks to Fouad Mardini!
|
62
|
+
it 'should create multiple fields from array values' do
|
63
|
+
data = {
|
64
|
+
:id => 1,
|
65
|
+
:name => ['matt1', 'matt2']
|
66
|
+
}
|
67
|
+
result = generator.add(data)
|
68
|
+
result.should match(/<field name="name">matt1<\/field>/)
|
69
|
+
result.should match(/<field name="name">matt2<\/field>/)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should create an add from a single Message::Document' do
|
73
|
+
document = RSolr::Message::Document.new
|
74
|
+
document.add_field('id', 1)
|
75
|
+
document.add_field('name', 'matt', :boost => 2.0)
|
76
|
+
result = generator.add(document)
|
77
|
+
result.should match(Regexp.escape('<?xml version="1.0" encoding="UTF-8"?>'))
|
78
|
+
result.should match(/<field name="id">1<\/field>/)
|
79
|
+
result.should match Regexp.escape('boost="2.0"')
|
80
|
+
result.should match Regexp.escape('name="name"')
|
81
|
+
result.should match Regexp.escape('matt</field>')
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should create adds from multiple Message::Documents' do
|
85
|
+
documents = (1..2).map do |i|
|
86
|
+
doc = RSolr::Message::Document.new
|
87
|
+
doc.add_field('id', i)
|
88
|
+
doc.add_field('name', "matt#{i}")
|
89
|
+
doc
|
90
|
+
end
|
91
|
+
result = generator.add(documents)
|
92
|
+
result.should match(/<field name="name">matt1<\/field>/)
|
93
|
+
result.should match(/<field name="name">matt2<\/field>/)
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
context :delete_by_id do
|
99
|
+
|
100
|
+
it 'should create a doc id delete' do
|
101
|
+
generator.delete_by_id(10).should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<delete>\n<id>10</id>\n</delete>\n"
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should create many doc id deletes' do
|
105
|
+
generator.delete_by_id([1, 2, 3]).should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<delete>\n<id>1</id>\n<id>2</id>\n<id>3</id>\n</delete>\n"
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
context :delete_by_query do
|
111
|
+
it 'should create a query delete' do
|
112
|
+
generator.delete_by_query('status:"LOST"').should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<delete>\n<query>status:\"LOST\"</query>\n</delete>\n"
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should create many query deletes' do
|
116
|
+
generator.delete_by_query(['status:"LOST"', 'quantity:0']).should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<delete>\n<query>status:\"LOST\"</query>\n<query>quantity:0</query>\n</delete>\n"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
describe RSolr do
|
2
|
+
|
3
|
+
context :connect do
|
4
|
+
|
5
|
+
it 'does not care about valid/live URLs yet' do
|
6
|
+
lambda{RSolr.connect :url=>'http://blah.blah.blah:666/solr'}.should_not raise_error
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should create an instance of RSolr::Connection::NetHttp as the #connection' do
|
10
|
+
expected_class = RSolr::Connection::NetHttp
|
11
|
+
RSolr.connect.connection.should be_a(expected_class)
|
12
|
+
RSolr.connect(:url=>'blah').connection.should be_a(expected_class)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
context :escape do
|
18
|
+
|
19
|
+
it "should escape properly" do
|
20
|
+
RSolr.escape('Trying & % different "characters" here!').should == "Trying\\ \\&\\ \\%\\ different\\ \\\"characters\\\"\\ here\\!"
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should escape' do
|
24
|
+
expected = "http\\:\\/\\/lucene\\.apache\\.org\\/solr"
|
25
|
+
RSolr.escape("http://lucene.apache.org/solr").should == expected
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'rsolr'))
|
data/tasks/rdoc.rake
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# Rdoc
|
2
|
+
desc 'Generate documentation for the rsolr gem.'
|
3
|
+
Rake::RDocTask.new(:doc) do |rdoc|
|
4
|
+
rdoc.rdoc_dir = 'doc'
|
5
|
+
rdoc.title = 'RSolr'
|
6
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
7
|
+
rdoc.rdoc_files.include('README.rdoc')
|
8
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
9
|
+
end
|
data/tasks/spec.rake
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
gem 'rspec'
|
2
|
+
|
3
|
+
# $stderr.puts `gem list`
|
4
|
+
|
5
|
+
require 'spec'
|
6
|
+
require 'spec/rake/spectask'
|
7
|
+
|
8
|
+
namespace :spec do
|
9
|
+
|
10
|
+
namespace :ruby do
|
11
|
+
desc 'run api specs through the Ruby implementations'
|
12
|
+
task :api do
|
13
|
+
puts "Ruby 1.8.7"
|
14
|
+
puts `rake spec:api`
|
15
|
+
puts "Ruby 1.9"
|
16
|
+
puts `rake1.9 spec:api`
|
17
|
+
puts "JRuby"
|
18
|
+
puts `jruby -S rake spec:api`
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'run api specs (mock out Solr dependency)'
|
23
|
+
Spec::Rake::SpecTask.new(:api) do |t|
|
24
|
+
|
25
|
+
t.spec_files = [File.join('spec', 'spec_helper.rb')]
|
26
|
+
t.spec_files += FileList[File.join('spec', 'api', '**', '*_spec.rb')]
|
27
|
+
|
28
|
+
t.verbose = true
|
29
|
+
t.spec_opts = ['--color']
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'run integration specs'
|
33
|
+
Spec::Rake::SpecTask.new(:integration) do |t|
|
34
|
+
|
35
|
+
t.spec_files = [File.join('spec', 'spec_helper.rb')]
|
36
|
+
t.spec_files += FileList[File.join('spec', 'integration', '**', '*_spec.rb')]
|
37
|
+
|
38
|
+
t.verbose = true
|
39
|
+
t.spec_opts = ['--color']
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: backupify-rsolr-nokogiri
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.12.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dave Benvenuti
|
9
|
+
- Ernie Makris
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2011-08-09 00:00:00.000000000Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: nokogiri
|
17
|
+
requirement: &2156327320 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.3.3
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2156327320
|
26
|
+
description: ''
|
27
|
+
email: davebenvenuti@gmail.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files:
|
31
|
+
- LICENSE
|
32
|
+
- README.rdoc
|
33
|
+
files:
|
34
|
+
- LICENSE
|
35
|
+
- README.rdoc
|
36
|
+
- VERSION
|
37
|
+
- lib/rsolr.rb
|
38
|
+
- lib/rsolr/client.rb
|
39
|
+
- lib/rsolr/connection.rb
|
40
|
+
- lib/rsolr/connection/net_http.rb
|
41
|
+
- lib/rsolr/connection/requestable.rb
|
42
|
+
- lib/rsolr/connection/utils.rb
|
43
|
+
- lib/rsolr/message.rb
|
44
|
+
- lib/rsolr/message/document.rb
|
45
|
+
- lib/rsolr/message/field.rb
|
46
|
+
- lib/rsolr/message/generator.rb
|
47
|
+
- spec/api/client_spec.rb
|
48
|
+
- spec/api/connection/net_http_spec.rb
|
49
|
+
- spec/api/connection/requestable_spec.rb
|
50
|
+
- spec/api/connection/utils_spec.rb
|
51
|
+
- spec/api/message_spec.rb
|
52
|
+
- spec/api/rsolr_spec.rb
|
53
|
+
- spec/spec_helper.rb
|
54
|
+
- Rakefile
|
55
|
+
- tasks/spec.rake
|
56
|
+
- tasks/rdoc.rake
|
57
|
+
homepage: http://github.com/backupify/rsolr
|
58
|
+
licenses: []
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.8.7
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: A fork of rsolr that uses nokogiri in place of builder for xml generation
|
81
|
+
test_files:
|
82
|
+
- spec/api/client_spec.rb
|
83
|
+
- spec/api/connection/net_http_spec.rb
|
84
|
+
- spec/api/connection/requestable_spec.rb
|
85
|
+
- spec/api/connection/utils_spec.rb
|
86
|
+
- spec/api/message_spec.rb
|
87
|
+
- spec/api/rsolr_spec.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
- Rakefile
|
90
|
+
- tasks/spec.rake
|
91
|
+
- tasks/rdoc.rake
|