common_indexer 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 931029ffbaed76ee103cb5bc8dd88dcd88fa1556494d2d3f562c2893fae77c38
4
- data.tar.gz: 662a785dced385458c692e967d96a71c90aab3fdf9c21a09d6551dc014521f93
3
+ metadata.gz: 20b26c3cf3c10115c85b72ef1f551393f41ab80df040b74a31e4073e34b1add7
4
+ data.tar.gz: 75c0681b5b3eaf60845d102360ce51347cb56a54d8076bbdc1e1c4ee74b3b2a0
5
5
  SHA512:
6
- metadata.gz: e042d390d0c68c4d3abc7d38569434be1740a9ceed64330d30e6a019cea5aeb718ad6cef3ec2e1bcdf6278a2e612dade48684c48329ca124a81d22c5c63913d9
7
- data.tar.gz: e75f6390d3b751dd0f60e655d1218845454d3b87935c9bfc126f3db25f15b46ff9e32eb3b98417000f455aef3e9ced42fce81cfe292ee6c9063834bb338128cc
6
+ metadata.gz: bbdf9bda38b86151d951da22b9b83754e19009af9eca9d4461d60d242357006ec0b3c76423eb205ca874a5dc278fc358eeb45c9ea0ee20884ca0084cc8e38e65
7
+ data.tar.gz: 58889be56ac62972e7efbabcafe3081d8fa911cd572681a9361714208049fde514da6ef7aa9df93eaebc206cc7ec22745caffcf0e10df061161eecd941ed7099
@@ -0,0 +1,31 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ docker:
5
+ - image: circleci/ruby:2.6.5
6
+ environment:
7
+ BUNDLER_VERSION: 2.1.4
8
+ steps:
9
+ - checkout
10
+ - run:
11
+ name: Install Bundler 2.1.4
12
+ command: gem install --no-doc bundler:2.1.4
13
+ - restore_cache:
14
+ keys:
15
+ - bundle-{{ checksum "Gemfile" }}-{{ checksum "common_indexer.gemspec" }}
16
+ - bundle- # used if checksum fails
17
+ - run:
18
+ name: Install dependencies
19
+ command: |
20
+ bundle config set path vendor/bundle
21
+ bundle check || bundle install --jobs 4 --retry 3
22
+ - save_cache:
23
+ key: bundle-{{ checksum "Gemfile" }}-{{ checksum "common_indexer.gemspec" }}
24
+ paths:
25
+ - "vendor/bundle"
26
+ - run:
27
+ name: Run Rubocop
28
+ command: bundle exec rubocop
29
+ - run:
30
+ name: Run Specs
31
+ command: bundle exec rspec spec
@@ -27,8 +27,10 @@ Gem::Specification.new do |spec|
27
27
  spec.add_dependency 'typhoeus'
28
28
  spec.add_dependency 'elasticsearch'
29
29
  spec.add_development_dependency 'bixby'
30
- spec.add_development_dependency 'bundler', '~> 1.16'
30
+ spec.add_development_dependency 'bundler'
31
+ spec.add_development_dependency 'coveralls', '~> 0.8.3'
31
32
  spec.add_development_dependency 'pry-byebug'
32
33
  spec.add_development_dependency 'rake', '~> 10.0'
33
34
  spec.add_development_dependency 'rspec'
35
+ spec.add_development_dependency 'simplecov'
34
36
  end
@@ -0,0 +1,39 @@
1
+ {
2
+ "settings": {
3
+ "analysis": {
4
+ "analyzer": {
5
+ "phrase_analyzer": {
6
+ "type": "custom",
7
+ "tokenizer": "standard",
8
+ "filter": [
9
+ "lowercase"
10
+ ]
11
+ },
12
+ "keyword_analyzer": {
13
+ "type": "custom",
14
+ "tokenizer": "standard",
15
+ "filter": [
16
+ "lowercase",
17
+ "english_stop"
18
+ ]
19
+ }
20
+ },
21
+ "filter": {
22
+ "english_stop": {
23
+ "type": "stop",
24
+ "stopwords": "_english_"
25
+ }
26
+ }
27
+ }
28
+ },
29
+ "mappings": {
30
+ "properties": {
31
+ "title": {
32
+ "type": "text",
33
+ "analyzer": "phrase_analyzer",
34
+ "search_analyzer": "keyword_analyzer",
35
+ "search_quote_analyzer": "phrase_analyzer"
36
+ }
37
+ }
38
+ }
39
+ }
@@ -17,6 +17,7 @@ module CommonIndexer # :nodoc:
17
17
  setting :endpoint, 'http://localhost:9200/'
18
18
  setting :index_name, 'common'
19
19
  setting :schema, JSON.parse(File.read(File.expand_path('../../config/schema.json', __FILE__)))
20
+ setting :settings, JSON.parse(File.read(File.expand_path('../../config/settings.json', __FILE__)))
20
21
 
21
22
  class << self
22
23
  delegate :index_name, to: :config
@@ -31,19 +32,30 @@ module CommonIndexer # :nodoc:
31
32
 
32
33
  def configure_index!
33
34
  new_index = [index_name, Time.now.utc.strftime('%Y%m%d%H%M%S%3N')].join('_')
34
- client.indices.create(index: new_index)
35
- client.indices.put_mapping(index: new_index, type: '_doc', body: { _doc: config.schema })
35
+ create_index(new_index)
36
+ apply_settings(new_index)
36
37
  reindex_into(new_index) if client.indices.exists(index: index_name)
