rsolr 0.12.0 → 2.6.0
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.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +29 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/CHANGES.txt +63 -260
- data/Gemfile +13 -0
- data/README.rdoc +177 -63
- data/Rakefile +19 -0
- data/lib/rsolr/char.rb +6 -0
- data/lib/rsolr/client.rb +344 -86
- data/lib/rsolr/document.rb +66 -0
- data/lib/rsolr/error.rb +182 -0
- data/lib/rsolr/field.rb +87 -0
- data/lib/rsolr/generator.rb +5 -0
- data/lib/rsolr/json.rb +60 -0
- data/lib/rsolr/response.rb +95 -0
- data/lib/rsolr/uri.rb +25 -0
- data/lib/rsolr/version.rb +7 -0
- data/lib/rsolr/xml.rb +150 -0
- data/lib/rsolr.rb +47 -35
- data/rsolr.gemspec +44 -31
- data/spec/api/client_spec.rb +423 -0
- data/spec/api/document_spec.rb +48 -0
- data/spec/api/error_spec.rb +158 -0
- data/spec/api/json_spec.rb +248 -0
- data/spec/api/pagination_spec.rb +31 -0
- data/spec/api/rsolr_spec.rb +31 -0
- data/spec/api/uri_spec.rb +37 -0
- data/spec/api/xml_spec.rb +255 -0
- data/spec/fixtures/basic_configs/_rest_managed.json +1 -0
- data/spec/fixtures/basic_configs/currency.xml +67 -0
- data/spec/fixtures/basic_configs/lang/stopwords_en.txt +54 -0
- data/spec/fixtures/basic_configs/protwords.txt +21 -0
- data/spec/fixtures/basic_configs/schema.xml +530 -0
- data/spec/fixtures/basic_configs/solrconfig.xml +572 -0
- data/spec/fixtures/basic_configs/stopwords.txt +14 -0
- data/spec/fixtures/basic_configs/synonyms.txt +29 -0
- data/spec/integration/solr5_spec.rb +38 -0
- data/spec/lib/rsolr/client_spec.rb +19 -0
- data/spec/spec_helper.rb +94 -0
- metadata +228 -54
- data/lib/rsolr/connection/net_http.rb +0 -48
- data/lib/rsolr/connection/requestable.rb +0 -43
- data/lib/rsolr/connection/utils.rb +0 -73
- data/lib/rsolr/connection.rb +0 -9
- data/lib/rsolr/message/document.rb +0 -48
- data/lib/rsolr/message/field.rb +0 -20
- data/lib/rsolr/message/generator.rb +0 -89
- data/lib/rsolr/message.rb +0 -8
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start do
|
3
|
+
add_filter "/spec/"
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'rsolr'
|
7
|
+
require 'rspec'
|
8
|
+
|
9
|
+
FIXTURES_DIR = File.expand_path("fixtures", File.dirname(__FILE__))
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
# rspec-expectations config goes here. You can use an alternate
|
13
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
14
|
+
# assertions if you prefer.
|
15
|
+
config.expect_with :rspec do |expectations|
|
16
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
17
|
+
# and `failure_message` of custom matchers include text for helper methods
|
18
|
+
# defined using `chain`, e.g.:
|
19
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
20
|
+
# # => "be bigger than 2 and smaller than 4"
|
21
|
+
# ...rather than:
|
22
|
+
# # => "be bigger than 2"
|
23
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
24
|
+
end
|
25
|
+
|
26
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
27
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
28
|
+
config.mock_with :rspec do |mocks|
|
29
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
30
|
+
# a real object. This is generally recommended, and will default to
|
31
|
+
# `true` in RSpec 4.
|
32
|
+
mocks.verify_partial_doubles = true
|
33
|
+
end
|
34
|
+
|
35
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
36
|
+
# have no way to turn it off -- the option exists only for backwards
|
37
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
38
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
39
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
40
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
41
|
+
|
42
|
+
# The settings below are suggested to provide a good initial experience
|
43
|
+
# with RSpec, but feel free to customize to your heart's content.
|
44
|
+
|
45
|
+
# This allows you to limit a spec run to individual examples or groups
|
46
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
47
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
48
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
49
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
50
|
+
config.filter_run_when_matching :focus
|
51
|
+
|
52
|
+
# Allows RSpec to persist some state between runs in order to support
|
53
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
54
|
+
# you configure your source control system to ignore this file.
|
55
|
+
config.example_status_persistence_file_path = 'spec/examples.txt'
|
56
|
+
|
57
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
58
|
+
# recommended. For more details, see:
|
59
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
60
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
61
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
62
|
+
config.disable_monkey_patching!
|
63
|
+
|
64
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
65
|
+
# be too noisy due to issues in dependencies.
|
66
|
+
config.warnings = true
|
67
|
+
|
68
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
69
|
+
# file, and it's useful to allow more verbose output when running an
|
70
|
+
# individual spec file.
|
71
|
+
if config.files_to_run.one?
|
72
|
+
# Use the documentation formatter for detailed output,
|
73
|
+
# unless a formatter has already been configured
|
74
|
+
# (e.g. via a command-line flag).
|
75
|
+
config.default_formatter = 'doc'
|
76
|
+
end
|
77
|
+
|
78
|
+
# Print the 10 slowest examples and example groups at the
|
79
|
+
# end of the spec run, to help surface which specs are running
|
80
|
+
# particularly slow.
|
81
|
+
config.profile_examples = 10
|
82
|
+
|
83
|
+
# Run specs in random order to surface order dependencies. If you find an
|
84
|
+
# order dependency and want to debug it, you can fix the order by providing
|
85
|
+
# the seed, which is printed after each run.
|
86
|
+
# --seed 1234
|
87
|
+
config.order = :random
|
88
|
+
|
89
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
90
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
91
|
+
# test failures related to randomization by passing the same `--seed` value
|
92
|
+
# as the one that triggered the failure.
|
93
|
+
Kernel.srand config.seed
|
94
|
+
end
|
metadata
CHANGED
@@ -1,70 +1,244 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsolr
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
7
|
-
-
|
8
|
-
|
6
|
+
authors:
|
7
|
+
- Antoine Latter
|
8
|
+
- Dmitry Lihachev
|
9
|
+
- Lucas Souza
|
10
|
+
- Peter Kieltyka
|
11
|
+
- Rob Di Marco
|
12
|
+
- Magnus Bergmark
|
13
|
+
- Jonathan Rochkind
|
14
|
+
- Chris Beer
|
15
|
+
- Craig Smith
|
16
|
+
- Randy Souza
|
17
|
+
- Colin Steele
|
18
|
+
- Peter Kieltyka
|
19
|
+
- Lorenzo Riccucci
|
20
|
+
- Mike Perham
|
21
|
+
- Mat Brown
|
22
|
+
- Shairon Toledo
|
23
|
+
- Matthew Rudy
|
24
|
+
- Fouad Mardini
|
25
|
+
- Jeremy Hinegardner
|
26
|
+
- Nathan Witmer
|
27
|
+
- Naomi Dushay
|
28
|
+
- '"shima"'
|
29
|
+
autorequire:
|
9
30
|
bindir: bin
|
10
31
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
32
|
+
date: 2024-03-25 00:00:00.000000000 Z
|
33
|
+
dependencies:
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: builder
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.1.2
|
41
|
+
type: :runtime
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.1.2
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: faraday
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.9'
|
55
|
+
- - "!="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 2.0.0
|
58
|
+
- - "<"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3'
|
61
|
+
type: :runtime
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0.9'
|
68
|
+
- - "!="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 2.0.0
|
71
|
+
- - "<"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '3'
|
74
|
+
- !ruby/object:Gem::Dependency
|
75
|
+
name: activesupport
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
type: :development
|
82
|
+
prerelease: false
|
83
|
+
version_requirements: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
- !ruby/object:Gem::Dependency
|
89
|
+
name: nokogiri
|
90
|
+
requirement: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 1.4.0
|
95
|
+
type: :development
|
96
|
+
prerelease: false
|
97
|
+
version_requirements: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.4.0
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: rake
|
104
|
+
requirement: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '10.0'
|
109
|
+
type: :development
|
110
|
+
prerelease: false
|
111
|
+
version_requirements: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '10.0'
|
116
|
+
- !ruby/object:Gem::Dependency
|
117
|
+
name: rdoc
|
118
|
+
requirement: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '4.0'
|
123
|
+
type: :development
|
124
|
+
prerelease: false
|
125
|
+
version_requirements: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '4.0'
|
130
|
+
- !ruby/object:Gem::Dependency
|
131
|
+
name: rspec
|
132
|
+
requirement: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - "~>"
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '3.0'
|
137
|
+
type: :development
|
138
|
+
prerelease: false
|
139
|
+
version_requirements: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - "~>"
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '3.0'
|
144
|
+
- !ruby/object:Gem::Dependency
|
145
|
+
name: simplecov
|
146
|
+
requirement: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
type: :development
|
152
|
+
prerelease: false
|
153
|
+
version_requirements: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: solr_wrapper
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
type: :development
|
166
|
+
prerelease: false
|
167
|
+
version_requirements: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - ">="
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0'
|
172
|
+
description: RSolr aims to provide a simple and extensible library for working with
|
173
|
+
Solr
|
174
|
+
email:
|
175
|
+
- goodieboy@gmail.com
|
18
176
|
executables: []
|
19
|
-
|
20
177
|
extensions: []
|
21
|
-
|
22
|
-
|
23
|
-
-
|
24
|
-
-
|
178
|
+
extra_rdoc_files: []
|
179
|
+
files:
|
180
|
+
- ".github/workflows/ruby.yml"
|
181
|
+
- ".gitignore"
|
182
|
+
- ".rspec"
|
25
183
|
- CHANGES.txt
|
26
|
-
|
27
|
-
- CHANGES.txt
|
28
|
-
- lib/rsolr/client.rb
|
29
|
-
- lib/rsolr/connection/net_http.rb
|
30
|
-
- lib/rsolr/connection/requestable.rb
|
31
|
-
- lib/rsolr/connection/utils.rb
|
32
|
-
- lib/rsolr/connection.rb
|
33
|
-
- lib/rsolr/message/document.rb
|
34
|
-
- lib/rsolr/message/field.rb
|
35
|
-
- lib/rsolr/message/generator.rb
|
36
|
-
- lib/rsolr/message.rb
|
37
|
-
- lib/rsolr.rb
|
184
|
+
- Gemfile
|
38
185
|
- LICENSE
|
39
186
|
- README.rdoc
|
187
|
+
- Rakefile
|
188
|
+
- lib/rsolr.rb
|
189
|
+
- lib/rsolr/char.rb
|
190
|
+
- lib/rsolr/client.rb
|
191
|
+
- lib/rsolr/document.rb
|
192
|
+
- lib/rsolr/error.rb
|
193
|
+
- lib/rsolr/field.rb
|
194
|
+
- lib/rsolr/generator.rb
|
195
|
+
- lib/rsolr/json.rb
|
196
|
+
- lib/rsolr/response.rb
|
197
|
+
- lib/rsolr/uri.rb
|
198
|
+
- lib/rsolr/version.rb
|
199
|
+
- lib/rsolr/xml.rb
|
40
200
|
- rsolr.gemspec
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
201
|
+
- spec/api/client_spec.rb
|
202
|
+
- spec/api/document_spec.rb
|
203
|
+
- spec/api/error_spec.rb
|
204
|
+
- spec/api/json_spec.rb
|
205
|
+
- spec/api/pagination_spec.rb
|
206
|
+
- spec/api/rsolr_spec.rb
|
207
|
+
- spec/api/uri_spec.rb
|
208
|
+
- spec/api/xml_spec.rb
|
209
|
+
- spec/fixtures/basic_configs/_rest_managed.json
|
210
|
+
- spec/fixtures/basic_configs/currency.xml
|
211
|
+
- spec/fixtures/basic_configs/lang/stopwords_en.txt
|
212
|
+
- spec/fixtures/basic_configs/protwords.txt
|
213
|
+
- spec/fixtures/basic_configs/schema.xml
|
214
|
+
- spec/fixtures/basic_configs/solrconfig.xml
|
215
|
+
- spec/fixtures/basic_configs/stopwords.txt
|
216
|
+
- spec/fixtures/basic_configs/synonyms.txt
|
217
|
+
- spec/integration/solr5_spec.rb
|
218
|
+
- spec/lib/rsolr/client_spec.rb
|
219
|
+
- spec/spec_helper.rb
|
220
|
+
homepage: https://github.com/rsolr/rsolr
|
221
|
+
licenses:
|
222
|
+
- Apache-2.0
|
223
|
+
metadata: {}
|
224
|
+
post_install_message:
|
46
225
|
rdoc_options: []
|
47
|
-
|
48
|
-
require_paths:
|
226
|
+
require_paths:
|
49
227
|
- lib
|
50
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
228
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
229
|
+
requirements:
|
52
230
|
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version:
|
55
|
-
|
56
|
-
|
57
|
-
requirements:
|
231
|
+
- !ruby/object:Gem::Version
|
232
|
+
version: 1.9.3
|
233
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
234
|
+
requirements:
|
58
235
|
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version:
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
signing_key:
|
67
|
-
specification_version: 3
|
236
|
+
- !ruby/object:Gem::Version
|
237
|
+
version: '0'
|
238
|
+
requirements:
|
239
|
+
- Apache Solr
|
240
|
+
rubygems_version: 3.4.10
|
241
|
+
signing_key:
|
242
|
+
specification_version: 4
|
68
243
|
summary: A Ruby client for Apache Solr
|
69
244
|
test_files: []
|
70
|
-
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
|
3
|
-
#
|
4
|
-
# Connection for standard HTTP Solr server
|
5
|
-
#
|
6
|
-
class RSolr::Connection::NetHttp
|
7
|
-
|
8
|
-
include RSolr::Connection::Requestable
|
9
|
-
|
10
|
-
def connection
|
11
|
-
@connection ||= Net::HTTP.new(@uri.host, @uri.port)
|
12
|
-
end
|
13
|
-
|
14
|
-
def get path, params={}
|
15
|
-
url = self.build_url path, params
|
16
|
-
net_http_response = self.connection.get url
|
17
|
-
create_http_context net_http_response, url, path, params
|
18
|
-
end
|
19
|
-
|
20
|
-
def post path, data, params={}, headers={}
|
21
|
-
url = self.build_url path, params
|
22
|
-
net_http_response = self.connection.post url, data, headers
|
23
|
-
create_http_context net_http_response, url, path, params, data, headers
|
24
|
-
end
|
25
|
-
|
26
|
-
def create_http_context net_http_response, url, path, params, data=nil, headers={}
|
27
|
-
full_url = "#{@uri.scheme}://#{@uri.host}"
|
28
|
-
full_url += @uri.port ? ":#{@uri.port}" : ''
|
29
|
-
full_url += url
|
30
|
-
{
|
31
|
-
:status_code=>net_http_response.code.to_i,
|
32
|
-
:url=>full_url,
|
33
|
-
:body=> encode_utf8(net_http_response.body),
|
34
|
-
:path=>path,
|
35
|
-
:params=>params,
|
36
|
-
:data=>data,
|
37
|
-
:headers=>headers,
|
38
|
-
:message => net_http_response.message
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
# accepts a path/string and optional hash of query params
|
43
|
-
def build_url path, params={}
|
44
|
-
full_path = @uri.path + path
|
45
|
-
super full_path, params, @uri.query
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# A module that defines the interface and top-level logic for http based connection classes.
|
2
|
-
module RSolr::Connection::Requestable
|
3
|
-
|
4
|
-
include RSolr::Connection::Utils
|
5
|
-
|
6
|
-
attr_reader :opts, :uri
|
7
|
-
|
8
|
-
# opts can have:
|
9
|
-
# :url => 'http://localhost:8080/solr'
|
10
|
-
def initialize opts={}
|
11
|
-
opts[:url] ||= 'http://127.0.0.1:8983/solr'
|
12
|
-
@opts = opts
|
13
|
-
@uri = URI.parse opts[:url]
|
14
|
-
end
|
15
|
-
|
16
|
-
# send a request to the connection
|
17
|
-
# request '/select', :q=>'*:*'
|
18
|
-
#
|
19
|
-
# request '/update', {:wt=>:xml}, '</commit>'
|
20
|
-
#
|
21
|
-
# force a post where the post body is the param query
|
22
|
-
# request '/update', "<optimize/>", :method=>:post
|
23
|
-
#
|
24
|
-
def request path, params={}, *extra
|
25
|
-
opts = extra[-1].kind_of?(Hash) ? extra.pop : {}
|
26
|
-
data = extra[0]
|
27
|
-
# force a POST, use the query string as the POST body
|
28
|
-
if opts[:method] == :post and data.to_s.empty?
|
29
|
-
http_context = self.post(path, hash_to_query(params), {}, {'Content-Type' => 'application/x-www-form-urlencoded'})
|
30
|
-
else
|
31
|
-
if data
|
32
|
-
# standard POST, using "data" as the POST body
|
33
|
-
http_context = self.post(path, data, params, {"Content-Type" => 'text/xml; charset=utf-8'})
|
34
|
-
else
|
35
|
-
# standard GET
|
36
|
-
http_context = self.get(path, params)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
raise RSolr::RequestError.new("Solr Response: #{http_context[:message]}") unless http_context[:status_code] == 200
|
40
|
-
http_context
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
# Helpful utility methods for building queries to a Solr server
|
2
|
-
# This includes helpers that the Direct connection can use.
|
3
|
-
module RSolr::Connection::Utils
|
4
|
-
|
5
|
-
# Performs URI escaping so that you can construct proper
|
6
|
-
# query strings faster. Use this rather than the cgi.rb
|
7
|
-
# version since it's faster. (Stolen from Rack).
|
8
|
-
def escape(s)
|
9
|
-
s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/n) {
|
10
|
-
#'%'+$1.unpack('H2'*$1.size).join('%').upcase
|
11
|
-
'%'+$1.unpack('H2'*bytesize($1)).join('%').upcase
|
12
|
-
}.tr(' ', '+')
|
13
|
-
end
|
14
|
-
|
15
|
-
# encodes the string as utf-8 in Ruby 1.9
|
16
|
-
# returns the unaltered string in Ruby 1.8
|
17
|
-
def encode_utf8 string
|
18
|
-
(string.respond_to?(:force_encoding) and string.respond_to?(:encoding)) ?
|
19
|
-
string.force_encoding(Encoding::UTF_8) : string
|
20
|
-
end
|
21
|
-
|
22
|
-
# Return the bytesize of String; uses String#length under Ruby 1.8 and
|
23
|
-
# String#bytesize under 1.9.
|
24
|
-
if ''.respond_to?(:bytesize)
|
25
|
-
def bytesize(string)
|
26
|
-
string.bytesize
|
27
|
-
end
|
28
|
-
else
|
29
|
-
def bytesize(string)
|
30
|
-
string.size
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# creates and returns a url as a string
|
35
|
-
# "url" is the base url
|
36
|
-
# "params" is an optional hash of GET style query params
|
37
|
-
# "string_query" is an extra query string that will be appended to the
|
38
|
-
# result of "url" and "params".
|
39
|
-
def build_url url='', params={}, string_query=''
|
40
|
-
queries = [string_query, hash_to_query(params)]
|
41
|
-
queries.delete_if{|i| i.to_s.empty?}
|
42
|
-
url += "?#{queries.join('&')}" unless queries.empty?
|
43
|
-
url
|
44
|
-
end
|
45
|
-
|
46
|
-
# converts a key value pair to an escaped string:
|
47
|
-
# Example:
|
48
|
-
# build_param(:id, 1) == "id=1"
|
49
|
-
def build_param(k,v)
|
50
|
-
"#{escape(k)}=#{escape(v)}"
|
51
|
-
end
|
52
|
-
|
53
|
-
#
|
54
|
-
# converts hash into URL query string, keys get an alpha sort
|
55
|
-
# if a value is an array, the array values get mapped to the same key:
|
56
|
-
# hash_to_query(:q=>'blah', :fq=>['blah', 'blah'], :facet=>{:field=>['location_facet', 'format_facet']})
|
57
|
-
# returns:
|
58
|
-
# ?q=blah&fq=blah&fq=blah&facet.field=location_facet&facet.field=format.facet
|
59
|
-
#
|
60
|
-
# if a value is empty/nil etc., it is not added
|
61
|
-
def hash_to_query(params)
|
62
|
-
mapped = params.map do |k, v|
|
63
|
-
next if v.to_s.empty?
|
64
|
-
if v.class == Array
|
65
|
-
hash_to_query(v.map { |x| [k, x] })
|
66
|
-
else
|
67
|
-
build_param k, v
|
68
|
-
end
|
69
|
-
end
|
70
|
-
mapped.compact.join("&")
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
data/lib/rsolr/connection.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
# A class that represents a "doc" xml element for a solr update
|
2
|
-
class RSolr::Message::Document
|
3
|
-
|
4
|
-
# "attrs" is a hash for setting the "doc" xml attributes
|
5
|
-
# "fields" is an array of Field objects
|
6
|
-
attr_accessor :attrs, :fields
|
7
|
-
|
8
|
-
# "doc_hash" must be a Hash/Mash object
|
9
|
-
# If a value in the "doc_hash" is an array,
|
10
|
-
# a field object is created for each value...
|
11
|
-
def initialize(doc_hash = {})
|
12
|
-
@fields = []
|
13
|
-
doc_hash.each_pair do |field,values|
|
14
|
-
# create a new field for each value (multi-valued)
|
15
|
-
# put non-array values into an array
|
16
|
-
values = [values] unless values.is_a?(Array)
|
17
|
-
values.each do |v|
|
18
|
-
next if v.to_s.empty?
|
19
|
-
@fields << RSolr::Message::Field.new({:name=>field}, v.to_s)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
@attrs={}
|
23
|
-
end
|
24
|
-
|
25
|
-
# returns an array of fields that match the "name" arg
|
26
|
-
def fields_by_name(name)
|
27
|
-
@fields.select{|f|f.name==name}
|
28
|
-
end
|
29
|
-
|
30
|
-
# returns the *first* field that matches the "name" arg
|
31
|
-
def field_by_name(name)
|
32
|
-
@fields.detect{|f|f.name==name}
|
33
|
-
end
|
34
|
-
|
35
|
-
#
|
36
|
-
# Add a field value to the document. Options map directly to
|
37
|
-
# XML attributes in the Solr <field> node.
|
38
|
-
# See http://wiki.apache.org/solr/UpdateXmlMessages#head-8315b8028923d028950ff750a57ee22cbf7977c6
|
39
|
-
#
|
40
|
-
# === Example:
|
41
|
-
#
|
42
|
-
# document.add_field('title', 'A Title', :boost => 2.0)
|
43
|
-
#
|
44
|
-
def add_field(name, value, options = {})
|
45
|
-
@fields << RSolr::Message::Field.new(options.merge({:name=>name}), value)
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
data/lib/rsolr/message/field.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# A class that represents a "doc"/"field" xml element for a solr update
|
2
|
-
class RSolr::Message::Field
|
3
|
-
|
4
|
-
# "attrs" is a hash for setting the "doc" xml attributes
|
5
|
-
# "value" is the text value for the node
|
6
|
-
attr_accessor :attrs, :value
|
7
|
-
|
8
|
-
# "attrs" must be a hash
|
9
|
-
# "value" should be something that responds to #_to_s
|
10
|
-
def initialize(attrs, value)
|
11
|
-
@attrs = attrs
|
12
|
-
@value = value
|
13
|
-
end
|
14
|
-
|
15
|
-
# the value of the "name" attribute
|
16
|
-
def name
|
17
|
-
@attrs[:name]
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|