solrbee 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ca8f6d8f901268390057453075d0c39306b2362cb1216ec4dbcdb168b6d5bb18
4
+ data.tar.gz: b17d0b604e4276a47c2e54d17fc92f9b9cc173fb1c2b283cc4d15f6f506c99d8
5
+ SHA512:
6
+ metadata.gz: 3967982e1454c5659be6716eaf2e3a1a215046b6c3bfbe383c09810b519391017ddb4febedc861235d97b44253fd4950ad75f88dbcddc5378e33d5e37d822c59
7
+ data.tar.gz: 9cd90db400ec1a2ec23daa227e6e22afb23da39328fb66384bd2cf18c52a01ee4c5db1f2620079a4a63d19096edc706de5320be3e93e67f8da5c2fb600948c61
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /Gemfile.lock
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 David Chandek-Stark
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,7 @@
1
+ SHELL = /bin/bash
2
+
3
+ .PHONY : test
4
+ test:
5
+ docker run --rm -d --name solrbee-test solr:8 solr-precreate solrbee
6
+ bundle exec rake
7
+ docker stop solrbee-test
@@ -0,0 +1,39 @@
1
+ # Solrbee
2
+
3
+ Solrbee is intended as a lightweight library for interacting with a modern Solr instance
4
+ using a managed schema. Our intestest is primarily in using Solr as data store, for example,
5
+ as an alterative to an RDBMS.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'solrbee'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install solrbee
22
+
23
+ ## Usage
24
+
25
+
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/solrbee.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "solrbee"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,65 @@
1
+ require "net/http"
2
+ require "uri"
3
+ require "json"
4
+
5
+ require "solrbee/version"
6
+ require "solrbee/base"
7
+ require "solrbee/response"
8
+ require "solrbee/collection"
9
+ require "solrbee/schema_api"
10
+
11
+ module Solrbee
12
+ class Error < StandardError; end
13
+
14
+ # Single-valued field types
15
+ STRING = "string"
16
+ LONG = "plong"
17
+ INT = "pint"
18
+ DATE = "pdate"
19
+ BOOLEAN = "boolean"
20
+
21
+ # Multi-valued field types
22
+ MSTRING = "strings"
23
+ MLONG = "plongs"
24
+ MINT = "pints"
25
+ MDATE = "pdates"
26
+ MBOOLEAN = "booleans"
27
+
28
+ def self.solr_url
29
+ ENV.fetch('SOLR_URL', 'http://localhost:8983/solr/')
30
+ end
31
+
32
+ def self.solr_uri
33
+ URI(solr_url)
34
+ end
35
+
36
+ def self.connection
37
+ Net::HTTP.new(solr_uri.host, solr_uri.port).tap do |http|
38
+ http.use_ssl = true if solr_uri.scheme == 'https'
39
+ end
40
+ end
41
+
42
+ def self.request_class(method)
43
+ Net::HTTP.const_get(method.to_s.downcase.capitalize)
44
+ end
45
+
46
+ def self.request(method, path)
47
+ u = URI.join(solr_url, path)
48
+ req = request_class(method).new(u, {'Accept'=>'application/json'})
49
+ yield req if block_given?
50
+ res = connection.request(req)
51
+ Response.handle(res)
52
+ end
53
+
54
+ def self.get(path)
55
+ request(:get, path)
56
+ end
57
+
58
+ def self.post(path, data)
59
+ request(:post, path) do |req|
60
+ req['Content-Type'] = 'application/json'
61
+ req.body = JSON.dump(data)
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,14 @@
1
+ require 'hashie'
2
+
3
+ module Solrbee
4
+ class Base < Hashie::Hash
5
+ include Hashie::Extensions::Coercion
6
+ include Hashie::Extensions::MergeInitializer
7
+ include Hashie::Extensions::MethodAccess
8
+ end
9
+
10
+ Field = Class.new(Base)
11
+ FieldType = Class.new(Base)
12
+ Header = Class.new(Base)
13
+ Schema = Class.new(Base)
14
+ end
@@ -0,0 +1,19 @@
1
+ module Solrbee
2
+ class Collection
3
+
4
+ attr_reader :name
5
+
6
+ def initialize(name)
7
+ @name = name
8
+ end
9
+
10
+ def to_s
11
+ name
12
+ end
13
+
14
+ def schema
15
+ @schema ||= SchemaApi.new(self)
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ module Solrbee
2
+ class Response < Base
3
+
4
+ coerce_key :schema, Schema
5
+ coerce_key :fields, Array[Field]
6
+ coerce_key :field, Field
7
+ coerce_key :responseHeader, Header
8
+ coerce_key :fieldTypes, Array[FieldType]
9
+ coerce_key :fieldType, FieldType
10
+
11
+ def self.handle(http_response)
12
+ http_response.value # raises Net::HTTPServerException
13
+ parsed = JSON.parse(http_response.body, symbolize_names: true, object_class: Solrbee::Base)
14
+ new(parsed)
15
+ end
16
+
17
+ def status
18
+ responseHeader.status
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,86 @@
1
+ module Solrbee
2
+ class SchemaApi
3
+
4
+ attr_reader :collection
5
+
6
+ def initialize(collection)
7
+ @collection = collection
8
+ end
9
+
10
+ def to_h
11
+ content
12
+ end
13
+
14
+ def name
15
+ response = Solrbee.get('%s/schema/name' % collection)
16
+ response.name
17
+ end
18
+
19
+ def version
20
+ response = Solrbee.get('%s/schema/version' % collection)
21
+ response.version
22
+ end
23
+
24
+ def content
25
+ response = Solrbee.get('%s/schema' % collection)
26
+ response.schema
27
+ end
28
+
29
+ def fields(show_defaults: true)
30
+ response = Solrbee.get('%s/schema/fields?showDefaults=%s' % [collection, show_defaults])
31
+ response.fields
32
+ end
33
+
34
+ def field(field_name, show_defaults: true)
35
+ response = Solrbee.get('%s/schema/fields/%s?showDefaults=%s' % [collection, field_name, show_defaults])
36
+ response.field
37
+ end
38
+
39
+ def unique_key
40
+ response = Solrbee.get('%s/schema/uniquekey' % collection)
41
+ response.uniqueKey
42
+ end
43
+
44
+ def field_types(show_defaults: true)
45
+ response = Solrbee.get('%s/schema/fieldtypes?showDefaults=%s' % [collection, show_defaults])
46
+ response.fieldTypes
47
+ end
48
+
49
+ def field_type(field_name, show_defaults: true)
50
+ response = Solrbee.get('%s/schema/fieldtypes/%s?showDefaults=%s' % [collection, field_name, show_defaults])
51
+ response.fieldType
52
+ end
53
+
54
+ def field_names
55
+ fields.map(&:name)
56
+ end
57
+
58
+ def field_type_names
59
+ field_types.map(&:name)
60
+ end
61
+
62
+ def index(*docs, commit: true)
63
+ Solrbee.post('%s/update/json/docs?commit=%s' % [collection, commit], docs)
64
+ end
65
+
66
+ def add_field(field)
67
+ data = { "add-field" => field }
68
+ Solrbee.post('%s/schema' % collection, data)
69
+ end
70
+
71
+ def delete_field(field)
72
+ data = {
73
+ "delete-field" => {
74
+ "name" => field.name
75
+ }
76
+ }
77
+ Solrbee.post('%s/schema' % collection, data)
78
+ end
79
+
80
+ def replace_field(field)
81
+ data = { "replace-field" => field }
82
+ Solrbee.post('%s/schema' % collection, data)
83
+ end
84
+
85
+ end
86
+ end
@@ -0,0 +1,3 @@
1
+ module Solrbee
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "solrbee/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "solrbee"
8
+ spec.version = Solrbee::VERSION
9
+ spec.authors = ["David Chandek-Stark"]
10
+ spec.email = ["david.chandek.stark@duke.edu"]
11
+
12
+ spec.summary = "Solr buzz"
13
+ spec.homepage = "https://github.com/dchandekstark/solrbee"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "hashie"
26
+
27
+ spec.add_development_dependency "bundler"
28
+ spec.add_development_dependency "rake"
29
+ spec.add_development_dependency "rspec"
30
+ spec.add_development_dependency "rspec-its"
31
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: solrbee
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Chandek-Stark
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-12-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hashie
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-its
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - david.chandek.stark@duke.edu
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - Makefile
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/solrbee.rb
100
+ - lib/solrbee/base.rb
101
+ - lib/solrbee/collection.rb
102
+ - lib/solrbee/response.rb
103
+ - lib/solrbee/schema_api.rb
104
+ - lib/solrbee/version.rb
105
+ - solrbee.gemspec
106
+ homepage: https://github.com/dchandekstark/solrbee
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubygems_version: 3.0.8
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Solr buzz
129
+ test_files: []