solrbee 0.1.1 → 0.1.2

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: 77127390eb03bfbd53eec6916f7873fab49b6436f4acb94c528f2cec7ed5f76b
4
- data.tar.gz: '08ab2300881e0fdacaafa0007d1a17031a2b11bebfe2ade9cbf533a02a7b2b42'
3
+ metadata.gz: 356cd5b312edac759a4090191b33a48282a49b379bf44aecdf224ec47ce73fd0
4
+ data.tar.gz: f0d399ed8c9eccfe86fffd3492ba248fe7b736407aee26a2465afa54962d89bd
5
5
  SHA512:
6
- metadata.gz: 5642a45f1013a4ddf33f4a339f0990ec218d7c3ebce3e6b3e1a0811c81256a6c155df333d7894618de9cb4a8b9e7c9eac5f178237474e96cd2de5ec7193cee83
7
- data.tar.gz: bba5257728a581433cf72dbd4dce18ab5f8f7baea95afca7dca75c16f5fc17b509110c9e8ecb9a87713960f3eccf951d0bf11a0afe8b4ba01de2f331fcefd095
6
+ metadata.gz: 7002601a792323c6533157152f92cab212e23fffd006f714f89b6f3610a20e4dfa35fab27451bb7a93b9e1f0e920e8b7081720e261143bb5568264a8d3817449
7
+ data.tar.gz: d29a32a7d00f985bf38bf1f7c36a044f78064739999b318ef4d3070eb1e411a04124c7c3e9140a6afce92ef28df018c6caa1554b82a5a44d307292d41d7af95f
data/Makefile CHANGED
@@ -2,13 +2,7 @@ SHELL = /bin/bash
2
2
 
3
3
  .PHONY : test
4
4
  test:
5
- bundle exec rake
6
-
7
-
8
- .PHONY : start-test-server
9
- start-test-server:
10
5
  docker run --rm -d -p 8983:8983 --name solrbee-test solr:8 solr-precreate solrbee
11
-
12
- .PHONY : stop-test-server
13
- stop-test-server:
6
+ while ! curl -fs http://localhost:8983/solr/solrbee/admin/ping 2>/dev/null ; do sleep 1 ; done
7
+ bundle exec rake
14
8
  docker stop solrbee-test
data/README.md CHANGED
@@ -25,7 +25,17 @@ Or install it yourself as:
25
25
 
26
26
  ## Usage
27
27
 
