solrbee 0.1.2 → 0.2.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/Makefile +3 -1
- data/lib/solrbee.rb +0 -1
- data/lib/solrbee/api_methods.rb +28 -28
- data/lib/solrbee/client.rb +27 -6
- data/lib/solrbee/cursor.rb +6 -6
- data/lib/solrbee/version.rb +1 -1
- metadata +2 -4
- data/lib/solrbee/request.rb +0 -45
- data/lib/solrbee/response.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 393fd5007989a615a71cf31c0a774d83ebbca8336e9b3ec14ad559258142f365
|
4
|
+
data.tar.gz: 43d7a6f001622631805071b0e95ed0311b02d1af81b1219f3d19760b7c5c1f0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b19fb64da3cbed12d11351fa84786125948515814122787fc6e131160f3e124c12895d6bc97990e076db723b8ca679a9cb84578e184e1d714e9f726a89380ad8
|
7
|
+
data.tar.gz: 6f3b14f05faf6cc4afae23d3f35ced388e2f9d86f925254c6354210d47ede80dcae8c27c61a89e5da5a331aa1e43903ff3cf3893b9e07dff718ff7113fba7f9e
|
data/Makefile
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
SHELL = /bin/bash
|
2
2
|
|
3
|
+
SOLR_URL = http://localhost:8983/solr/solrbee
|
4
|
+
|
3
5
|
.PHONY : test
|
4
6
|
test:
|
5
7
|
docker run --rm -d -p 8983:8983 --name solrbee-test solr:8 solr-precreate solrbee
|
6
8
|
while ! curl -fs http://localhost:8983/solr/solrbee/admin/ping 2>/dev/null ; do sleep 1 ; done
|
7
|
-
bundle exec rake
|
9
|
+
SOLR_URL=$(SOLR_URL) bundle exec rake
|
8
10
|
docker stop solrbee-test
|
data/lib/solrbee.rb
CHANGED
data/lib/solrbee/api_methods.rb
CHANGED
@@ -2,59 +2,60 @@ module Solrbee
|
|
2
2
|
module ApiMethods
|
3
3
|
|
4
4
|
def ping
|
5
|
-
response =
|
6
|
-
response
|
5
|
+
response = request(path: '/admin/ping')
|
6
|
+
response['status']
|
7
7
|
end
|
8
8
|
|
9
9
|
def schema
|
10
|
-
response =
|
11
|
-
response
|
10
|
+
response = request(path: '/schema')
|
11
|
+
response['schema']
|
12
12
|
end
|
13
13
|
|
14
14
|
def schema_name
|
15
|
-
response =
|
16
|
-
response
|
15
|
+
response = request(path: '/schema/name')
|
16
|
+
response['name']
|
17
17
|
end
|
18
18
|
|
19
19
|
def schema_version
|
20
|
-
response =
|
21
|
-
response
|
20
|
+
response = request(path: '/schema/version')
|
21
|
+
response['version']
|
22
22
|
end
|
23
23
|
|
24
24
|
def fields(**params)
|
25
|
-
response =
|
26
|
-
response
|
25
|
+
response = request(path: '/schema/fields', params: params)
|
26
|
+
response['fields']
|
27
27
|
end
|
28
28
|
|
29
29
|
def field(field_name, **params)
|
30
|
-
response =
|
31
|
-
response
|
30
|
+
response = request(path: '/schema/fields/%s' % field_name, params: params)
|
31
|
+
response['field']
|
32
32
|
end
|
33
33
|
|
34
34
|
def unique_key
|
35
|
-
|
35
|
+
response = request(path: '/schema/uniquekey')
|
36
|
+
response['uniqueKey']
|
36
37
|
end
|
37
38
|
|
38
39
|
def field_types(**params)
|
39
|
-
response =
|
40
|
-
response
|
40
|
+
response = request(path: '/schema/fieldtypes', params: params)
|
41
|
+
response['fieldTypes']
|
41
42
|
end
|
42
43
|
|
43
44
|
def field_type(field_name, **params)
|
44
|
-
response =
|
45
|
-
response
|
45
|
+
response = request(path: '/schema/fieldtypes/%s' % field_name, params: params)
|
46
|
+
response['fieldType']
|
46
47
|
end
|
47
48
|
|
48
49
|
def field_names
|
49
|
-
fields.map
|
50
|
+
fields.map { |f| f['name'] }
|
50
51
|
end
|
51
52
|
|
52
53
|
def field_type_names
|
53
|
-
field_types.map
|
54
|
+
field_types.map { |f| f['name'] }
|
54
55
|
end
|
55
56
|
|
56
57
|
def modify_schema(commands)
|
57
|
-
|
58
|
+
request(path: '/schema', data: commands)
|
58
59
|
end
|
59
60
|
|
60
61
|
def add_field(field)
|
@@ -70,24 +71,23 @@ module Solrbee
|
|
70
71
|
end
|
71
72
|
|
72
73
|
# "real-time get"
|
73
|
-
|
74
|
-
|
75
|
-
response
|
76
|
-
response.doc || response.docs
|
74
|
+
def get_by_id(*ids, **params)
|
75
|
+
response = request(path: '/get', params: params.merge(id: ids.join(',')))
|
76
|
+
response['response']['doc'] || response['response']['docs']
|
77
77
|
end
|
78
78
|
|
79
79
|
def index(*docs, **params)
|
80
|
-
|
80
|
+
request(path: '/update/json/docs', data: docs, params: params)
|
81
81
|
end
|
82
82
|
alias_method :add, :index
|
83
83
|
alias_method :update, :index
|
84
84
|
|
85
85
|
def delete(*ids)
|
86
|
-
|
86
|
+
request(path: '/update', data: { delete: ids })
|
87
87
|
end
|
88
88
|
|
89
|
-
def query(params)
|
90
|
-
|
89
|
+
def query(**params)
|
90
|
+
request(path: '/query', data: params)
|
91
91
|
end
|
92
92
|
|
93
93
|
end
|
data/lib/solrbee/client.rb
CHANGED
@@ -8,13 +8,14 @@ module Solrbee
|
|
8
8
|
class Client
|
9
9
|
include ApiMethods
|
10
10
|
|
11
|
-
attr_reader :
|
11
|
+
attr_reader :uri
|
12
12
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
def self.cursor(url: nil)
|
14
|
+
new(url: url).cursor
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(url: nil)
|
18
|
+
@uri = URI(url || ENV['SOLR_URL'])
|
18
19
|
end
|
19
20
|
|
20
21
|
def connection
|
@@ -27,5 +28,25 @@ module Solrbee
|
|
27
28
|
Cursor.new(self)
|
28
29
|
end
|
29
30
|
|
31
|
+
def request(path:, data: nil, params: {})
|
32
|
+
req_class = data ? Net::HTTP::Post : Net::HTTP::Get
|
33
|
+
|
34
|
+
req_uri = uri.dup.tap do |u|
|
35
|
+
u.path += path
|
36
|
+
u.query = URI.encode_www_form(params) unless params.empty?
|
37
|
+
end
|
38
|
+
|
39
|
+
req = req_class.new(req_uri)
|
40
|
+
req['Accept'] = 'application/json'
|
41
|
+
|
42
|
+
if data
|
43
|
+
req['Content-Type'] = 'application/json'
|
44
|
+
req.body = JSON.dump(data)
|
45
|
+
end
|
46
|
+
|
47
|
+
http_response = connection.request(req)
|
48
|
+
JSON.parse(http_response.body)
|
49
|
+
end
|
50
|
+
|
30
51
|
end
|
31
52
|
end
|
data/lib/solrbee/cursor.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Solrbee
|
2
2
|
#
|
3
|
-
#
|
3
|
+
# SUMMARY
|
4
4
|
#
|
5
|
-
# > client = Solrbee::Client.new
|
5
|
+
# > client = Solrbee::Client.new
|
6
6
|
# > cursor = Solrbee::Cursor.new(client)
|
7
7
|
# > query = { query: 'foo:bar', sort: 'title ASC', limit: 10 }
|
8
8
|
# > results = cursor.execute(query)
|
@@ -25,10 +25,10 @@ module Solrbee
|
|
25
25
|
|
26
26
|
while true
|
27
27
|
response = client.query(q)
|
28
|
-
break if response
|
29
|
-
break if response
|
30
|
-
response
|
31
|
-
q.params.cursorMark = response
|
28
|
+
break if response['response']['numFound'] == 0
|
29
|
+
break if response['nextCursorMark'] == q.params.cursorMark
|
30
|
+
response['response']['docs'].each { |doc| yielder << doc }
|
31
|
+
q.params.cursorMark = response['nextCursorMark']
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
data/lib/solrbee/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solrbee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Chandek-Stark
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -101,8 +101,6 @@ files:
|
|
101
101
|
- lib/solrbee/client.rb
|
102
102
|
- lib/solrbee/cursor.rb
|
103
103
|
- lib/solrbee/query.rb
|
104
|
-
- lib/solrbee/request.rb
|
105
|
-
- lib/solrbee/response.rb
|
106
104
|
- lib/solrbee/version.rb
|
107
105
|
- solrbee.gemspec
|
108
106
|
homepage: https://github.com/dchandekstark/solrbee
|
data/lib/solrbee/request.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
module Solrbee
|
2
|
-
class Request
|
3
|
-
|
4
|
-
attr_reader :client, :path, :data, :params
|
5
|
-
|
6
|
-
def self.execute(*args)
|
7
|
-
new(*args).execute
|
8
|
-
end
|
9
|
-
|
10
|
-
def initialize(client, path, data: nil, params: {})
|
11
|
-
@client = client
|
12
|
-
@path = path
|
13
|
-
@data = data
|
14
|
-
@params = params
|
15
|
-
end
|
16
|
-
|
17
|
-
def request_class
|
18
|
-
data ? Net::HTTP::Post : Net::HTTP::Get
|
19
|
-
end
|
20
|
-
|
21
|
-
def headers
|
22
|
-
Hash.new.tap do |h|
|
23
|
-
h['Accept'] = 'application/json'
|
24
|
-
h['Content-Type'] = 'application/json' if data
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def uri
|
29
|
-
client.uri.dup.tap do |u|
|
30
|
-
u.path += path
|
31
|
-
unless params.empty?
|
32
|
-
u.query = URI.encode_www_form(params)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def execute
|
38
|
-
req = request_class.new(uri, headers)
|
39
|
-
req.body = JSON.dump(data) if data
|
40
|
-
http_response = client.connection.request(req)
|
41
|
-
Response.new JSON.parse(http_response.body)
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
data/lib/solrbee/response.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'hashie'
|
2
|
-
|
3
|
-
module Solrbee
|
4
|
-
class Response < Hashie::Mash
|
5
|
-
|
6
|
-
disable_warnings
|
7
|
-
|
8
|
-
def header
|
9
|
-
responseHeader
|
10
|
-
end
|
11
|
-
|
12
|
-
def num_found
|
13
|
-
response.numFound
|
14
|
-
end
|
15
|
-
|
16
|
-
def docs
|
17
|
-
response.docs
|
18
|
-
end
|
19
|
-
|
20
|
-
def doc
|
21
|
-
response.doc
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|