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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 356cd5b312edac759a4090191b33a48282a49b379bf44aecdf224ec47ce73fd0
4
- data.tar.gz: f0d399ed8c9eccfe86fffd3492ba248fe7b736407aee26a2465afa54962d89bd
3
+ metadata.gz: 393fd5007989a615a71cf31c0a774d83ebbca8336e9b3ec14ad559258142f365
4
+ data.tar.gz: 43d7a6f001622631805071b0e95ed0311b02d1af81b1219f3d19760b7c5c1f0c
5
5
  SHA512:
6
- metadata.gz: 7002601a792323c6533157152f92cab212e23fffd006f714f89b6f3610a20e4dfa35fab27451bb7a93b9e1f0e920e8b7081720e261143bb5568264a8d3817449
7
- data.tar.gz: d29a32a7d00f985bf38bf1f7c36a044f78064739999b318ef4d3070eb1e411a04124c7c3e9140a6afce92ef28df018c6caa1554b82a5a44d307292d41d7af95f
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
@@ -6,7 +6,6 @@ require "hashie"
6
6
 
7
7
  require "solrbee/version"
8
8
  require "solrbee/response"
9
- require "solrbee/request"
10
9
  require "solrbee/query"
11
10
  require "solrbee/client"
12
11
  require "solrbee/cursor"
@@ -2,59 +2,60 @@ module Solrbee
2
2
  module ApiMethods
3
3
 
4
4
  def ping
5
- response = Request.execute(self, '/admin/ping')
6
- response.status
5
+ response = request(path: '/admin/ping')
6
+ response['status']
7
7
  end
8
8
 
9
9
  def schema
10
- response = Request.execute(self, '/schema')
11
- response.schema
10
+ response = request(path: '/schema')
11
+ response['schema']
12
12
  end
13
13
 
14
14
  def schema_name
15
- response = Request.execute(self, '/schema/name')
16
- response.name
15
+ response = request(path: '/schema/name')
16
+ response['name']
17
17
  end
18
18
 
19
19
  def schema_version
20
- response = Request.execute(self, '/schema/version')
21
- response.version
20
+ response = request(path: '/schema/version')
21
+ response['version']
22
22
  end
23
23
 
24
24
  def fields(**params)
25
- response = Request.execute(self, '/schema/fields', params: params)
26
- response.fields
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 = Request.execute(self, '/schema/fields/%s' % field_name, params: params)
31
- response.field
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
- @unique_key ||= Request.execute(self, '/schema/uniquekey').uniqueKey
35
+ response = request(path: '/schema/uniquekey')
36
+ response['uniqueKey']
36
37
  end
37
38
 
38
39
  def field_types(**params)
39
- response = Request.execute(self, '/schema/fieldtypes', params: params)
40
- response.fieldTypes
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 = Request.execute(self, '/schema/fieldtypes/%s' % field_name, params: params)
45
- response.fieldType
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(&:name)
50
+ fields.map { |f| f['name'] }
50
51
  end
51
52
 
52
53
  def field_type_names
53
- field_types.map(&:name)
54
+ field_types.map { |f| f['name'] }
54
55
  end
55
56
 
56
57
  def modify_schema(commands)
57
- Request.execute(self, '/schema', data: commands)
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
- # Note: Using POST here for simpler params.
74
- def get_by_id(*ids)
75
- response = Request.execute(self, '/get', params: { id: ids.join(',') })
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
- Request.execute(self, '/update/json/docs', data: docs, params: params)
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
- Request.execute(self, '/update', data: { delete: ids })
86
+ request(path: '/update', data: { delete: ids })
87
87
  end
88
88
 
89
- def query(params)
90
- Request.execute(self, '/query', data: Query.new(params))
89
+ def query(**params)
90
+ request(path: '/query', data: params)
91
91
  end
92
92
 
93
93
  end
@@ -8,13 +8,14 @@ module Solrbee
8
8
  class Client
9
9
  include ApiMethods
10
10
 
11
- attr_reader :collection, :uri
11
+ attr_reader :uri
12
12
 
13
- def initialize(collection)
14
- @collection = collection
15
- @uri = URI(Solrbee.solr_url).tap do |u|
16
- u.path += '/%s' % URI.encode_www_form_component(collection)
17
- end
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
@@ -1,8 +1,8 @@
1
1
  module Solrbee
2
2
  #
3
- # Summary
3
+ # SUMMARY
4
4
  #
5
- # > client = Solrbee::Client.new('mycollection'))
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.num_found == 0
29
- break if response.nextCursorMark == q.params.cursorMark
30
- response.docs.each { |doc| yielder << doc }
31
- q.params.cursorMark = response.nextCursorMark
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
@@ -1,3 +1,3 @@
1
1
  module Solrbee
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.2
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-05 00:00:00.000000000 Z
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
@@ -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
@@ -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