28
-
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
+ ```
29
39
 
30
40
  ## Development
31
41
 
@@ -1,6 +1,12 @@
1
+ require "json"
2
+ require "net/http"
3
+ require "uri"
4
+
5
+ require "hashie"
6
+
1
7
  require "solrbee/version"
2
8
  require "solrbee/response"
3
- require "solrbee/request_params"
9
+ require "solrbee/request"
4
10
  require "solrbee/query"
5
11
  require "solrbee/client"
6
12
  require "solrbee/cursor"
@@ -9,6 +15,8 @@ module Solrbee
9
15
 
10
16
  class Error < StandardError; end
11
17
 
18
+ API_VERSION = 'V1'
19
+
12
20
  # Single-valued field types
13
21
  STRING = "string"
14
22
  LONG = "plong"
@@ -1,42 +1,47 @@
1
1
  module Solrbee
2
2
  module ApiMethods
3
3
 
4
+ def ping
5
+ response = Request.execute(self, '/admin/ping')
6
+ response.status
7
+ end
8
+
9
+ def schema
10
+ response = Request.execute(self, '/schema')
11
+ response.schema
12
+ end
13
+
4
14
  def schema_name
5
- response = get('/schema/name')
15
+ response = Request.execute(self, '/schema/name')
6
16
  response.name
7
17
  end
8
18
 
9
19
  def schema_version
10
- response = get('/schema/version')
20
+ response = Request.execute(self, '/schema/version')
11
21
  response.version
12
22
  end
13
23
 
14
- def schema
15
- response = get('/schema')
16
- response.schema
17
- end
18
-
19
24
  def fields(**params)
20
- response = get('/schema/fields', **params)
25
+ response = Request.execute(self, '/schema/fields', params: params)
21
26
  response.fields
22
27
  end
23
28
 
24
29
  def field(field_name, **params)
25
- response = get('/schema/fields/%s' % field_name, **params)
30
+ response = Request.execute(self, '/schema/fields/%s' % field_name, params: params)
26
31
  response.field
27
32
  end
28
33
 
29
34
  def unique_key
30
- @unique_key ||= get('/schema/uniquekey').uniqueKey
35
+ @unique_key ||= Request.execute(self, '/schema/uniquekey').uniqueKey
31
36
  end
32
37
 
33
38
  def field_types(**params)
34
- response = get('/schema/fieldtypes', **params)
39
+ response = Request.execute(self, '/schema/fieldtypes', params: params)
35
40
  response.fieldTypes
36
41
  end
37
42
 
38
43
  def field_type(field_name, **params)
39
- response = get('/schema/fieldtypes/%s' % field_name, **params)
44
+ response = Request.execute(self, '/schema/fieldtypes/%s' % field_name, params: params)
40
45
  response.fieldType
41
46
  end
42
47
 
@@ -48,37 +53,41 @@ module Solrbee
48
53
  field_types.map(&:name)
49
54
  end
50
55
 
56
+ def modify_schema(commands)
57
+ Request.execute(self, '/schema', data: commands)
58
+ end
59
+
51
60
  def add_field(field)
52
- post('/schema', {"add-field"=>field})
61
+ modify_schema("add-field"=>field)
53
62
  end
54
63
 
55
- def delete_field(field)
56
- post('/schema', {"delete-field"=>{"name"=>field.name}})
64
+ def delete_field(field_name)
65
+ modify_schema("delete-field"=>{"name"=>field_name})
57
66
  end
58
67
 
59
68
  def replace_field(field)
60
- post('/schema', {"replace-field"=>field})
69
+ modify_schema("replace-field"=>field)
61
70
  end
62
71
 
63
72
  # "real-time get"
64
73
  # Note: Using POST here for simpler params.
65
74
  def get_by_id(*ids)
66
- response = post('/get', params: { id: ids })
75
+ response = Request.execute(self, '/get', params: { id: ids.join(',') })
67
76
  response.doc || response.docs
68
77
  end
69
78
 
70
79
  def index(*docs, **params)
71
- post('/update/json/docs', docs, **params)
80
+ Request.execute(self, '/update/json/docs', data: docs, params: params)
72
81
  end
73
82
  alias_method :add, :index
74
83
  alias_method :update, :index
75
84
 
76
85
  def delete(*ids)
77
- post('/update', delete: ids)
86
+ Request.execute(self, '/update', data: { delete: ids })
78
87
  end
79
88
 
80
89
  def query(params)
81
- post('/query', Query.new(params))
90
+ Request.execute(self, '/query', data: Query.new(params))
82
91
  end
83
92
 
84
93
  end
@@ -23,34 +23,6 @@ module Solrbee
23
23
  end
24
24
  end
25
25
 
26
- # :get -> Net::HTTP::Get
27
- def request_class(method)
28
- Net::HTTP.const_get(method.to_s.downcase.capitalize)
29
- end
30
-
31
- def request(method, path, **params)
32
- req_uri = uri.dup
33
- req_uri.path += path
34
- unless params.empty?
35
- req_uri.query = URI.encode_www_form RequestParams.new(params)
36
- end
37
- req = request_class(method).new(req_uri, {'Accept'=>'application/json'})
38
- yield req if block_given?
39
- res = connection.request(req)
40
- Response.new JSON.parse(res.body)
41
- end
42
-
43
- def get(path, **params)
44
- request(:get, path, **params)
45
- end
46
-
47
- def post(path, data, **params)
48
- request(:post, path, **params) do |req|
49
- req['Content-Type'] = 'application/json'
50
- req.body = JSON.dump(data)
51
- end
52
- end
53
-
54
26
  def cursor
55
27
  Cursor.new(self)
56
28
  end
@@ -5,16 +5,15 @@ module Solrbee
5
5
  # A query targeting the JSON Request API.
6
6
  #
7
7
  class Query < Hashie::Trash
8
-
9
- property :query, from: :q, default: '*:*'
8
+ property :query, from: :q, default: '*:*'
10
9
  property :filter, from: :fq
11
- property :limit, from: :rows, default: 10
10
+ property :limit, from: :rows, default: 10
12
11
  property :fields, from: :fl
13
12
  property :sort
14
13
  property :offset, from: :start
15
14
  property :facet
16
15
  property :queries
17
- property :params, default: {}
16
+ property :params, default: {}
18
17
 
19
18
  # Build a query for a Cursor
20
19
  def self.cursor(params, unique_key)
@@ -0,0 +1,45 @@
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,3 +1,3 @@
1
1
  module Solrbee
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
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.1
4
+ version: 0.1.2
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-04 00:00:00.000000000 Z
11
+ date: 2020-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -101,7 +101,7 @@ files:
101
101
  - lib/solrbee/client.rb
102
102
  - lib/solrbee/cursor.rb
103
103
  - lib/solrbee/query.rb
104
- - lib/solrbee/request_params.rb
104
+ - lib/solrbee/request.rb
105
105
  - lib/solrbee/response.rb
106
106
  - lib/solrbee/version.rb
107
107
  - solrbee.gemspec
@@ -1,13 +0,0 @@
1
- require 'hashie'
2
-
3
- module Solrbee
4
- #
5
- # For marshalling various API request query parameters
6
- #
7
- class RequestParams < Hashie::Trash
8
- property :showDefaults, from: :show_defaults
9
- property :includeDynamic, from: :include_dynamic
10
- property :fl
11
- property :commit
12
- end
13
- end