solrbee 0.3.0 → 0.4.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 +4 -4
- data/Gemfile +2 -1
- data/Makefile +1 -6
- data/README.md +1 -11
- data/config/api.yml +22 -45
- data/lib/rom/solr.rb +40 -11
- data/lib/{solrbee → rom/solr}/array.rb +0 -0
- data/lib/rom/solr/commands.rb +17 -0
- data/lib/rom/solr/commands/create_documents.rb +15 -0
- data/lib/rom/solr/commands/delete_documents.rb +15 -0
- data/lib/rom/solr/commands/delete_documents_by_query.rb +15 -0
- data/lib/rom/solr/commands/update_documents.rb +15 -0
- data/lib/rom/solr/dataset.rb +33 -54
- data/lib/rom/solr/document_repo.rb +33 -0
- data/lib/rom/solr/documents_dataset.rb +12 -0
- data/lib/rom/solr/gateway.rb +2 -13
- data/lib/rom/solr/relation.rb +22 -8
- data/lib/rom/solr/relations/documents_relation.rb +160 -0
- data/lib/rom/solr/relations/schema_info_relation.rb +100 -0
- data/lib/rom/solr/repository.rb +9 -0
- data/lib/rom/solr/request_handler.rb +52 -0
- data/lib/rom/solr/{response.rb → response_handler.rb} +2 -2
- data/lib/rom/solr/schema.rb +1 -3
- data/lib/rom/solr/schema_info_dataset.rb +11 -0
- data/lib/rom/solr/schema_info_repo.rb +45 -0
- data/lib/rom/solr/select_cursor.rb +56 -0
- data/lib/solrbee.rb +12 -23
- data/lib/solrbee/version.rb +1 -1
- data/solrbee.gemspec +0 -1
- data/test.sh +14 -0
- metadata +19 -24
- data/lib/rom/solr/datasets/select_dataset.rb +0 -53
- data/lib/rom/solr/paginated_dataset.rb +0 -62
- data/lib/rom/solr/relations/schema_relation.rb +0 -75
- data/lib/rom/solr/relations/select_relation.rb +0 -43
- data/lib/rom/solr/request.rb +0 -24
- data/lib/rom/solr/schemaless.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11deb067a219ff325c0aa6dfaeb14422674cfd2a30338d14a1f00fa3f2081550
|
4
|
+
data.tar.gz: b6566f900e8a437feb379dba1e7f8de64e9c5a4b821cc501256ce0ee58da52e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa65e21c6552dc4d4276ecfdc1a4089e69d3625af84d014cb6353183a9e145ed8adf34158b180e2c70d1718d211e35b32fbd545438bd13753d171484b1577010
|
7
|
+
data.tar.gz: 78fd833f50640f5f875be47160a87642f2b612c90906e3d349e68042f5d267b4b375727babcc8c2512c90006e7e858535e2382ecfc638d7dff333822f20e04c4
|
data/Gemfile
CHANGED
data/Makefile
CHANGED
@@ -1,10 +1,5 @@
|
|
1
1
|
SHELL = /bin/bash
|
2
2
|
|
3
|
-
SOLR_URL = http://localhost:8983/solr/solrbee
|
4
|
-
|
5
3
|
.PHONY : test
|
6
4
|
test:
|
7
|
-
|
8
|
-
while ! curl -fs http://localhost:8983/solr/solrbee/admin/ping 2>/dev/null ; do sleep 1 ; done
|
9
|
-
SOLR_URL=$(SOLR_URL) bundle exec rake
|
10
|
-
docker stop solrbee-test
|
5
|
+
./test.sh
|
data/README.md
CHANGED
@@ -25,17 +25,7 @@ Or install it yourself as:
|
|
25
25
|
|
26
26
|
## Usage
|
27
27
|
|
28
|
-
|
29
|
-
$ bundle console
|
30
|
-
irb(main):001:0> client = Solrbee::Client.new('solrbee')
|
31
|
-
=> #<Solrbee::Client:0x00007fd3410d7c50 @collection="solrbee", @uri=#<URI::HTTP http://localhost:8983/solr/solrbee>>
|
32
|
-
irb(main):002:0> client.unique_key
|
33
|
-
=> "id"
|
34
|
-
irb(main):003:0> client.schema_version
|
35
|
-
=> 1.6
|
36
|
-
irb(main):004:0> client.schema_name
|
37
|
-
=> "default-config"
|
38
|
-
```
|
28
|
+
TODO
|
39
29
|
|
40
30
|
## Development
|
41
31
|
|
data/config/api.yml
CHANGED
@@ -1,45 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
path: /schema/fields/%{name}
|
24
|
-
response_key: field
|
25
|
-
|
26
|
-
unique_key:
|
27
|
-
path: /schema/uniquekey
|
28
|
-
response_key: uniqueKey
|
29
|
-
|
30
|
-
field_types:
|
31
|
-
path: /schema/fieldtypes
|
32
|
-
response_key: fieldTypes
|
33
|
-
|
34
|
-
field_type:
|
35
|
-
path: /schema/fieldtypes/%{name}
|
36
|
-
response_key: fieldType
|
37
|
-
|
38
|
-
update:
|
39
|
-
path: /update
|
40
|
-
|
41
|
-
update_json:
|
42
|
-
path: /update/json
|
43
|
-
|
44
|
-
update_json_docs:
|
45
|
-
path: /update/json/docs
|
1
|
+
field_types:
|
2
|
+
path: fieldtypes
|
3
|
+
key: fieldTypes
|
4
|
+
field_type:
|
5
|
+
desc: GET /schema/fieldtype/[name]
|
6
|
+
path: fieldtypes/%{name}
|
7
|
+
args:
|
8
|
+
- name
|
9
|
+
key: fieldType
|
10
|
+
dynamic_fields:
|
11
|
+
desc: GET /schema/dynamicfields
|
12
|
+
path: dynamicfields
|
13
|
+
key: dynamicFields
|
14
|
+
dynamic_field:
|
15
|
+
desc: GET /schema/dynamicfields/[name]
|
16
|
+
args:
|
17
|
+
- name
|
18
|
+
path: dynamicfields/%{name}
|
19
|
+
key: dynamicField
|
20
|
+
copy_fields:
|
21
|
+
path: copyfields
|
22
|
+
key: copyFields
|
data/lib/rom/solr.rb
CHANGED
@@ -1,22 +1,51 @@
|
|
1
1
|
require 'rom-http'
|
2
|
+
require 'securerandom'
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
module ROM
|
5
|
+
module Solr
|
6
|
+
|
7
|
+
def self.dataset_class(name)
|
8
|
+
prefix = name.to_s.split(/[_\/]/).map(&:capitalize).join('')
|
9
|
+
const_name = "#{prefix}Dataset"
|
10
|
+
const_defined?(const_name, false) ? const_get(const_name, false) : Dataset
|
11
|
+
end
|
12
|
+
|
13
|
+
module Types
|
14
|
+
include ROM::HTTP::Types
|
15
|
+
end
|
16
|
+
|
17
|
+
UUID = Types::String.default { SecureRandom.uuid }
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
5
21
|
|
22
|
+
# Utilities
|
23
|
+
require_relative 'solr/array'
|
24
|
+
|
25
|
+
# Handlers
|
26
|
+
require_relative 'solr/request_handler'
|
27
|
+
require_relative 'solr/response_handler'
|
28
|
+
|
29
|
+
# Datasets
|
6
30
|
require_relative 'solr/dataset'
|
7
|
-
require_relative 'solr/
|
31
|
+
require_relative 'solr/documents_dataset'
|
32
|
+
require_relative 'solr/schema_info_dataset'
|
8
33
|
|
34
|
+
# Gateway
|
9
35
|
require_relative 'solr/gateway'
|
10
36
|
|
11
|
-
|
37
|
+
# Schemas
|
38
|
+
require_relative 'solr/schema'
|
12
39
|
|
40
|
+
# Relations
|
13
41
|
require_relative 'solr/relation'
|
14
|
-
require_relative 'solr/relations/schema_relation'
|
15
|
-
require_relative 'solr/relations/select_relation'
|
16
42
|
|
17
|
-
|
18
|
-
|
19
|
-
|
43
|
+
# Repositories
|
44
|
+
require_relative 'solr/repository'
|
45
|
+
require_relative 'solr/schema_info_repo'
|
46
|
+
require_relative 'solr/document_repo'
|
20
47
|
|
21
|
-
|
22
|
-
|
48
|
+
# Commands
|
49
|
+
require_relative 'solr/commands'
|
50
|
+
|
51
|
+
ROM.register_adapter(:solr, ROM::Solr)
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ROM
|
2
|
+
module Solr
|
3
|
+
module Commands
|
4
|
+
class Create < ROM::Commands::Create
|
5
|
+
adapter :solr
|
6
|
+
end
|
7
|
+
|
8
|
+
class Update < ROM::Commands::Update
|
9
|
+
adapter :solr
|
10
|
+
end
|
11
|
+
|
12
|
+
class Delete < ROM::Commands::Delete
|
13
|
+
adapter :solr
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/rom/solr/dataset.rb
CHANGED
@@ -2,60 +2,42 @@ module ROM
|
|
2
2
|
module Solr
|
3
3
|
class Dataset < ROM::HTTP::Dataset
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
setting :
|
8
|
-
option :enum_on, default: ->{ self.class.default_enum_on }
|
9
|
-
|
10
|
-
# Default query parameters
|
11
|
-
setting :default_params, EMPTY_HASH, reader: true
|
12
|
-
option :params, type: Types::Hash, default: ->{ self.class.default_params }
|
13
|
-
|
14
|
-
# Request and response handlers
|
15
|
-
config.default_response_handler = Response
|
16
|
-
config.default_request_handler = Request
|
17
|
-
|
18
|
-
# @override Handles multiple path segments and nils
|
19
|
-
def with_path(segments)
|
20
|
-
s = Array.wrap(segments)
|
21
|
-
return self if s.empty?
|
22
|
-
with_options(path: s.compact.join('/'))
|
23
|
-
end
|
5
|
+
setting :default_response_key, reader: true
|
6
|
+
setting :default_content_type, reader: true
|
7
|
+
setting :default_base_path, reader: true
|
24
8
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
with_options(enum_on: k)
|
9
|
+
configure do |config|
|
10
|
+
config.default_response_handler = ResponseHandler
|
11
|
+
config.default_request_handler = RequestHandler
|
29
12
|
end
|
30
13
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
14
|
+
option :response_key, default: proc { self.class.default_response_key }
|
15
|
+
option :request_data, type: Types::String, default: proc { EMPTY_STRING }
|
16
|
+
option :content_type, type: Types::String, default: proc { self.class.default_content_type }
|
17
|
+
option :base_path, type: Types::Path, default: proc { self.class.default_base_path || EMPTY_STRING }
|
18
|
+
|
19
|
+
# @override Query parameters are valid with POST, too.
|
20
|
+
def uri
|
21
|
+
uri_s = [options[:uri], path].compact.reject(&:empty?).join('/')
|
22
|
+
|
23
|
+
URI(uri_s).tap do |u|
|
24
|
+
u.query = param_encoder.call(params) if has_params?
|
25
|
+
end
|
36
26
|
end
|
37
27
|
|
38
28
|
# @override
|
39
|
-
def
|
40
|
-
return
|
41
|
-
with_params params.merge(new_params).compact
|
42
|
-
end
|
29
|
+
def each(&block)
|
30
|
+
return to_enum unless block_given?
|
43
31
|
|
44
|
-
|
45
|
-
with_params defaults.merge(params)
|
32
|
+
enumerable_data.each(&block)
|
46
33
|
end
|
47
34
|
|
48
|
-
|
49
|
-
|
50
|
-
if params == new_params
|
51
|
-
self
|
52
|
-
else
|
53
|
-
with_options(params: new_params)
|
54
|
-
end
|
35
|
+
def with_request_data(data)
|
36
|
+
with_options(request_data: data)
|
55
37
|
end
|
56
38
|
|
57
|
-
def
|
58
|
-
|
39
|
+
def with_response_key(*path)
|
40
|
+
with_options(response_key: path)
|
59
41
|
end
|
60
42
|
|
61
43
|
# Copies and makes private superclass #response method
|
@@ -67,23 +49,20 @@ module ROM
|
|
67
49
|
cache.fetch_or_store(:response) { __response__ }
|
68
50
|
end
|
69
51
|
|
70
|
-
|
71
|
-
|
72
|
-
return to_enum unless block_given?
|
73
|
-
enumerable_response.each(&block)
|
52
|
+
def has_request_data?
|
53
|
+
!request_data.nil? && !request_data.empty?
|
74
54
|
end
|
75
55
|
|
76
|
-
def
|
77
|
-
|
78
|
-
Array.wrap(response)
|
79
|
-
else
|
80
|
-
keys = Array.wrap options[:enum_on]
|
81
|
-
Array.wrap response.dig(*keys)
|
82
|
-
end
|
56
|
+
def has_params?
|
57
|
+
params.any?
|
83
58
|
end
|
84
59
|
|
85
60
|
private
|
86
61
|
|
62
|
+
def enumerable_data
|
63
|
+
Array.wrap(response_key ? response.dig(*response_key) : response)
|
64
|
+
end
|
65
|
+
|
87
66
|
def cache
|
88
67
|
@cache ||= Concurrent::Map.new
|
89
68
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module ROM
|
2
|
+
module Solr
|
3
|
+
class DocumentRepo < Repository[:documents]
|
4
|
+
|
5
|
+
auto_struct false
|
6
|
+
|
7
|
+
def find(id)
|
8
|
+
documents.by_unique_key(id).one!
|
9
|
+
end
|
10
|
+
|
11
|
+
def search
|
12
|
+
documents
|
13
|
+
end
|
14
|
+
|
15
|
+
def all
|
16
|
+
documents.all
|
17
|
+
end
|
18
|
+
|
19
|
+
def create(docs)
|
20
|
+
documents.command(:create_documents).call(docs)
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete(docs)
|
24
|
+
documents.command(:delete_documents).call(docs)
|
25
|
+
end
|
26
|
+
|
27
|
+
def update(docs)
|
28
|
+
documents.command(:update_documents).call(docs)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/rom/solr/gateway.rb
CHANGED
@@ -4,20 +4,9 @@ module ROM
|
|
4
4
|
|
5
5
|
adapter :solr
|
6
6
|
|
7
|
-
|
8
|
-
config[:uri] ||= ENV.fetch('SOLR_URL', 'http://localhost:8983/solr')
|
9
|
-
config[:headers] ||= { Accept: 'application/json' }
|
10
|
-
super
|
11
|
-
end
|
12
|
-
|
7
|
+
# @override
|
13
8
|
def dataset(name)
|
14
|
-
dataset_class(name).new
|
15
|
-
end
|
16
|
-
|
17
|
-
def dataset_class(name)
|
18
|
-
prefix = name.to_s.split(/_/).map(&:capitalize).join('')
|
19
|
-
const_name = "#{prefix}Dataset"
|
20
|
-
ROM::Solr.const_defined?(const_name, false) ? ROM::Solr.const_get(const_name, false) : Dataset
|
9
|
+
ROM::Solr.dataset_class(name).new(config)
|
21
10
|
end
|
22
11
|
|
23
12
|
end
|