solrb 0.2.8 → 0.2.9
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/README.md +12 -0
- data/lib/solr/configuration.rb +1 -8
- data/lib/solr/errors/could_not_detect_endpoint_in_url.rb +14 -0
- data/lib/solr/query/request/edismax_adapter.rb +9 -1
- data/lib/solr/query/request/shards_preference.rb +27 -0
- data/lib/solr/query/request/shards_preferences/property.rb +21 -0
- data/lib/solr/query/request.rb +6 -1
- data/lib/solr/support/url_helper.rb +21 -0
- data/lib/solr/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 890bdddf977e6d555f4863777d80d58118d58be0230f65c1e159149e4943ec4b
|
4
|
+
data.tar.gz: 64659a76d63f8cdaeaf88c295f72215620d5a2fadad002c6d77febc1c319fdc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8d4c6bc82c7948f01e876ce8e21c0ea3239c4136ed6e1e7706fbc8ec612e76446383c8ceb6ffc24fc903c666a13251eaddaa509e5b755c4907863be805e447d
|
7
|
+
data.tar.gz: fcf165ac576f8facd86f4df33a1a9cd6557d20b029ea92477b543b3d63e17eec5d2472c6ca9e11778073448ec9c539c2330da96fbb03695e5de2f266b320c71d
|
data/README.md
CHANGED
@@ -399,6 +399,18 @@ Example of usage:
|
|
399
399
|
)
|
400
400
|
```
|
401
401
|
|
402
|
+
## Query with shards.preference
|
403
|
+
|
404
|
+
```ruby
|
405
|
+
shards_preference = Solr::Query::Request::ShardsPreference.new(
|
406
|
+
properties: [
|
407
|
+
Solr::Query::Request::ShardsPreferences::Property.new(name: 'replica.type', value: 'PULL')
|
408
|
+
]
|
409
|
+
)
|
410
|
+
request = Solr::Query::Request.new(search_term: 'term', shards_preference: shards_preference)
|
411
|
+
request.run(page: 1, page_size: 10)
|
412
|
+
```
|
413
|
+
|
402
414
|
## Field list
|
403
415
|
|
404
416
|
|
data/lib/solr/configuration.rb
CHANGED
@@ -73,14 +73,7 @@ module Solr
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def core_name_from_solr_url_env
|
76
|
-
|
77
|
-
core_name = full_solr_core_uri.path.gsub('/solr', '').delete('/')
|
78
|
-
|
79
|
-
if !core_name || core_name == ''
|
80
|
-
raise Solr::Errors::CouldNotInferImplicitCoreName
|
81
|
-
end
|
82
|
-
|
83
|
-
core_name
|
76
|
+
Solr::Support::UrlHelper.core_name_from_url(ENV['SOLR_URL'])
|
84
77
|
end
|
85
78
|
|
86
79
|
def build_env_url_core_config(name: nil)
|
@@ -15,6 +15,7 @@ module Solr
|
|
15
15
|
RERANK_QUERY = :rq
|
16
16
|
QUERY_OPERATOR = :'q.op'
|
17
17
|
JSON_FACET = :'json.facet'
|
18
|
+
SHARDS_PREFERENCE = :'shards.preference'
|
18
19
|
|
19
20
|
attr_reader :request
|
20
21
|
|
@@ -36,6 +37,7 @@ module Solr
|
|
36
37
|
solr_params = add_rerank_query(solr_params)
|
37
38
|
solr_params = add_phrase_slop(solr_params)
|
38
39
|
solr_params = add_query_operator(solr_params)
|
40
|
+
solr_params = add_shards_preference(solr_params)
|
39
41
|
solr_params
|
40
42
|
end
|
41
43
|
|
@@ -52,7 +54,7 @@ module Solr
|
|
52
54
|
solr_params[FILTER_QUERY] = filters
|
53
55
|
solr_params
|
54
56
|
end
|
55
|
-
|
57
|
+
|
56
58
|
def add_facets(solr_params)
|
57
59
|
return solr_params if Array(request.facets).empty?
|
58
60
|
solr_params[JSON_FACET] = request.facets.map(&:to_solr_h).reduce(&:merge).to_json
|
@@ -156,6 +158,12 @@ module Solr
|
|
156
158
|
solr_params[QUERY_OPERATOR] = request.query_operator
|
157
159
|
solr_params
|
158
160
|
end
|
161
|
+
|
162
|
+
def add_shards_preference(solr_params)
|
163
|
+
return solr_params if request.shards_preference.empty?
|
164
|
+
solr_params[SHARDS_PREFERENCE] = request.shards_preference.to_solr_s
|
165
|
+
solr_params
|
166
|
+
end
|
159
167
|
end
|
160
168
|
end
|
161
169
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'solr/query/request/shards_preferences/property'
|
2
|
+
|
3
|
+
module Solr
|
4
|
+
module Query
|
5
|
+
class Request
|
6
|
+
class ShardsPreference
|
7
|
+
attr_accessor :properties
|
8
|
+
|
9
|
+
def self.none
|
10
|
+
new
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(properties: [])
|
14
|
+
@properties = properties
|
15
|
+
end
|
16
|
+
|
17
|
+
def empty?
|
18
|
+
properties.empty?
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_solr_s
|
22
|
+
properties.map(&:to_solr_s).join(',')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Solr
|
2
|
+
module Query
|
3
|
+
class Request
|
4
|
+
class ShardsPreferences
|
5
|
+
class Property
|
6
|
+
attr_reader :name, :value
|
7
|
+
|
8
|
+
def initialize(name:, value:)
|
9
|
+
@name = name
|
10
|
+
@value = value
|
11
|
+
freeze
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_solr_s
|
15
|
+
"#{name}:#{value}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/solr/query/request.rb
CHANGED
@@ -13,6 +13,7 @@ require 'solr/query/request/sorting/function'
|
|
13
13
|
require 'solr/query/request/field_with_boost'
|
14
14
|
require 'solr/query/request/or_filter'
|
15
15
|
require 'solr/query/request/and_filter'
|
16
|
+
require 'solr/query/request/shards_preference'
|
16
17
|
require 'solr/query/handler'
|
17
18
|
|
18
19
|
module Solr
|
@@ -21,7 +22,7 @@ module Solr
|
|
21
22
|
attr_reader :search_term
|
22
23
|
attr_accessor :filters, :query_fields, :field_list, :facets, :boosting, :debug_mode, :spellcheck,
|
23
24
|
:limit_docs_by_field, :phrase_slop, :query_operator
|
24
|
-
attr_writer :grouping, :sorting
|
25
|
+
attr_writer :grouping, :sorting, :shards_preference
|
25
26
|
|
26
27
|
def initialize(search_term:, query_fields: [], field_list: Solr::Query::Request::FieldList.new, filters: [])
|
27
28
|
@search_term = search_term
|
@@ -45,6 +46,10 @@ module Solr
|
|
45
46
|
@sorting ||= Solr::Query::Request::Sorting.none
|
46
47
|
end
|
47
48
|
|
49
|
+
def shards_preference
|
50
|
+
@shards_preference ||= Solr::Query::Request::ShardsPreference.none
|
51
|
+
end
|
52
|
+
|
48
53
|
def to_h
|
49
54
|
Solr::Query::Request::EdismaxAdapter.new(self).to_h
|
50
55
|
end
|
@@ -33,6 +33,27 @@ module Solr
|
|
33
33
|
def current_core
|
34
34
|
Solr.current_core_config
|
35
35
|
end
|
36
|
+
|
37
|
+
def core_name_from_url(url)
|
38
|
+
full_solr_core_uri = URI.parse(url)
|
39
|
+
core_name = full_solr_core_uri.path.gsub('/solr', '').delete('/')
|
40
|
+
|
41
|
+
if !core_name || core_name == ''
|
42
|
+
raise Solr::Errors::CouldNotInferImplicitCoreName
|
43
|
+
end
|
44
|
+
|
45
|
+
core_name
|
46
|
+
end
|
47
|
+
|
48
|
+
def solr_endpoint_from_url(url)
|
49
|
+
solr_endpoint = url[/(\A.+\/solr)/]
|
50
|
+
|
51
|
+
if !solr_endpoint || solr_endpoint == ''
|
52
|
+
raise Solr::Errors::CouldNotDetectEndpointInUrl
|
53
|
+
end
|
54
|
+
|
55
|
+
solr_endpoint
|
56
|
+
end
|
36
57
|
end
|
37
58
|
end
|
38
59
|
end
|
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.2.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adriano Luz
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2022-08-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: addressable
|
@@ -176,6 +176,7 @@ files:
|
|
176
176
|
- lib/solr/document.rb
|
177
177
|
- lib/solr/document_collection.rb
|
178
178
|
- lib/solr/errors/ambiguous_core_error.rb
|
179
|
+
- lib/solr/errors/could_not_detect_endpoint_in_url.rb
|
179
180
|
- lib/solr/errors/could_not_infer_implicit_core_name.rb
|
180
181
|
- lib/solr/errors/no_active_solr_nodes_error.rb
|
181
182
|
- lib/solr/errors/solr_connection_failed_error.rb
|
@@ -216,6 +217,8 @@ files:
|
|
216
217
|
- lib/solr/query/request/geo_filter.rb
|
217
218
|
- lib/solr/query/request/grouping.rb
|
218
219
|
- lib/solr/query/request/or_filter.rb
|
220
|
+
- lib/solr/query/request/shards_preference.rb
|
221
|
+
- lib/solr/query/request/shards_preferences/property.rb
|
219
222
|
- lib/solr/query/request/sorting.rb
|
220
223
|
- lib/solr/query/request/sorting/field.rb
|
221
224
|
- lib/solr/query/request/sorting/function.rb
|