solrbee 0.1.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/Makefile +1 -4
- data/README.md +1 -11
- data/config/api.yml +22 -0
- data/lib/rom/solr.rb +56 -0
- data/lib/rom/solr/array.rb +10 -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 +68 -0
- data/lib/rom/solr/document_repo.rb +45 -0
- data/lib/rom/solr/documents_dataset.rb +62 -0
- data/lib/rom/solr/documents_paginator.rb +21 -0
- data/lib/rom/solr/gateway.rb +14 -0
- data/lib/rom/solr/query.rb +135 -0
- data/lib/rom/solr/query_builder.rb +36 -0
- data/lib/rom/solr/query_templates.rb +34 -0
- data/lib/rom/solr/relation.rb +39 -0
- data/lib/rom/solr/relations/documents_relation.rb +215 -0
- data/lib/rom/solr/relations/schema_info_relation.rb +78 -0
- data/lib/rom/solr/repository.rb +9 -0
- data/lib/rom/solr/request_handler.rb +52 -0
- data/lib/rom/solr/response_handler.rb +12 -0
- data/lib/rom/solr/schema.rb +7 -0
- data/lib/rom/solr/schema_info_dataset.rb +19 -0
- data/lib/rom/solr/schema_info_repo.rb +29 -0
- data/lib/rom/solr/utils.rb +36 -0
- data/lib/solrbee.rb +22 -28
- data/lib/solrbee/version.rb +1 -1
- data/solrbee.gemspec +3 -1
- data/test.sh +14 -0
- metadata +58 -9
- data/lib/solrbee/api_methods.rb +0 -94
- data/lib/solrbee/client.rb +0 -31
- data/lib/solrbee/cursor.rb +0 -37
- data/lib/solrbee/query.rb +0 -35
- data/lib/solrbee/request.rb +0 -45
- data/lib/solrbee/response.rb +0 -25
@@ -0,0 +1,19 @@
|
|
1
|
+
module ROM
|
2
|
+
module Solr
|
3
|
+
class SchemaInfoDataset < Dataset
|
4
|
+
|
5
|
+
configure do |config|
|
6
|
+
config.default_base_path = 'schema'
|
7
|
+
|
8
|
+
config.default_response_handler = Proc.new do |*args|
|
9
|
+
ResponseHandler.call(*args).values.flatten
|
10
|
+
end
|
11
|
+
|
12
|
+
config.default_request_handler = Proc.new do |dataset|
|
13
|
+
RequestHandler.call(dataset.add_params(omitHeader: true))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module ROM
|
4
|
+
module Solr
|
5
|
+
class SchemaInfoRepo < Repository[:schema_info]
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
auto_struct false
|
9
|
+
|
10
|
+
VALUES = %i[ schema_name
|
11
|
+
similarity
|
12
|
+
unique_key
|
13
|
+
version
|
14
|
+
info
|
15
|
+
field
|
16
|
+
field_type
|
17
|
+
dynamic_field
|
18
|
+
copy_field
|
19
|
+
]
|
20
|
+
|
21
|
+
def_delegators :schema_info, :fields, :field_types, :dynamic_fields, :copy_fields
|
22
|
+
|
23
|
+
VALUES.each do |name|
|
24
|
+
define_method name, proc { |*args| schema_info.send(name, *args).one! }
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'time'
|
3
|
+
|
4
|
+
module ROM
|
5
|
+
module Solr
|
6
|
+
module Utils
|
7
|
+
|
8
|
+
def phrase(value)
|
9
|
+
if value.match?(/ /)
|
10
|
+
'"%s"' % value.gsub(/"/, '\"')
|
11
|
+
else
|
12
|
+
value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Escape a Solr query value
|
17
|
+
#
|
18
|
+
# @param value [String] raw value
|
19
|
+
# @return [String] escaped value
|
20
|
+
def escape(value)
|
21
|
+
value
|
22
|
+
.gsub(ESCAPE_CHARS, '\\1')
|
23
|
+
.gsub(DOUBLE_AMPERSAND, '\&\&')
|
24
|
+
.gsub(DOUBLE_PIPE, '\|\|')
|
25
|
+
end
|
26
|
+
|
27
|
+
# Formats a value as a Solr date.
|
28
|
+
def solr_date(value)
|
29
|
+
DateTime.parse(value.to_s).to_time.utc.iso8601
|
30
|
+
end
|
31
|
+
|
32
|
+
extend self
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/solrbee.rb
CHANGED
@@ -1,39 +1,33 @@
|
|
1
|
-
require
|
2
|
-
require "net/http"
|
3
|
-
require "uri"
|
1
|
+
require 'solrbee/version'
|
4
2
|
|
5
|
-
require
|
6
|
-
|
7
|
-
require "solrbee/version"
|
8
|
-
require "solrbee/response"
|
9
|
-
require "solrbee/request"
|
10
|
-
require "solrbee/query"
|
11
|
-
require "solrbee/client"
|
12
|
-
require "solrbee/cursor"
|
3
|
+
require 'dry-types'
|
4
|
+
require 'rom/solr'
|
13
5
|
|
14
6
|
module Solrbee
|
15
7
|
|
16
|
-
|
8
|
+
DEFAULT_URI = ENV.fetch('SOLR_URL', 'http://localhost:8983/solr').freeze
|
17
9
|
|
18
|
-
|
10
|
+
def self.documents
|
11
|
+
ROM::Solr::DocumentRepo.new(container)
|
12
|
+
end
|
19
13
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
INT = "pint"
|
24
|
-
DATE = "pdate"
|
25
|
-
BOOLEAN = "boolean"
|
14
|
+
def self.schema_info
|
15
|
+
ROM::Solr::SchemaInfoRepo.new(container)
|
16
|
+
end
|
26
17
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
18
|
+
def self.container(uri: DEFAULT_URI)
|
19
|
+
ROM.container(:solr, uri: uri) do |config|
|
20
|
+
config.auto_registration(
|
21
|
+
File.expand_path('../rom/solr/', __FILE__),
|
22
|
+
namespace: 'ROM::Solr'
|
23
|
+
)
|
24
|
+
|
25
|
+
yield config if block_given?
|
26
|
+
end
|
27
|
+
end
|
33
28
|
|
34
|
-
|
35
|
-
|
36
|
-
ENV.fetch('SOLR_URL', 'http://localhost:8983/solr').sub(/\/\z/, '')
|
29
|
+
module Types
|
30
|
+
include Dry.Types()
|
37
31
|
end
|
38
32
|
|
39
33
|
end
|
data/lib/solrbee/version.rb
CHANGED
data/solrbee.gemspec
CHANGED
@@ -22,7 +22,9 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
23
|
spec.require_paths = ["lib"]
|
24
24
|
|
25
|
-
spec.add_dependency "
|
25
|
+
spec.add_dependency "rom"
|
26
|
+
spec.add_dependency "rom-http"
|
27
|
+
spec.add_dependency "dry-types"
|
26
28
|
|
27
29
|
spec.add_development_dependency "bundler"
|
28
30
|
spec.add_development_dependency "rake"
|
data/test.sh
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
docker run --rm -d -p 8983:8983 --name solrbee-test solr:8 solr-precreate solrbee
|
4
|
+
|
5
|
+
while ! curl -fs http://localhost:8983/solr/solrbee/admin/ping 2>/dev/null ;
|
6
|
+
do sleep 1
|
7
|
+
done
|
8
|
+
|
9
|
+
SOLR_URL=http://localhost:8983/solr/solrbee bundle exec rake
|
10
|
+
code=$?
|
11
|
+
|
12
|
+
docker stop solrbee-test
|
13
|
+
|
14
|
+
exit $code
|
metadata
CHANGED
@@ -1,17 +1,45 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solrbee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.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:
|
11
|
+
date: 2021-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rom
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rom-http
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dry-types
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
16
44
|
requirements:
|
17
45
|
- - ">="
|
@@ -96,15 +124,36 @@ files:
|
|
96
124
|
- Rakefile
|
97
125
|
- bin/console
|
98
126
|
- bin/setup
|
127
|
+
- config/api.yml
|
128
|
+
- lib/rom/solr.rb
|
129
|
+
- lib/rom/solr/array.rb
|
130
|
+
- lib/rom/solr/commands.rb
|
131
|
+
- lib/rom/solr/commands/create_documents.rb
|
132
|
+
- lib/rom/solr/commands/delete_documents.rb
|
133
|
+
- lib/rom/solr/commands/delete_documents_by_query.rb
|
134
|
+
- lib/rom/solr/commands/update_documents.rb
|
135
|
+
- lib/rom/solr/dataset.rb
|
136
|
+
- lib/rom/solr/document_repo.rb
|
137
|
+
- lib/rom/solr/documents_dataset.rb
|
138
|
+
- lib/rom/solr/documents_paginator.rb
|
139
|
+
- lib/rom/solr/gateway.rb
|
140
|
+
- lib/rom/solr/query.rb
|
141
|
+
- lib/rom/solr/query_builder.rb
|
142
|
+
- lib/rom/solr/query_templates.rb
|
143
|
+
- lib/rom/solr/relation.rb
|
144
|
+
- lib/rom/solr/relations/documents_relation.rb
|
145
|
+
- lib/rom/solr/relations/schema_info_relation.rb
|
146
|
+
- lib/rom/solr/repository.rb
|
147
|
+
- lib/rom/solr/request_handler.rb
|
148
|
+
- lib/rom/solr/response_handler.rb
|
149
|
+
- lib/rom/solr/schema.rb
|
150
|
+
- lib/rom/solr/schema_info_dataset.rb
|
151
|
+
- lib/rom/solr/schema_info_repo.rb
|
152
|
+
- lib/rom/solr/utils.rb
|
99
153
|
- lib/solrbee.rb
|
100
|
-
- lib/solrbee/api_methods.rb
|
101
|
-
- lib/solrbee/client.rb
|
102
|
-
- lib/solrbee/cursor.rb
|
103
|
-
- lib/solrbee/query.rb
|
104
|
-
- lib/solrbee/request.rb
|
105
|
-
- lib/solrbee/response.rb
|
106
154
|
- lib/solrbee/version.rb
|
107
155
|
- solrbee.gemspec
|
156
|
+
- test.sh
|
108
157
|
homepage: https://github.com/dchandekstark/solrbee
|
109
158
|
licenses:
|
110
159
|
- MIT
|
data/lib/solrbee/api_methods.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
module Solrbee
|
2
|
-
module ApiMethods
|
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
|
-
|
14
|
-
def schema_name
|
15
|
-
response = Request.execute(self, '/schema/name')
|
16
|
-
response.name
|
17
|
-
end
|
18
|
-
|
19
|
-
def schema_version
|
20
|
-
response = Request.execute(self, '/schema/version')
|
21
|
-
response.version
|
22
|
-
end
|
23
|
-
|
24
|
-
def fields(**params)
|
25
|
-
response = Request.execute(self, '/schema/fields', params: params)
|
26
|
-
response.fields
|
27
|
-
end
|
28
|
-
|
29
|
-
def field(field_name, **params)
|
30
|
-
response = Request.execute(self, '/schema/fields/%s' % field_name, params: params)
|
31
|
-
response.field
|
32
|
-
end
|
33
|
-
|
34
|
-
def unique_key
|
35
|
-
@unique_key ||= Request.execute(self, '/schema/uniquekey').uniqueKey
|
36
|
-
end
|
37
|
-
|
38
|
-
def field_types(**params)
|
39
|
-
response = Request.execute(self, '/schema/fieldtypes', params: params)
|
40
|
-
response.fieldTypes
|
41
|
-
end
|
42
|
-
|
43
|
-
def field_type(field_name, **params)
|
44
|
-
response = Request.execute(self, '/schema/fieldtypes/%s' % field_name, params: params)
|
45
|
-
response.fieldType
|
46
|
-
end
|
47
|
-
|
48
|
-
def field_names
|
49
|
-
fields.map(&:name)
|
50
|
-
end
|
51
|
-
|
52
|
-
def field_type_names
|
53
|
-
field_types.map(&:name)
|
54
|
-
end
|
55
|
-
|
56
|
-
def modify_schema(commands)
|
57
|
-
Request.execute(self, '/schema', data: commands)
|
58
|
-
end
|
59
|
-
|
60
|
-
def add_field(field)
|
61
|
-
modify_schema("add-field"=>field)
|
62
|
-
end
|
63
|
-
|
64
|
-
def delete_field(field_name)
|
65
|
-
modify_schema("delete-field"=>{"name"=>field_name})
|
66
|
-
end
|
67
|
-
|
68
|
-
def replace_field(field)
|
69
|
-
modify_schema("replace-field"=>field)
|
70
|
-
end
|
71
|
-
|
72
|
-
# "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
|
77
|
-
end
|
78
|
-
|
79
|
-
def index(*docs, **params)
|
80
|
-
Request.execute(self, '/update/json/docs', data: docs, params: params)
|
81
|
-
end
|
82
|
-
alias_method :add, :index
|
83
|
-
alias_method :update, :index
|
84
|
-
|
85
|
-
def delete(*ids)
|
86
|
-
Request.execute(self, '/update', data: { delete: ids })
|
87
|
-
end
|
88
|
-
|
89
|
-
def query(params)
|
90
|
-
Request.execute(self, '/query', data: Query.new(params))
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
94
|
-
end
|
data/lib/solrbee/client.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require "net/http"
|
2
|
-
require "uri"
|
3
|
-
require "json"
|
4
|
-
|
5
|
-
require "solrbee/api_methods"
|
6
|
-
|
7
|
-
module Solrbee
|
8
|
-
class Client
|
9
|
-
include ApiMethods
|
10
|
-
|
11
|
-
attr_reader :collection, :uri
|
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
|
18
|
-
end
|
19
|
-
|
20
|
-
def connection
|
21
|
-
Net::HTTP.new(uri.host, uri.port).tap do |http|
|
22
|
-
http.use_ssl = true if uri.scheme == 'https'
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def cursor
|
27
|
-
Cursor.new(self)
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
data/lib/solrbee/cursor.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
module Solrbee
|
2
|
-
#
|
3
|
-
# Summary
|
4
|
-
#
|
5
|
-
# > client = Solrbee::Client.new('mycollection'))
|
6
|
-
# > cursor = Solrbee::Cursor.new(client)
|
7
|
-
# > query = { query: 'foo:bar', sort: 'title ASC', limit: 10 }
|
8
|
-
# > results = cursor.execute(query)
|
9
|
-
# > results.each do |doc|
|
10
|
-
# ...
|
11
|
-
# > end
|
12
|
-
#
|
13
|
-
class Cursor
|
14
|
-
|
15
|
-
attr_reader :client
|
16
|
-
|
17
|
-
def initialize(client)
|
18
|
-
@client = client
|
19
|
-
end
|
20
|
-
|
21
|
-
# @return [Enumerator] an enumerator of query results
|
22
|
-
def execute(query)
|
23
|
-
Enumerator.new do |yielder|
|
24
|
-
q = Query.cursor(query, client.unique_key)
|
25
|
-
|
26
|
-
while true
|
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
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|