solrb 0.1.4 → 0.1.5
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +100 -34
- data/lib/solr/connection.rb +1 -1
- data/lib/solr/query/request/runner.rb +1 -4
- data/lib/solr/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afb9302df9f0a348f4d80a007a7e3da0df0fed4ff012e814788c6b610fdfb642
|
4
|
+
data.tar.gz: 4001463e4a3c13b487180336e9cb0d949de06beb377b24caf7b8f7d579cffc84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54f453cedf22c49924b2e959356029e3079d28498213ec4ef890da46caee815552554ba9dbc5ec48c476ff1089090fac0699c1f801d58e3095ac6f8810327d39
|
7
|
+
data.tar.gz: 76b252a3b999c546fab15c0f7e421179ea081c0d0a31b3a4f64950f29fce12f0d36d3762b05ac8a2bfb99b7911eb5294010a0947ac3975d2b0b6838be5792d56
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,19 +1,41 @@
|
|
1
1
|
[](https://circleci.com/gh/machinio/solrb/tree/master)
|
2
2
|
[](https://codeclimate.com/github/machinio/solrb/maintainability)
|
3
3
|
|
4
|
-
|
4
|
+
Solrb
|
5
|
+
======
|
5
6
|
|
6
7
|
Object-Oriented approach to Solr in Ruby.
|
7
8
|
|
8
|
-
|
9
|
+
Installation: `gem install solrb`
|
9
10
|
|
10
|
-
|
11
|
+
## Table of contents
|
11
12
|
|
12
|
-
```ruby
|
13
|
-
gem 'solrb', require: 'solr'
|
14
|
-
```
|
15
13
|
|
16
|
-
|
14
|
+
* [Configuration](#configuration)
|
15
|
+
* [Setting Solr URL via environment variable](#setting-solr-url-via-environment-variable)
|
16
|
+
* [Single core configuration](#single-core-configuration)
|
17
|
+
* [Multiple core configuration](#multiple-core-configuration)
|
18
|
+
* [Indexing](#indexing)
|
19
|
+
* [Querying](#querying)
|
20
|
+
* [Simple Query](#simple-query)
|
21
|
+
* [Querying multiple cores](#querying-multiple-cores)
|
22
|
+
* [Query with field boost](#query-with-field-boost)
|
23
|
+
* [Query with filtering](#query-with-filtering)
|
24
|
+
* [Query with sorting](#query-with-sorting)
|
25
|
+
* [Query with grouping](#query-with-grouping)
|
26
|
+
* [Query with facets](#query-with-facets)
|
27
|
+
* [Query with boosting functions](#query-with-boosting-functions)
|
28
|
+
* [Dictionary boosting function](#dictionary-boosting-function)
|
29
|
+
* [Field list](#field-list)
|
30
|
+
* [Deleting documents](#deleting-documents)
|
31
|
+
* [Active Support instrumentation](#active-support-instrumentation)
|
32
|
+
* [Running specs](#running-specs)
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
# Configuration
|
37
|
+
|
38
|
+
## Setting Solr URL via environment variable
|
17
39
|
|
18
40
|
The simplest way to use Solrb is `SORL_URL` environment variable (that has a core name in it):
|
19
41
|
|
@@ -21,19 +43,23 @@ The simplest way to use Solrb is `SORL_URL` environment variable (that has a cor
|
|
21
43
|
ENV['SOLR_URL'] = 'http://localhost:8983/solr/demo'
|
22
44
|
```
|
23
45
|
|
24
|
-
|
46
|
+
|
47
|
+
You can also use `Solr.configure` to specify the solr URL explicitly:
|
25
48
|
|
26
49
|
```ruby
|
27
|
-
# Single core configuration
|
28
50
|
Solr.configure do |config|
|
29
51
|
config.url = 'http://localhost:8983/solr/demo'
|
30
52
|
end
|
31
53
|
```
|
32
54
|
|
55
|
+
It's important to note that those fields that are not configured, will be passed as-is to solr.
|
56
|
+
*So you only need to specify fields in configuration if you want Solrb to modify them at runtime*.
|
57
|
+
|
58
|
+
## Single core configuration
|
59
|
+
|
33
60
|
Use `Solr.configure` for an additional configuration:
|
34
61
|
|
35
62
|
```ruby
|
36
|
-
# Single core configuration
|
37
63
|
Solr.configure do |config|
|
38
64
|
config.url = 'http://localhost:8983/solr/demo'
|
39
65
|
|
@@ -50,8 +76,9 @@ Solr.configure do |config|
|
|
50
76
|
end
|
51
77
|
```
|
52
78
|
|
79
|
+
## Multiple core configuration
|
80
|
+
|
53
81
|
```ruby
|
54
|
-
# Multiple core configuration
|
55
82
|
Solr.configure do |config|
|
56
83
|
config.url = 'http://localhost:8983/solr'
|
57
84
|
|
@@ -79,10 +106,6 @@ Solr.configure do |config|
|
|
79
106
|
end
|
80
107
|
```
|
81
108
|
|
82
|
-
It's important to note that those fields that are not configured, will be passed as-is to solr.
|
83
|
-
*So you only need to specify fields in configuration if you want Solrb to modify them at runtime*.
|
84
|
-
|
85
|
-
|
86
109
|
Warning: Solrb doesn't support fields with the same name. If you have two fields with the same name mapping
|
87
110
|
to a single solr field, you'll have to rename one of the fields.
|
88
111
|
|
@@ -97,9 +120,8 @@ end
|
|
97
120
|
...
|
98
121
|
```
|
99
122
|
|
100
|
-
## Usage
|
101
123
|
|
102
|
-
|
124
|
+
# Indexing
|
103
125
|
|
104
126
|
```ruby
|
105
127
|
# creates a single document and commits it to index
|
@@ -117,9 +139,9 @@ You can also create indexing document directly from attributes:
|
|
117
139
|
doc = Solr::Indexing::Document.new(id: 5, name: 'John')
|
118
140
|
```
|
119
141
|
|
120
|
-
|
142
|
+
# Querying
|
121
143
|
|
122
|
-
|
144
|
+
## Simple Query
|
123
145
|
|
124
146
|
```ruby
|
125
147
|
field = Solr::Query::Request::FieldWithBoost.new(field: :name)
|
@@ -127,8 +149,19 @@ doc = Solr::Indexing::Document.new(id: 5, name: 'John')
|
|
127
149
|
request = Solr::Query::Request.new(search_term: 'term', fields: [field])
|
128
150
|
request.run(page: 1, page_size: 10)
|
129
151
|
```
|
152
|
+
## Querying multiple cores
|
130
153
|
|
131
|
-
|
154
|
+
For multi-core configuration use `Solr.with_core` block:
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
Solr.with_core(:models) do
|
158
|
+
Solr.delete_by_id(3242343)
|
159
|
+
Solr::Query::Request.new(search_term: 'term', fields: fields)
|
160
|
+
Solr::Indexing::Request.new(documents: [doc])
|
161
|
+
end
|
162
|
+
```
|
163
|
+
|
164
|
+
## Query with field boost
|
132
165
|
|
133
166
|
```ruby
|
134
167
|
fields = [
|
@@ -140,7 +173,7 @@ doc = Solr::Indexing::Document.new(id: 5, name: 'John')
|
|
140
173
|
request.run(page: 1, page_size: 10)
|
141
174
|
```
|
142
175
|
|
143
|
-
|
176
|
+
## Query with filtering
|
144
177
|
|
145
178
|
```ruby
|
146
179
|
fields = [
|
@@ -153,7 +186,7 @@ doc = Solr::Indexing::Document.new(id: 5, name: 'John')
|
|
153
186
|
```
|
154
187
|
|
155
188
|
|
156
|
-
|
189
|
+
## Query with sorting
|
157
190
|
|
158
191
|
```ruby
|
159
192
|
fields = [
|
@@ -166,7 +199,7 @@ doc = Solr::Indexing::Document.new(id: 5, name: 'John')
|
|
166
199
|
request.run(page: 1, page_size: 10)
|
167
200
|
```
|
168
201
|
|
169
|
-
|
202
|
+
## Query with grouping
|
170
203
|
|
171
204
|
```ruby
|
172
205
|
fields = [
|
@@ -178,7 +211,7 @@ doc = Solr::Indexing::Document.new(id: 5, name: 'John')
|
|
178
211
|
request.run(page: 1, page_size: 10)
|
179
212
|
```
|
180
213
|
|
181
|
-
|
214
|
+
## Query with facets
|
182
215
|
|
183
216
|
```ruby
|
184
217
|
fields = [
|
@@ -190,7 +223,7 @@ doc = Solr::Indexing::Document.new(id: 5, name: 'John')
|
|
190
223
|
request.run(page: 1, page_size: 10)
|
191
224
|
```
|
192
225
|
|
193
|
-
|
226
|
+
## Query with boosting functions
|
194
227
|
|
195
228
|
```ruby
|
196
229
|
fields = [
|
@@ -204,8 +237,34 @@ doc = Solr::Indexing::Document.new(id: 5, name: 'John')
|
|
204
237
|
)
|
205
238
|
request.run(page: 1, page_size: 10)
|
206
239
|
```
|
240
|
+
### Dictionary boosting function
|
241
|
+
Sometimes you want to do a dictionary-style boosting
|
242
|
+
example: given a hash (dictionary)
|
243
|
+
|
244
|
+
```ruby
|
245
|
+
{3025 => 2.0, 3024 => 1.5, 3023 => 1.2}
|
246
|
+
```
|
207
247
|
|
208
|
-
|
248
|
+
and a field of `category_id`
|
249
|
+
the resulting boosting function will be:
|
250
|
+
```
|
251
|
+
if(eq(category_id_it, 3025), 2.0, if(eq(category_id_it, 3024), 1.5, if(eq(category_id_it, 3023), 1.2, 1)))
|
252
|
+
```
|
253
|
+
note that I added spaces for readability, real Solr query functions must always be w/out spaces
|
254
|
+
|
255
|
+
Example of usage:
|
256
|
+
|
257
|
+
```ruby
|
258
|
+
category_id_boosts = {3025 => 2.0, 3024 => 1.5, 3023 => 1.2}
|
259
|
+
request.boosting = Solr::Query::Request::Boosting.new(
|
260
|
+
multiplicative_boost_functions: [
|
261
|
+
Solr::Query::Request::Boosting::DictionaryBoostFunction.new(field: :category_id,
|
262
|
+
dictionary: category_id_boosts)
|
263
|
+
]
|
264
|
+
)
|
265
|
+
```
|
266
|
+
|
267
|
+
## Field list
|
209
268
|
|
210
269
|
|
211
270
|
```ruby
|
@@ -220,7 +279,7 @@ doc = Solr::Indexing::Document.new(id: 5, name: 'John')
|
|
220
279
|
request.run(page: 1, page_size: 10)
|
221
280
|
```
|
222
281
|
|
223
|
-
|
282
|
+
# Deleting documents
|
224
283
|
|
225
284
|
```ruby
|
226
285
|
Solr.delete_by_id(3242343)
|
@@ -229,19 +288,26 @@ Solr.delete_by_query('*:*')
|
|
229
288
|
Solr.delete_by_query('*:*', commit: true)
|
230
289
|
```
|
231
290
|
|
232
|
-
|
291
|
+
# Active Support instrumentation
|
233
292
|
|
234
|
-
|
293
|
+
This gem publishes events via [Active Support Instrumentation](https://edgeguides.rubyonrails.org/active_support_instrumentation.html)
|
294
|
+
|
295
|
+
To subscribe to solrb events, you can add this code to initializer:
|
235
296
|
|
236
297
|
```ruby
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
298
|
+
ActiveSupport::Notifications.subscribe('request.solrb') do |*args|
|
299
|
+
event = ActiveSupport::Notifications::Event.new(*args)
|
300
|
+
if Logger::INFO == Rails.logger.level
|
301
|
+
Rails.logger.info("Solrb #{event.duration.round(1)}ms")
|
302
|
+
elsif Logger::DEBUG == Rails.logger.level && Rails.env.development?
|
303
|
+
Pry::ColorPrinter.pp(event.payload)
|
304
|
+
end
|
241
305
|
end
|
242
306
|
```
|
243
307
|
|
244
|
-
|
308
|
+
|
309
|
+
|
310
|
+
# Running specs
|
245
311
|
|
246
312
|
This project is setup to use CI to run all specs agains a real solr.
|
247
313
|
|
data/lib/solr/connection.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Solr
|
2
2
|
# low-level connection that can do network requests to Solr
|
3
3
|
class Connection
|
4
|
-
INSTRUMENT_KEY = 'solrb
|
4
|
+
INSTRUMENT_KEY = 'request.solrb'.freeze
|
5
5
|
|
6
6
|
def initialize(url, faraday_options: Solr.configuration.faraday_options)
|
7
7
|
# Allow mock the connection for testing
|
@@ -22,10 +22,7 @@ module Solr
|
|
22
22
|
|
23
23
|
def run
|
24
24
|
raw_response = connection(PATH).post_as_json(request_params)
|
25
|
-
|
26
|
-
Solr.instrument(name: 'solrb.request_response_cycle',
|
27
|
-
data: { request: request_params, response: raw_response })
|
28
|
-
response
|
25
|
+
Solr::Response.from_raw_response(raw_response)
|
29
26
|
end
|
30
27
|
|
31
28
|
private
|
data/lib/solr/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adriano Luz
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-09-
|
12
|
+
date: 2018-09-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: addressable
|