active-es 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a948a48926a07e5143226cb67f08e420dbf8d822b13db1ee0c519eb31c12d18e
4
+ data.tar.gz: ced3c9bdf36ddfd6e75dbd97f2ce6b49824722bc98148dd453193357cecc981d
5
+ SHA512:
6
+ metadata.gz: 4fd5087146de2c8170f0b8eeb74f08fdd54624c0aa2950cfe99492a1e8ed9d9ffd531543baf8fa84734747dd6d4fd4063b0554339eb096838a968308cecf8af2
7
+ data.tar.gz: 152ab98507a3aa691b97b5bd0af55f1e2b8503dcd8f11de0a8f4a96d033622fa8861d2d8198185fd7b458462b6b4f5a2bc6bd9d52cc070a7a2443f0a93fd39b8
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.0
7
+ before_install: gem install bundler -v 1.17.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at info@soartec-lab.work. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in active_es.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,186 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ active-es (0.1.0)
5
+ elasticsearch (~> 6.0)
6
+ rails (>= 4.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (5.2.2)
12
+ actionpack (= 5.2.2)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (>= 0.6.1)
15
+ actionmailer (5.2.2)
16
+ actionpack (= 5.2.2)
17
+ actionview (= 5.2.2)
18
+ activejob (= 5.2.2)
19
+ mail (~> 2.5, >= 2.5.4)
20
+ rails-dom-testing (~> 2.0)
21
+ actionpack (5.2.2)
22
+ actionview (= 5.2.2)
23
+ activesupport (= 5.2.2)
24
+ rack (~> 2.0)
25
+ rack-test (>= 0.6.3)
26
+ rails-dom-testing (~> 2.0)
27
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
28
+ actionview (5.2.2)
29
+ activesupport (= 5.2.2)
30
+ builder (~> 3.1)
31
+ erubi (~> 1.4)
32
+ rails-dom-testing (~> 2.0)
33
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
34
+ activejob (5.2.2)
35
+ activesupport (= 5.2.2)
36
+ globalid (>= 0.3.6)
37
+ activemodel (5.2.2)
38
+ activesupport (= 5.2.2)
39
+ activerecord (5.2.2)
40
+ activemodel (= 5.2.2)
41
+ activesupport (= 5.2.2)
42
+ arel (>= 9.0)
43
+ activestorage (5.2.2)
44
+ actionpack (= 5.2.2)
45
+ activerecord (= 5.2.2)
46
+ marcel (~> 0.3.1)
47
+ activesupport (5.2.2)
48
+ concurrent-ruby (~> 1.0, >= 1.0.2)
49
+ i18n (>= 0.7, < 2)
50
+ minitest (~> 5.1)
51
+ tzinfo (~> 1.1)
52
+ arel (9.0.0)
53
+ builder (3.2.3)
54
+ byebug (10.0.2)
55
+ coderay (1.1.2)
56
+ concurrent-ruby (1.1.4)
57
+ crass (1.0.4)
58
+ diff-lcs (1.3)
59
+ elasticsearch (6.1.0)
60
+ elasticsearch-api (= 6.1.0)
61
+ elasticsearch-transport (= 6.1.0)
62
+ elasticsearch-api (6.1.0)
63
+ multi_json
64
+ elasticsearch-transport (6.1.0)
65
+ faraday
66
+ multi_json
67
+ erubi (1.8.0)
68
+ faraday (0.15.4)
69
+ multipart-post (>= 1.2, < 3)
70
+ ffi (1.9.25)
71
+ globalid (0.4.2)
72
+ activesupport (>= 4.2.0)
73
+ i18n (1.5.2)
74
+ concurrent-ruby (~> 1.0)
75
+ libv8 (6.7.288.46.1)
76
+ listen (3.1.5)
77
+ rb-fsevent (~> 0.9, >= 0.9.4)
78
+ rb-inotify (~> 0.9, >= 0.9.7)
79
+ ruby_dep (~> 1.2)
80
+ loofah (2.2.3)
81
+ crass (~> 1.0.2)
82
+ nokogiri (>= 1.5.9)
83
+ mail (2.7.1)
84
+ mini_mime (>= 0.1.1)
85
+ marcel (0.3.3)
86
+ mimemagic (~> 0.3.2)
87
+ method_source (0.9.2)
88
+ mimemagic (0.3.3)
89
+ mini_mime (1.0.1)
90
+ mini_portile2 (2.4.0)
91
+ mini_racer (0.2.4)
92
+ libv8 (>= 6.3)
93
+ minitest (5.11.3)
94
+ multi_json (1.13.1)
95
+ multipart-post (2.0.0)
96
+ nio4r (2.3.1)
97
+ nokogiri (1.10.1)
98
+ mini_portile2 (~> 2.4.0)
99
+ pry (0.12.2)
100
+ coderay (~> 1.1.0)
101
+ method_source (~> 0.9.0)
102
+ pry-byebug (3.6.0)
103
+ byebug (~> 10.0)
104
+ pry (~> 0.10)
105
+ pry-rails (0.3.9)
106
+ pry (>= 0.10.4)
107
+ puma (3.12.0)
108
+ rack (2.0.6)
109
+ rack-test (1.1.0)
110
+ rack (>= 1.0, < 3)
111
+ rails (5.2.2)
112
+ actioncable (= 5.2.2)
113
+ actionmailer (= 5.2.2)
114
+ actionpack (= 5.2.2)
115
+ actionview (= 5.2.2)
116
+ activejob (= 5.2.2)
117
+ activemodel (= 5.2.2)
118
+ activerecord (= 5.2.2)
119
+ activestorage (= 5.2.2)
120
+ activesupport (= 5.2.2)
121
+ bundler (>= 1.3.0)
122
+ railties (= 5.2.2)
123
+ sprockets-rails (>= 2.0.0)
124
+ rails-dom-testing (2.0.3)
125
+ activesupport (>= 4.2.0)
126
+ nokogiri (>= 1.6)
127
+ rails-html-sanitizer (1.0.4)
128
+ loofah (~> 2.2, >= 2.2.2)
129
+ railties (5.2.2)
130
+ actionpack (= 5.2.2)
131
+ activesupport (= 5.2.2)
132
+ method_source
133
+ rake (>= 0.8.7)
134
+ thor (>= 0.19.0, < 2.0)
135
+ rake (10.5.0)
136
+ rb-fsevent (0.10.3)
137
+ rb-inotify (0.10.0)
138
+ ffi (~> 1.0)
139
+ rspec (3.8.0)
140
+ rspec-core (~> 3.8.0)
141
+ rspec-expectations (~> 3.8.0)
142
+ rspec-mocks (~> 3.8.0)
143
+ rspec-core (3.8.0)
144
+ rspec-support (~> 3.8.0)
145
+ rspec-expectations (3.8.2)
146
+ diff-lcs (>= 1.2.0, < 2.0)
147
+ rspec-support (~> 3.8.0)
148
+ rspec-mocks (3.8.0)
149
+ diff-lcs (>= 1.2.0, < 2.0)
150
+ rspec-support (~> 3.8.0)
151
+ rspec-support (3.8.0)
152
+ ruby_dep (1.5.0)
153
+ sprockets (3.7.2)
154
+ concurrent-ruby (~> 1.0)
155
+ rack (> 1, < 3)
156
+ sprockets-rails (3.2.1)
157
+ actionpack (>= 4.0)
158
+ activesupport (>= 4.0)
159
+ sprockets (>= 3.0.0)
160
+ sqlite3 (1.3.13)
161
+ thor (0.20.3)
162
+ thread_safe (0.3.6)
163
+ tzinfo (1.2.5)
164
+ thread_safe (~> 0.1)
165
+ websocket-driver (0.7.0)
166
+ websocket-extensions (>= 0.1.0)
167
+ websocket-extensions (0.1.3)
168
+
169
+ PLATFORMS
170
+ ruby
171
+
172
+ DEPENDENCIES
173
+ active-es!
174
+ bundler (~> 1.17)
175
+ byebug
176
+ listen (>= 3.0.5, < 3.2)
177
+ mini_racer
178
+ pry-byebug
179
+ pry-rails
180
+ puma (~> 3.11)
181
+ rake (~> 10.0)
182
+ rspec (~> 3.0)
183
+ sqlite3
184
+
185
+ BUNDLED WITH
186
+ 1.17.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 soartec-lab
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.
data/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # ActiveEs
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/active_es`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'active-es'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install active-es
22
+
23
+ ## Usage
24
+
25
+ ### STEP1
26
+ #### Setting Config
27
+ Create config/searchengine.yml
28
+
29
+ See: spec/dummy/config/searchengine.yml
30
+
31
+ ### STEP2
32
+ #### Inherit `ActiveEs::Base`
33
+
34
+ ```
35
+ class Content < ActiveEs::Base
36
+ end
37
+ ```
38
+
39
+ ### STEP3
40
+ #### Define the property of model.
41
+
42
+ format is `property :field_name, type: 'detatype', options... `
43
+ To check the specifiable detatype, execute the following command on rails console.
44
+
45
+ ```
46
+ $ bundle exec rails console
47
+ $ > ActiveEs::Schema::Definition::FieldDetaTypes
48
+ ```
49
+
50
+ FYI: spec/dummy/app/models/content.rb
51
+ ```
52
+ class Content < ActiveEs::Base
53
+ property :title, type: 'text', analyzer: 'kuromoji'
54
+ property :description, type: 'text', analyzer: "kuromoji"
55
+ property :number, type: 'integer'
56
+ property :rank, type: 'integer'
57
+ end
58
+ ```
59
+
60
+ ## dummy app
61
+
62
+ $ bundle exec rails runner spec/dummy/db/seeds.rb
63
+ $ bundle exec rails console
64
+ $ => Content.all
65
+ $ => [#<Content:0x00007fffc5e958a0 @description="description2", @id="IhrI1mgBhOPWXkxafVfv", @number=2, @rank=2, @score=1.0, @title="title2">,
66
+ #<Content:0x00007fffc5e94f90 @description="descripnumion10", @id="JBrI1mgBhOPWXkxaflfy", @number=10, @rank=10, @score=1.0, @title="title10">,
67
+ #<Content:0x00007fffc5eab948 @description="description1", @id="IRrI1mgBhOPWXkxafVdk", @number=1, @rank=1, @score=1.0, @title="title1">,
68
+ #<Content:0x00007fffc5eab3f8 @description="descripnumion20", @id="JRrI1mgBhOPWXkxaf1d1", @number=20, @rank=20, @score=1.0, @title="title20">,
69
+ #<Content:0x00007fffc5eaa368 @description="description0", @id="IBrI1mgBhOPWXkxafFfP", @number=0, @rank=0, @score=1.0, @title="title0">,
70
+ #<Content:0x00007fffc5ebb618 @description="descripnumion0", @id="IxrI1mgBhOPWXkxafld1", @number=0, @rank=0, @score=1.0, @title="title0">]
71
+
72
+ ## Development
73
+
74
+ 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.
75
+
76
+ 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).
77
+
78
+ # FYI
79
+ https://github.com/elastic/elasticsearch-ruby
80
+
81
+ ## Contributing
82
+
83
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/active_es. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
84
+
85
+ ## License
86
+
87
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
88
+
89
+ ## Code of Conduct
90
+
91
+ Everyone interacting in the ActiveEs project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/active_es/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -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
data/active-es.gemspec ADDED
@@ -0,0 +1,49 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "active_es/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "active-es"
8
+ spec.version = ActiveEs::VERSION
9
+ spec.authors = ["soartec-lab"]
10
+ spec.email = ["info@soartec-lab.work"]
11
+
12
+ spec.summary = %q{gem for abstract use of search engine.}
13
+ spec.description = %q{I will write this section when I finish creating this gem.}
14
+ spec.homepage = "https://github.com/soartec-lab/active-es"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = spec.homepage
22
+ spec.metadata["changelog_uri"] = spec.homepage
23
+ else
24
+ raise "RubyGems 2.0 or newer is required to protect against " \
25
+ "public gem pushes."
26
+ end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_dependency "rails", ">= 4.0"
38
+ spec.add_dependency 'elasticsearch', '~> 6.0'
39
+ spec.add_development_dependency "bundler", "~> 1.17"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "rspec", "~> 3.0"
42
+ spec.add_development_dependency 'mini_racer'
43
+ spec.add_development_dependency 'puma', '~> 3.11'
44
+ spec.add_development_dependency 'listen', '>= 3.0.5', '< 3.2'
45
+ spec.add_development_dependency 'sqlite3'
46
+ spec.add_development_dependency 'byebug'
47
+ spec.add_development_dependency 'pry-byebug'
48
+ spec.add_development_dependency 'pry-rails'
49
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "active_es"
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__)
data/bin/setup ADDED
@@ -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
data/lib/active_es.rb ADDED
@@ -0,0 +1,13 @@
1
+ require "active_es/version"
2
+
3
+ module ActiveEs
4
+ extend ActiveSupport::Autoload
5
+
6
+ autoload :Base
7
+ autoload :Client
8
+ autoload :Configurations
9
+ autoload :Persistence
10
+ autoload :Quering
11
+ autoload :Schema
12
+ autoload :AttributeMethods
13
+ end
@@ -0,0 +1,10 @@
1
+ module ActiveEs
2
+ # = Active Record Attribute Methods
3
+ module AttributeMethods
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ attr_accessor :id, :score
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module ActiveEs
2
+ class Base
3
+ extend Schema
4
+ extend Quering
5
+ extend Persistence
6
+ include Client
7
+ include AttributeMethods
8
+ include ActiveModel::Model
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ require 'elasticsearch'
2
+
3
+ module ActiveEs
4
+ module Client
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ cattr_accessor :client
9
+
10
+ def self.connect
11
+ configrations = ActiveEs::Configurations.new
12
+ @@client = Elasticsearch::Client.new url: configrations.connection_url
13
+ end
14
+ self.connect
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ module ActiveEs
2
+ class Configurations
3
+ attr_reader :connection_url, :index
4
+
5
+ def initialize
6
+ load_confing = YAML.load_file(Rails.root.join('config', 'searchengine.yml'))
7
+ config = load_confing[Rails.env]
8
+ @connection_url = "#{config["host"]}:#{config["port"]}"
9
+ @index = config["index"]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ module ActiveEs
2
+ module Persistence
3
+ # using
4
+ # ActiveEs::Base.create!(title: 'title1', description: 'description1')
5
+ # => true
6
+ #
7
+ # ActiveEs::Base.create!(title: 'title1')
8
+ # => true
9
+ def create!(attributes = nil)
10
+ result = client.create index: index, type: type, body: attributes
11
+ result["result"] == "created" ? true : raise
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,184 @@
1
+ module ActiveEs
2
+ module Quering
3
+ # using
4
+ # ActiveEs::Base.find('W_KDRmgBeTay2K79iAf7')
5
+ # => #<Content:0x00007fffc4637fb0 @description="sample description 1", @id="W_KDRmgBeTay2K79iAf7", @title="sample title 1">
6
+ def find(id)
7
+ result = client.get index: index, type: type, id: id
8
+
9
+ new(result["_source"].merge({ id: result["_id"] }))
10
+ end
11
+
12
+ def count
13
+ client.count(index: index, type: type)["count"]
14
+ end
15
+
16
+ def all
17
+ body = { query: { match_all: {} } }
18
+ result = client.search index: index, type: type, body: body
19
+
20
+ result_instance(result)
21
+ end
22
+
23
+ # using
24
+ # It retrieves data that matches one of the attributes specified by the argument.
25
+ # The value of Hash specified by attributes is an empty string delimiter and can be specified more than once.
26
+ # In that case, we will retrieve data whose value matches one of the specified keys.
27
+ # Unlike the term method, Analyze uses it for the field that Analyze needs to do.
28
+ #
29
+ # ActiveEs::Base.match(title: "sample")
30
+ # => [
31
+ # #<Content:0x00007fffc4637fb0 @description="sample description 1", @id="W_KDRmgBeTay2K79iAf7", @score=0.2876821, @title="sample title 1">,
32
+ # #<Content:0x00007fffc3f0c7b8 @description="sample description 2", @id="XPKDRmgBeTay2K79ywfz", @score=0.2876821, @title="sample title 2">
33
+ # ]
34
+ # ActiveEs::Base.match(title: '1 0')
35
+ # => [#<Content:0x00007fffdea9fea8 @description="sample description 1", @id="W_KDRmgBeTay2K79iAf7", @score=0.2876821, @title="sample title 1">]
36
+ #
37
+ # ActiveEs::Base.match(title: 'invalid_title')
38
+ # => []
39
+ def match(attributes = nil)
40
+ body = { query: { match: attributes } }
41
+ result = client.search index: index, type: type, body: body
42
+
43
+ result_instance(result)
44
+ end
45
+
46
+
47
+ # using
48
+ # In the argument, pass field to key and Hash with numerical value to value.
49
+ # Unlike the match method, since Analyze is not performed,
50
+ # high-speed searching is possible for fields where Analyze is unnecessary.
51
+ #
52
+ # ActiveEs::Base.term(number: 3)
53
+ # => [#<Content:0x00007fffe60264b0 @description="sample description 1", @id="Hhp01mgBhOPWXkxaeleN", @number=3, @score=1.0, @title="sample title 1">]
54
+ def term(attributes = nil)
55
+ body = { query: { term: attributes } }
56
+ result = client.search index: index, type: type, body: body
57
+
58
+ result_instance(result)
59
+ end
60
+
61
+ # using
62
+ # We perform a search using a match query for multiple fields.
63
+ # The default operation is "and", but an or search is performed by specifying "or" as the key 'operation' of the argument.
64
+ # Unlike the terms method, Analyze uses it for the field that Analyze needs to do.
65
+ #
66
+ # ActiveEs::Base.multi_match(field: ['title', 'description'], match: 'sample 1')
67
+ # => [#<Content:0x00007fffbc2746b0 @description="sample description 1", @id="W_KDRmgBeTay2K79iAf7", @score=0.5753642, @title="sample title 1">]
68
+ #
69
+ # ActiveEs::Base.multi_match(fields: ['title', 'description'], match: ['sample', '1'])
70
+ # => [#<Content:0x00007fffbc2746b0 @description="sample description 1", @id="W_KDRmgBeTay2K79iAf7", @score=0.5753642, @title="sample title 1">]
71
+ #
72
+ # ActiveEs::Base.multi_match(fields: ['title', 'description'], match: ['sample', '1'], operator: 'or')
73
+ # => [
74
+ # #<Content:0x00007ffff712d280 @description="sample description 1", @id="W_KDRmgBeTay2K79iAf7", @score=0.5753642, @title="sample title 1">,
75
+ # #<Content:0x00007ffff712c6a0 @description="sample description 2", @id="XPKDRmgBeTay2K79ywfz", @score=0.2876821, @title="sample title 2">
76
+ # ]
77
+ #
78
+ # ActiveEs::Base.multi_match(fields: '', match: [])
79
+ # => []
80
+ def multi_match(fields:, match:, operator: 'and')
81
+ raise ArgumentError, "operator accepts only 'and','or'" unless operator =~ /and|or/
82
+
83
+ keyword = Array(match).join(' ')
84
+ body = { query: { multi_match: { fields: fields, query: keyword, operator: operator} } }
85
+ result = client.search index: index, type: type, body: body
86
+
87
+ result_instance(result)
88
+ end
89
+
90
+ # using
91
+ # We perform a search using a match query for multiple fields.
92
+ # The default operation is "and", but an or search is performed by specifying "or" as the key 'operation' of the argument.
93
+ # Unlike the multi_match method, since Analyze is not performed,
94
+ # high-speed searching is possible for fields where Analyze is unnecessary.
95
+ #
96
+ # ActiveEs::Base.terms(number: 1)
97
+ # => [#<Content:0x00007fffbc7dfeb0 @description="description1", @id="IRrI1mgBhOPWXkxafVdk", @number=1, @rank=1, @score=1.0, @title="title1">]
98
+ #
99
+ # ActiveEs::Base.terms(number: [1, 2])
100
+ # => [
101
+ # #<Content:0x00007fffbbe29038 @description="description2", @id="IhrI1mgBhOPWXkxafVfv", @number=2, @rank=2, @score=1.0, @title="title2">,
102
+ # #<Content:0x00007fffbbe33100 @description="description1", @id="IRrI1mgBhOPWXkxafVdk", @number=1, @rank=1, @score=1.0, @title="title1">
103
+ # ]
104
+ def terms(attributes = nil)
105
+ field = attributes.keys.first
106
+ query = { field => attributes.values.flatten }
107
+
108
+ body = { query: { terms: query } }
109
+ result = client.search index: index, type: type, body: body
110
+
111
+ result_instance(result)
112
+ end
113
+
114
+ # using
115
+ # Get data that matches all the attributes specified by arguments.
116
+ #
117
+ # ActiveEs::Base.must(title: 'sample', description: '1')
118
+ # => [#<Content:0x00007fffd5f32230 @description="sample description 1", @id="W_KDRmgBeTay2K79iAf7", @score=0.5753642, @title="sample title 1">]
119
+ #
120
+ # ActiveEs::Base.must(title: '')
121
+ # => []
122
+ def must(attributes = {})
123
+ query = attributes.map { |attr| { match: Hash[*attr] } }
124
+ body = { query: { bool: { must: query } } }
125
+ result = client.search index: index, type: type, body: body
126
+
127
+ result_instance(result)
128
+ end
129
+
130
+ # using
131
+ # It retrieves data that matches one of the attributes specified by the argument.
132
+ #
133
+ # ActiveEs::Base.should(title: '1')
134
+ # => [#<Content:0x00007fffe7e42ea8 @description="sample description 1", @id="W_KDRmgBeTay2K79iAf7", @score=0.2876821, @title="sample title 1">]
135
+ #
136
+ # ActiveEs::Base.should(title: '2', description: '1')
137
+ # => [
138
+ # #<Content:0x00007fffe7fe0198@description="sample description 2", @id="XPKDRmgBeTay2K79ywfz", @score=0.2876821, @title="sample title 2">,
139
+ # #<Content:0x00007fffe7ff7e88@description="sample description 1", @id="W_KDRmgBeTay2K79iAf7", @score=0.2876821, @title="sample title 1">
140
+ # ]
141
+ #
142
+ # ActiveEs::Base.should(title: '')
143
+ # => []
144
+ def should(attributes = {})
145
+ query = attributes.map { |attr| { match: Hash[*attr] } }
146
+ body = { query: { bool: { should: query } } }
147
+ result = client.search index: index, type: type, body: body
148
+
149
+ result_instance(result)
150
+ end
151
+
152
+ # using
153
+ # Acquires all data that does not match Hash specified in argument's.
154
+ # Hash values ​​of attributes can be separated by null character and multiple can be specified.
155
+ # In that case, we will retrieve all data that is not included in any of the specified values.
156
+ #
157
+ # ActiveEs::Base.must_not(title: '1')
158
+ # => [#<Content:0x00007ffff31bc3f8 @description="sample description 2", @id="XPKDRmgBeTay2K79ywfz", @score=1.0, @title="sample title 2">]
159
+ #
160
+ # ActiveEs::Base.must_not(title: '')
161
+ # => [
162
+ # #<Content:0x00007ffff3b3bd20 @description="sample description 2", @id="XPKDRmgBeTay2K79ywfz", @score=1.0, @title="sample title 2">,
163
+ # #<Content:0x00007ffff3b3b938 @description="sample description 1", @id="W_KDRmgBeTay2K79iAf7", @score=1.0, @title="sample title 1">
164
+ # ]
165
+ #
166
+ # ActiveEs::Base.must_not(title: '1 2')
167
+ # => []
168
+ def must_not(attributes = {})
169
+ query = attributes.map { |attr| { match: Hash[*attr] } }
170
+ body = { query: { bool: { must_not: query } } }
171
+ result = client.search index: index, type: type, body: body
172
+
173
+ result_instance(result)
174
+ end
175
+
176
+ private
177
+
178
+ def result_instance(result)
179
+ result.dig("hits", "hits").map do |hit|
180
+ new(hit["_source"].merge({ id: hit["_id"], score: hit["_score"] }))
181
+ end
182
+ end
183
+ end
184
+ end
@@ -0,0 +1,11 @@
1
+ require "active_es/schema/definition"
2
+ require "active_es/schema/describe"
3
+ require "active_es/schema/control"
4
+
5
+ module ActiveEs
6
+ module Schema
7
+ include Definition
8
+ include Describe
9
+ include Control
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module ActiveEs
2
+ module Schema
3
+ module Control
4
+ extend ActiveSupport::Concern
5
+
6
+ def healthy?
7
+ status = client.cluster.health["status"]
8
+ status == "green"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,41 @@
1
+ module ActiveEs
2
+ module Schema
3
+ module Definition
4
+ extend ActiveSupport::Concern
5
+
6
+ mattr_accessor :properties, default: {}
7
+
8
+ FieldDetaTypes = %w(
9
+ text keyword
10
+ long integer short byte
11
+ double float half_float scaled_float
12
+ date
13
+ boolean
14
+ binary
15
+ integer_range float_range long_range double_range date_range
16
+ )
17
+
18
+ def property(field, **options)
19
+ if options.values.all? { |key| FieldDetaTypes.exclude?(key) }
20
+ raise ArgumentError('invalid field deta types')
21
+ end
22
+
23
+ properties[field] = options
24
+ attr_accessor field
25
+ end
26
+
27
+ def create_schema
28
+ client.indices.create index: index, body: mappings
29
+ end
30
+
31
+ def delete_schema
32
+ client.indices.delete index: index
33
+ end
34
+
35
+ def reset_schema
36
+ delete_schema
37
+ create_schema
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,19 @@
1
+ module ActiveEs
2
+ module Schema
3
+ module Describe
4
+ extend ActiveSupport::Concern
5
+
6
+ def index
7
+ ActiveEs::Configurations.new.index
8
+ end
9
+
10
+ def type
11
+ name.tableize
12
+ end
13
+
14
+ def mappings
15
+ { mappings: { "#{type}" => { properties: properties } } }
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveEs
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,244 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active-es
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - soartec-lab
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-02-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: elasticsearch
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '6.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '6.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.17'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.17'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mini_racer
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: puma
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.11'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.11'
111
+ - !ruby/object:Gem::Dependency
112
+ name: listen
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 3.0.5
118
+ - - "<"
119
+ - !ruby/object:Gem::Version
120
+ version: '3.2'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: 3.0.5
128
+ - - "<"
129
+ - !ruby/object:Gem::Version
130
+ version: '3.2'
131
+ - !ruby/object:Gem::Dependency
132
+ name: sqlite3
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ - !ruby/object:Gem::Dependency
146
+ name: byebug
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ - !ruby/object:Gem::Dependency
160
+ name: pry-byebug
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ - !ruby/object:Gem::Dependency
174
+ name: pry-rails
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ type: :development
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ description: I will write this section when I finish creating this gem.
188
+ email:
189
+ - info@soartec-lab.work
190
+ executables: []
191
+ extensions: []
192
+ extra_rdoc_files: []
193
+ files:
194
+ - ".gitignore"
195
+ - ".rspec"
196
+ - ".travis.yml"
197
+ - CODE_OF_CONDUCT.md
198
+ - Gemfile
199
+ - Gemfile.lock
200
+ - LICENSE.txt
201
+ - README.md
202
+ - Rakefile
203
+ - active-es.gemspec
204
+ - bin/console
205
+ - bin/setup
206
+ - lib/active_es.rb
207
+ - lib/active_es/attribute_methods.rb
208
+ - lib/active_es/base.rb
209
+ - lib/active_es/client.rb
210
+ - lib/active_es/configurations.rb
211
+ - lib/active_es/persistence.rb
212
+ - lib/active_es/quering.rb
213
+ - lib/active_es/schema.rb
214
+ - lib/active_es/schema/control.rb
215
+ - lib/active_es/schema/definition.rb
216
+ - lib/active_es/schema/describe.rb
217
+ - lib/active_es/version.rb
218
+ homepage: https://github.com/soartec-lab/active-es
219
+ licenses:
220
+ - MIT
221
+ metadata:
222
+ homepage_uri: https://github.com/soartec-lab/active-es
223
+ source_code_uri: https://github.com/soartec-lab/active-es
224
+ changelog_uri: https://github.com/soartec-lab/active-es
225
+ post_install_message:
226
+ rdoc_options: []
227
+ require_paths:
228
+ - lib
229
+ required_ruby_version: !ruby/object:Gem::Requirement
230
+ requirements:
231
+ - - ">="
232
+ - !ruby/object:Gem::Version
233
+ version: '0'
234
+ required_rubygems_version: !ruby/object:Gem::Requirement
235
+ requirements:
236
+ - - ">="
237
+ - !ruby/object:Gem::Version
238
+ version: '0'
239
+ requirements: []
240
+ rubygems_version: 3.0.1
241
+ signing_key:
242
+ specification_version: 4
243
+ summary: gem for abstract use of search engine.
244
+ test_files: []