solr4r 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +30 -0
- data/README +1 -1
- data/lib/solr4r/builder.rb +31 -21
- data/lib/solr4r/client/admin.rb +83 -0
- data/lib/solr4r/client/query.rb +93 -0
- data/lib/solr4r/client/update.rb +123 -0
- data/lib/solr4r/client.rb +113 -149
- data/lib/solr4r/document.rb +14 -14
- data/lib/solr4r/endpoints.rb +86 -0
- data/lib/solr4r/logging.rb +5 -3
- data/lib/solr4r/request.rb +10 -38
- data/lib/solr4r/response.rb +19 -8
- data/lib/solr4r/result.rb +2 -2
- data/lib/solr4r/uri_extension.rb +5 -4
- data/lib/solr4r/version.rb +1 -1
- data/lib/solr4r.rb +3 -2
- data/spec/solr4r/builder_spec.rb +50 -30
- data/spec/solr4r/client_spec.rb +93 -0
- data/spec/spec_helper.rb +0 -4
- metadata +37 -12
- data/lib/solr4r/request_extension.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad8418aa9f1a84f5ff0c9196c7f1a805b8b4e84d
|
4
|
+
data.tar.gz: 4b557a50a64366aa9501f436dc0c2f1d66a5412e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1f608e0dac485d86383efca1f68b099d08e803d57b3371d61cdbfa7de93166207d745ff7068af226086f8ce8d35bbcc8eeb1ae946c31c32f7c0d22707029a3d
|
7
|
+
data.tar.gz: e75af57456ae37f54c70ebd448010b07b9055ea853dcd530521315267c958bad360e52db7bc55e9cee777099712849f3033bee15922a3a257650e4a1e47de187
|
data/ChangeLog
CHANGED
@@ -2,6 +2,36 @@
|
|
2
2
|
|
3
3
|
= Revision history for solr4r
|
4
4
|
|
5
|
+
== 0.0.6 [2015-03-18]
|
6
|
+
|
7
|
+
* Extracted Solr4R::Endpoints from Solr4R::Client.
|
8
|
+
* Extracted Solr4R::Client::Admin, Solr4R::Client::Query and
|
9
|
+
Solr4R::Client::Update from Solr4R::Client.
|
10
|
+
* Added core to Solr4R::Client.default_uri and adjusted
|
11
|
+
Solr4R::Client::DEFAULT_SYSTEM_PATH.
|
12
|
+
* Added Solr4R::Client::Admin#cores.
|
13
|
+
* Added Solr4R::Client::Admin#fields.
|
14
|
+
* Added Solr4R::Client::Admin#analyze_document.
|
15
|
+
* Added Solr4R::Client::Admin#analyze_field.
|
16
|
+
* Added Solr4R::Client::Query#json_document.
|
17
|
+
* Added Solr4R::Client::Query#more_like_this_h (using the {request
|
18
|
+
handler}[https://cwiki.apache.org/confluence/display/solr/MoreLikeThis]).
|
19
|
+
* Added Solr4R::Client::Query#more_like_this_q (using the {query
|
20
|
+
parser}[https://cwiki.apache.org/confluence/display/solr/Other+Parsers#OtherParsers-MoreLikeThisQueryParser]).
|
21
|
+
* Added support for {local
|
22
|
+
params}[https://cwiki.apache.org/confluence/display/solr/Local+Parameters+in+Queries]
|
23
|
+
to Solr4R::Client.query_string.
|
24
|
+
* Extended Solr4R::RequestUriExtension#query_pairs to skip +nil+ values.
|
25
|
+
* Extended Solr4R::RequestUriExtension#query_pairs to allow control over
|
26
|
+
nested key's value (via +:_+).
|
27
|
+
* Refactored Solr4R::Document#more_like_this to use
|
28
|
+
Solr4R::Client#more_like_this.
|
29
|
+
* Refactored Solr4R::Builder#delete to use Solr4R::Client.query_string for
|
30
|
+
query hashes.
|
31
|
+
* Refactored Solr4R::Request preparation; dropped
|
32
|
+
Solr4R::HTTPRequestExtension.
|
33
|
+
* Refactored Solr4R::Response initialization.
|
34
|
+
|
5
35
|
== 0.0.5 [2015-02-11]
|
6
36
|
|
7
37
|
* Fixed Solr4R::Result for unsupported types.
|
data/README
CHANGED
data/lib/solr4r/builder.rb
CHANGED
@@ -5,9 +5,9 @@
|
|
5
5
|
# #
|
6
6
|
# solr4r -- A Ruby client for Apache Solr #
|
7
7
|
# #
|
8
|
-
# Copyright (C) 2014 Jens Wille
|
8
|
+
# Copyright (C) 2014-2015 Jens Wille #
|
9
9
|
# #
|
10
|
-
#
|
10
|
+
# solr4r is free software: you can redistribute it and/or modify it under the #
|
11
11
|
# terms of the GNU Affero General Public License as published by the Free #
|
12
12
|
# Software Foundation, either version 3 of the License, or (at your option) #
|
13
13
|
# any later version. #
|
@@ -39,15 +39,11 @@ module Solr4R
|
|
39
39
|
|
40
40
|
end
|
41
41
|
|
42
|
-
DEFAULT_OPTIONS = {
|
43
|
-
encoding: 'UTF-8'
|
44
|
-
}
|
42
|
+
DEFAULT_OPTIONS = { encoding: 'UTF-8' }
|
45
43
|
|
46
44
|
def initialize(options = {})
|
47
|
-
|
48
|
-
|
49
|
-
'block argument not supported, use options hash instead'
|
50
|
-
end
|
45
|
+
raise ArgumentError,
|
46
|
+
'block argument not supported, use options hash instead' if block_given?
|
51
47
|
|
52
48
|
super(
|
53
49
|
@_solr_opt = DEFAULT_OPTIONS.merge(options),
|
@@ -99,7 +95,7 @@ module Solr4R
|
|
99
95
|
# </add>
|
100
96
|
#
|
101
97
|
# # document attributes
|
102
|
-
# add([[{ id: 42, text: 'blah' },
|
98
|
+
# add([[{ id: 42, text: 'blah' }, boost: 10.0]])
|
103
99
|
#
|
104
100
|
# <?xml version="1.0" encoding="UTF-8"?>
|
105
101
|
# <add>
|
@@ -121,7 +117,7 @@ module Solr4R
|
|
121
117
|
# </add>
|
122
118
|
#
|
123
119
|
# # all attributes together
|
124
|
-
# add([[{ id: 42, text: ['blah', boost: 2.0] },
|
120
|
+
# add([[{ id: 42, text: ['blah', boost: 2.0] }, boost: 10.0]], commitWithin: 23)
|
125
121
|
#
|
126
122
|
# <?xml version="1.0" encoding="UTF-8"?>
|
127
123
|
# <add commitWithin="23">
|
@@ -141,6 +137,8 @@ module Solr4R
|
|
141
137
|
} }
|
142
138
|
end
|
143
139
|
|
140
|
+
alias_method :doc, :add
|
141
|
+
|
144
142
|
# See Schema[http://wiki.apache.org/solr/UpdateXmlMessages#A.22commit.22_and_.22optimize.22].
|
145
143
|
#
|
146
144
|
# Examples:
|
@@ -189,6 +187,8 @@ module Solr4R
|
|
189
187
|
|
190
188
|
# See Schema[http://wiki.apache.org/solr/UpdateXmlMessages#A.22delete.22_documents_by_ID_and_by_Query].
|
191
189
|
#
|
190
|
+
# See Client.query_string for handling of query hashes.
|
191
|
+
#
|
192
192
|
# Examples:
|
193
193
|
#
|
194
194
|
# # single ID
|
@@ -230,8 +230,7 @@ module Solr4R
|
|
230
230
|
#
|
231
231
|
# <?xml version="1.0" encoding="UTF-8"?>
|
232
232
|
# <delete>
|
233
|
-
# <query>office:Bridgewater</query>
|
234
|
-
# <query>skills:Perl</query>
|
233
|
+
# <query>office:Bridgewater skills:Perl</query>
|
235
234
|
# </delete>
|
236
235
|
#
|
237
236
|
# # query hash with array
|
@@ -239,8 +238,15 @@ module Solr4R
|
|
239
238
|
#
|
240
239
|
# <?xml version="1.0" encoding="UTF-8"?>
|
241
240
|
# <delete>
|
242
|
-
# <query>office:Bridgewater</query>
|
243
|
-
#
|
241
|
+
# <query>office:Bridgewater office:Osaka</query>
|
242
|
+
# </delete>
|
243
|
+
#
|
244
|
+
# # query hash with LocalParams
|
245
|
+
# delete(query: { office: 'Bridgewater', _: { type: :edismax } })
|
246
|
+
#
|
247
|
+
# <?xml version="1.0" encoding="UTF-8"?>
|
248
|
+
# <delete>
|
249
|
+
# <query>{!type=edismax}office:Bridgewater</query>
|
244
250
|
# </delete>
|
245
251
|
#
|
246
252
|
# # both IDs and queries
|
@@ -250,15 +256,19 @@ module Solr4R
|
|
250
256
|
# <delete>
|
251
257
|
# <id>05991</id>
|
252
258
|
# <id>06000</id>
|
253
|
-
# <query>office:Bridgewater</query>
|
254
|
-
# <query>office:Osaka</query>
|
259
|
+
# <query>office:Bridgewater office:Osaka</query>
|
255
260
|
# </delete>
|
256
261
|
def delete(hash)
|
257
262
|
to_xml(:delete) { |delete_node| hash.each { |key, values|
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
263
|
+
case key.to_s
|
264
|
+
when 'id'
|
265
|
+
_each(values) { |id| delete_node.id_(id) }
|
266
|
+
when 'query'
|
267
|
+
_each(values) { |query|
|
268
|
+
delete_node.query_(Client.query_string(query, false)) }
|
269
|
+
else
|
270
|
+
raise ArgumentError, "`id' or `query' expected, got %p" % key
|
271
|
+
end
|
262
272
|
} }
|
263
273
|
end
|
264
274
|
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
###############################################################################
|
5
|
+
# #
|
6
|
+
# solr4r -- A Ruby client for Apache Solr #
|
7
|
+
# #
|
8
|
+
# Copyright (C) 2014-2015 Jens Wille #
|
9
|
+
# #
|
10
|
+
# solr4r is free software: you can redistribute it and/or modify it under the #
|
11
|
+
# terms of the GNU Affero General Public License as published by the Free #
|
12
|
+
# Software Foundation, either version 3 of the License, or (at your option) #
|
13
|
+
# any later version. #
|
14
|
+
# #
|
15
|
+
# solr4r is distributed in the hope that it will be useful, but WITHOUT ANY #
|
16
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
17
|
+
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for #
|
18
|
+
# more details. #
|
19
|
+
# #
|
20
|
+
# You should have received a copy of the GNU Affero General Public License #
|
21
|
+
# along with solr4r. If not, see <http://www.gnu.org/licenses/>. #
|
22
|
+
# #
|
23
|
+
###############################################################################
|
24
|
+
#++
|
25
|
+
|
26
|
+
module Solr4R
|
27
|
+
|
28
|
+
class Client
|
29
|
+
|
30
|
+
DEFAULT_PING_PATH = 'admin/ping'
|
31
|
+
DEFAULT_CORES_PATH = '../admin/cores'
|
32
|
+
DEFAULT_FIELDS_PATH = 'schema/fields'
|
33
|
+
DEFAULT_SYSTEM_PATH = '../admin/info/system'
|
34
|
+
DEFAULT_ANALYZE_DOCUMENT_PATH = 'analysis/document'
|
35
|
+
DEFAULT_ANALYZE_FIELD_PATH = 'analysis/field'
|
36
|
+
|
37
|
+
module Admin
|
38
|
+
|
39
|
+
def solr_version(type = :spec,
|
40
|
+
params = {}, options = {}, path = DEFAULT_SYSTEM_PATH, &block)
|
41
|
+
|
42
|
+
json(path, params, options, &block) % "lucene/solr-#{type}-version"
|
43
|
+
end
|
44
|
+
|
45
|
+
def ping(
|
46
|
+
params = {}, options = {}, path = DEFAULT_PING_PATH, &block)
|
47
|
+
|
48
|
+
json(path, params, options, &block) % 'status'
|
49
|
+
end
|
50
|
+
|
51
|
+
def cores(
|
52
|
+
params = {}, options = {}, path = DEFAULT_CORES_PATH, &block)
|
53
|
+
|
54
|
+
json(path, params, options, &block) % 'status'
|
55
|
+
end
|
56
|
+
|
57
|
+
def fields(
|
58
|
+
params = {}, options = {}, path = DEFAULT_FIELDS_PATH, &block)
|
59
|
+
|
60
|
+
json(path, params, options, &block) % 'fields'
|
61
|
+
end
|
62
|
+
|
63
|
+
def analyze_document(doc,
|
64
|
+
params = {}, options = {}, path = DEFAULT_ANALYZE_DOCUMENT_PATH, &block)
|
65
|
+
|
66
|
+
doc = builder.doc(doc) unless doc.is_a?(String)
|
67
|
+
update(doc, amend_options_hash(
|
68
|
+
options, :params, wt: :json), path, &block).result % 'analysis'
|
69
|
+
end
|
70
|
+
|
71
|
+
def analyze_field(analysis,
|
72
|
+
params = {}, options = {}, path = DEFAULT_ANALYZE_FIELD_PATH, &block)
|
73
|
+
|
74
|
+
json(path, params.merge(analysis: analysis), options, &block) % 'analysis'
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
include Admin
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
###############################################################################
|
5
|
+
# #
|
6
|
+
# solr4r -- A Ruby client for Apache Solr #
|
7
|
+
# #
|
8
|
+
# Copyright (C) 2014-2015 Jens Wille #
|
9
|
+
# #
|
10
|
+
# solr4r is free software: you can redistribute it and/or modify it under the #
|
11
|
+
# terms of the GNU Affero General Public License as published by the Free #
|
12
|
+
# Software Foundation, either version 3 of the License, or (at your option) #
|
13
|
+
# any later version. #
|
14
|
+
# #
|
15
|
+
# solr4r is distributed in the hope that it will be useful, but WITHOUT ANY #
|
16
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
17
|
+
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for #
|
18
|
+
# more details. #
|
19
|
+
# #
|
20
|
+
# You should have received a copy of the GNU Affero General Public License #
|
21
|
+
# along with solr4r. If not, see <http://www.gnu.org/licenses/>. #
|
22
|
+
# #
|
23
|
+
###############################################################################
|
24
|
+
#++
|
25
|
+
|
26
|
+
module Solr4R
|
27
|
+
|
28
|
+
class Client
|
29
|
+
|
30
|
+
MATCH_ALL_QUERY = '*:*'
|
31
|
+
|
32
|
+
DEFAULT_SELECT_PATH = 'select'
|
33
|
+
DEFAULT_MLT_PATH = 'mlt'
|
34
|
+
|
35
|
+
MLT_DEFAULT_FL = '*,score'
|
36
|
+
MLT_DEFAULT_ROWS = 5
|
37
|
+
MLT_LOCAL_PARAMS = local_params_string(
|
38
|
+
%w[mintf mindf minwl maxwl], type: :mlt, qf: '$mlt.fl')
|
39
|
+
|
40
|
+
module Query
|
41
|
+
|
42
|
+
def count(
|
43
|
+
params = {}, options = {}, path = DEFAULT_SELECT_PATH, &block)
|
44
|
+
|
45
|
+
params = params.merge(rows: 0)
|
46
|
+
params[:q] ||= MATCH_ALL_QUERY
|
47
|
+
get(path, params, options, &block)
|
48
|
+
end
|
49
|
+
|
50
|
+
def json_query(
|
51
|
+
params = {}, options = {}, path = DEFAULT_SELECT_PATH, &block)
|
52
|
+
|
53
|
+
json(path, params.merge(Hash[[:q, :fq].map { |key|
|
54
|
+
[key, self.class.query_string(params[key])] }]), options, &block)
|
55
|
+
end
|
56
|
+
|
57
|
+
def json_document(id,
|
58
|
+
params = {}, options = {}, path = DEFAULT_SELECT_PATH, &block)
|
59
|
+
|
60
|
+
json_query(params.merge(q: { id: id }), options, path, &block).first
|
61
|
+
end
|
62
|
+
|
63
|
+
def more_like_this_h(id, fields,
|
64
|
+
params = {}, options = {}, path = DEFAULT_MLT_PATH, &block)
|
65
|
+
|
66
|
+
_more_like_this_query({ id: id }, fields, params, options, path, &block)
|
67
|
+
end
|
68
|
+
|
69
|
+
def more_like_this_q(id, fields,
|
70
|
+
params = {}, options = {}, path = DEFAULT_SELECT_PATH, &block)
|
71
|
+
|
72
|
+
_more_like_this_query(MLT_LOCAL_PARAMS + id, fields, amend_options_array(
|
73
|
+
params, :fq, '-id' => id, _: { cache: false }), options, path, &block)
|
74
|
+
end
|
75
|
+
|
76
|
+
alias_method :more_like_this, :more_like_this_q
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def _more_like_this_query(query, fields, params, *args, &block)
|
81
|
+
json_query(params.merge('mlt.fl' => Array(fields).join(','),
|
82
|
+
q: query,
|
83
|
+
fl: params.fetch(:fl, MLT_DEFAULT_FL),
|
84
|
+
rows: params.fetch(:rows, MLT_DEFAULT_ROWS)), *args, &block)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
include Query
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
###############################################################################
|
5
|
+
# #
|
6
|
+
# solr4r -- A Ruby client for Apache Solr #
|
7
|
+
# #
|
8
|
+
# Copyright (C) 2014-2015 Jens Wille #
|
9
|
+
# #
|
10
|
+
# solr4r is free software: you can redistribute it and/or modify it under the #
|
11
|
+
# terms of the GNU Affero General Public License as published by the Free #
|
12
|
+
# Software Foundation, either version 3 of the License, or (at your option) #
|
13
|
+
# any later version. #
|
14
|
+
# #
|
15
|
+
# solr4r is distributed in the hope that it will be useful, but WITHOUT ANY #
|
16
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
17
|
+
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for #
|
18
|
+
# more details. #
|
19
|
+
# #
|
20
|
+
# You should have received a copy of the GNU Affero General Public License #
|
21
|
+
# along with solr4r. If not, see <http://www.gnu.org/licenses/>. #
|
22
|
+
# #
|
23
|
+
###############################################################################
|
24
|
+
#++
|
25
|
+
|
26
|
+
module Solr4R
|
27
|
+
|
28
|
+
class Client
|
29
|
+
|
30
|
+
DEFAULT_BATCH_SIZE = 1000
|
31
|
+
|
32
|
+
DEFAULT_UPDATE_TYPE = 'text/xml'
|
33
|
+
|
34
|
+
DEFAULT_UPDATE_PATH = 'update'
|
35
|
+
|
36
|
+
module Update
|
37
|
+
|
38
|
+
def update(data,
|
39
|
+
params = {}, options = {},
|
40
|
+
path = DEFAULT_UPDATE_PATH,
|
41
|
+
type = DEFAULT_UPDATE_TYPE, &block)
|
42
|
+
|
43
|
+
post(path, data, params, amend_options_hash(
|
44
|
+
options, :headers, 'Content-Type' => type), &block)
|
45
|
+
end
|
46
|
+
|
47
|
+
# See Builder#add.
|
48
|
+
def add(doc, attributes = {},
|
49
|
+
params = {}, options = {}, &block)
|
50
|
+
|
51
|
+
update(builder.add(doc, attributes), params, options, &block)
|
52
|
+
end
|
53
|
+
|
54
|
+
def add_batch(docs, attributes = {},
|
55
|
+
params = {}, options = {}, batch_size = DEFAULT_BATCH_SIZE, &block)
|
56
|
+
|
57
|
+
failed = []
|
58
|
+
|
59
|
+
docs.each_slice(batch_size) { |batch|
|
60
|
+
add(batch, attributes, params, options, &block).success? ||
|
61
|
+
failed.concat(batch_size == 1 ? batch : add_batch(batch,
|
62
|
+
attributes, params, options, batch_size / 10, &block))
|
63
|
+
}
|
64
|
+
|
65
|
+
failed
|
66
|
+
end
|
67
|
+
|
68
|
+
# See Builder#commit.
|
69
|
+
def commit(attributes = {},
|
70
|
+
params = {}, options = {}, &block)
|
71
|
+
|
72
|
+
update(builder.commit(attributes), params, options, &block)
|
73
|
+
end
|
74
|
+
|
75
|
+
# See Builder#optimize.
|
76
|
+
def optimize(attributes = {},
|
77
|
+
params = {}, options = {}, &block)
|
78
|
+
|
79
|
+
update(builder.optimize(attributes), params, options, &block)
|
80
|
+
end
|
81
|
+
|
82
|
+
# See Builder#rollback.
|
83
|
+
def rollback(
|
84
|
+
params = {}, options = {}, &block)
|
85
|
+
|
86
|
+
update(builder.rollback, params, options, &block)
|
87
|
+
end
|
88
|
+
|
89
|
+
# See Builder#delete.
|
90
|
+
def delete(hash,
|
91
|
+
params = {}, options = {}, &block)
|
92
|
+
|
93
|
+
update(builder.delete(hash), params, options, &block)
|
94
|
+
end
|
95
|
+
|
96
|
+
# See #delete.
|
97
|
+
def delete_by_id(id,
|
98
|
+
params = {}, options = {}, &block)
|
99
|
+
|
100
|
+
delete({ id: id }, params, options, &block)
|
101
|
+
end
|
102
|
+
|
103
|
+
# See #delete.
|
104
|
+
def delete_by_query(query,
|
105
|
+
params = {}, options = {}, &block)
|
106
|
+
|
107
|
+
delete({ query: query }, params, options, &block)
|
108
|
+
end
|
109
|
+
|
110
|
+
# See #delete_by_query.
|
111
|
+
def delete_all!(
|
112
|
+
params = {}, options = {}, &block)
|
113
|
+
|
114
|
+
delete_by_query(MATCH_ALL_QUERY, params, options, &block)
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
include Update
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|