37
38
  client.indices.put_alias(index: new_index, name: index_name)
38
39
  end
39
40
 
40
41
  private
41
42
 
42
- def reindex_into(new_index)
43
- existing_index = client.indices.get(index: index_name).keys.first
44
- raise ArgumentError, "Cannot reindex #{index_name} into itself" if existing_index == new_index
45
- client.reindex(body: { source: { index: existing_index }, dest: { index: new_index } })
46
- client.indices.delete(index: existing_index)
47
- end
43
+ def create_index(new_index)
44
+ client.indices.create(index: new_index)
45
+ client.indices.put_mapping(index: new_index, type: '_doc', body: { _doc: config.schema })
46
+ end
47
+
48
+ def apply_settings(new_index)
49
+ client.indices.close(index: new_index)
50
+ client.indices.put_settings(index: new_index, body: config.settings)
51
+ client.indices.open(index: new_index)
52
+ end
53
+
54
+ def reindex_into(new_index)
55
+ existing_index = client.indices.get(index: index_name).keys.first
56
+ raise ArgumentError, "Cannot reindex #{index_name} into itself" if existing_index == new_index
57
+ client.reindex(body: { source: { index: existing_index }, dest: { index: new_index } })
58
+ client.indices.delete(index: existing_index)
59
+ end
48
60
  end
49
61
  end
@@ -4,7 +4,7 @@ require 'active_support/concern'
4
4
  module CommonIndexer # :nodoc:
5
5
  module Base
6
6
  extend ActiveSupport::Concern
7
-
7
+
8
8
  included do
9
9
  extend ActiveModel::Callbacks
10
10
  define_model_callbacks :delete_common_index, :update_common_index
@@ -21,8 +21,8 @@ module CommonIndexer # :nodoc:
21
21
  def delete_document
22
22
  _run_delete_common_index_callbacks do
23
23
  CommonIndexer.client.delete index: CommonIndexer.index_name,
24
- id: id,
25
- type: '_doc'
24
+ id: id,
25
+ type: '_doc'
26
26
  end
27
27
  rescue Elasticsearch::Transport::Transport::Error => err
28
28
  Rails.logger.warn("Common Index delete failure: #{err.message}")
@@ -31,10 +31,10 @@ module CommonIndexer # :nodoc:
31
31
  def update_common_index
32
32
  _run_update_common_index_callbacks do
33
33
  CommonIndexer.client.index index: CommonIndexer.index_name,
34
- id: id,
35
- type: '_doc',
36
- body: to_common_index
37
- end
34
+ id: id,
35
+ type: '_doc',
36
+ body: to_common_index
37
+ end
38
38
  rescue Elasticsearch::Transport::Transport::Error => err
39
39
  Rails.logger.warn("Common Indexing failure: #{err.message}")
40
40
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CommonIndexer
4
- VERSION = '0.4.1'
4
+ VERSION = '0.5.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: common_indexer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Klein
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-08-16 00:00:00.000000000 Z
12
+ date: 2020-03-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: active-fedora
@@ -111,18 +111,32 @@ dependencies:
111
111
  version: '0'
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: bundler
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: coveralls
114
128
  requirement: !ruby/object:Gem::Requirement
115
129
  requirements:
116
130
  - - "~>"
117
131
  - !ruby/object:Gem::Version
118
- version: '1.16'
132
+ version: 0.8.3
119
133
  type: :development
120
134
  prerelease: false
121
135
  version_requirements: !ruby/object:Gem::Requirement
122
136
  requirements:
123
137
  - - "~>"
124
138
  - !ruby/object:Gem::Version
125
- version: '1.16'
139
+ version: 0.8.3
126
140
  - !ruby/object:Gem::Dependency
127
141
  name: pry-byebug
128
142
  requirement: !ruby/object:Gem::Requirement
@@ -165,6 +179,20 @@ dependencies:
165
179
  - - ">="
166
180
  - !ruby/object:Gem::Version
167
181
  version: '0'
182
+ - !ruby/object:Gem::Dependency
183
+ name: simplecov
184
+ requirement: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ type: :development
190
+ prerelease: false
191
+ version_requirements: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
168
196
  description: Common Indexing mixin for NUL Digital Collections
169
197
  email:
170
198
  - mbklein@gmail.com
@@ -173,6 +201,7 @@ executables: []
173
201
  extensions: []
174
202
  extra_rdoc_files: []
175
203
  files:
204
+ - ".circleci/config.yml"
176
205
  - ".gitignore"
177
206
  - ".rspec"
178
207
  - ".rubocop.yml"
@@ -185,6 +214,7 @@ files:
185
214
  - bin/setup
186
215
  - common_indexer.gemspec
187
216
  - config/schema.json
217
+ - config/settings.json
188
218
  - lib/common_indexer.rb
189
219
  - lib/common_indexer/base.rb
190
220
  - lib/common_indexer/version.rb
@@ -207,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
237
  - !ruby/object:Gem::Version
208
238
  version: '0'
209
239
  requirements: []
210
- rubygems_version: 3.0.1
240
+ rubygems_version: 3.1.2
211
241
  signing_key:
212
242
  specification_version: 4
213
243
  summary: Common Indexing mixin for NUL Digital Collections