base_indexer 4.2.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +1 -10
- data/app/controllers/base_indexer/application_controller.rb +0 -12
- data/app/controllers/base_indexer/items_controller.rb +6 -13
- data/base_indexer.gemspec +1 -1
- data/config/initializers/base_indexer.rb +0 -1
- data/config/routes.rb +0 -2
- data/lib/base_indexer.rb +0 -2
- data/lib/base_indexer/main_indexer_engine.rb +13 -8
- data/lib/base_indexer/solr/client.rb +27 -58
- data/lib/base_indexer/solr/writer.rb +18 -15
- data/lib/base_indexer/version.rb +1 -1
- data/lib/tasks/index.rake +3 -3
- data/spec/base_indexer/main_indexer_engine_spec.rb +2 -3
- data/spec/base_indexer/solr/client_spec.rb +23 -38
- data/spec/base_indexer/solr/writer_spec.rb +8 -14
- data/spec/controllers/base_indexer/items_controller_spec.rb +1 -1
- data/spec/spec_helper.rb +51 -44
- metadata +3 -4
- data/app/controllers/base_indexer/collections_controller.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 416cd88ba0ca83c08d9783cebc9af1eb044647c6
|
4
|
+
data.tar.gz: bd8aa214f215b69bbd5f553cd2f32a72dabec313
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad1abf4ebe31cb0caf0199e88086d7da89c52ce3efce64ee9806daa652132ac52313d823facc32fb8fe5be0a59627a811781839893a097afbf27949acfd6b9f9
|
7
|
+
data.tar.gz: 2b5db11fd80aedc6b7ec2a7dc1a95e587ac5faa13183b0ec6ad27ab9247d9cd5640086010e7adb416ec61a7ecde408c1a34dd7a4a632f66770a0180bc384bfde
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -14,7 +14,7 @@ gemspec
|
|
14
14
|
# gem 'debugger'
|
15
15
|
|
16
16
|
# BEGIN ENGINE_CART BLOCK
|
17
|
-
# engine_cart: 0.
|
17
|
+
# engine_cart: 1.0.1
|
18
18
|
# engine_cart stanza: 0.10.0
|
19
19
|
# the below comes from engine_cart, a gem used to test this Rails engine gem in the context of a Rails app.
|
20
20
|
file = File.expand_path('Gemfile', ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || File.expand_path('.internal_test_app', File.dirname(__FILE__)))
|
@@ -36,14 +36,5 @@ else
|
|
36
36
|
gem 'rails', ENV['RAILS_VERSION']
|
37
37
|
end
|
38
38
|
end
|
39
|
-
|
40
|
-
case ENV['RAILS_VERSION']
|
41
|
-
when /^4.2/
|
42
|
-
gem 'responders', '~> 2.0'
|
43
|
-
gem 'sass-rails', '>= 5.0'
|
44
|
-
gem 'coffee-rails', '~> 4.1.0'
|
45
|
-
when /^4.[01]/
|
46
|
-
gem 'sass-rails', '< 5.0'
|
47
|
-
end
|
48
39
|
end
|
49
40
|
# END ENGINE_CART BLOCK
|
@@ -1,16 +1,4 @@
|
|
1
1
|
module BaseIndexer
|
2
2
|
class ApplicationController < ActionController::Base
|
3
|
-
|
4
|
-
def remove_prefix(druid)
|
5
|
-
druid.gsub('druid:', '') # lop off druid prefix if sent
|
6
|
-
end
|
7
|
-
|
8
|
-
def report_failure(method_symbol, params, e)
|
9
|
-
"#{method_symbol} #{params}\n\n#{e.inspect}\n#{e.message}\n#{e.backtrace}"
|
10
|
-
end
|
11
|
-
|
12
|
-
def report_success
|
13
|
-
'success'
|
14
|
-
end
|
15
3
|
end
|
16
4
|
end
|
@@ -1,22 +1,15 @@
|
|
1
|
-
require_dependency 'base_indexer/application_controller'
|
2
|
-
|
3
1
|
module BaseIndexer
|
4
2
|
class ItemsController < ApplicationController
|
5
3
|
def update
|
6
4
|
Rails.logger.debug "Receiving indexing #{druid}"
|
7
5
|
|
8
|
-
indexer = BaseIndexer.indexer_class.constantize.new
|
9
6
|
indexer.index druid, { subtarget_params => true }
|
10
7
|
head :ok
|
11
|
-
Rails.logger.debug "Completing indexing #{druid}"
|
12
|
-
rescue StandardError => e
|
13
|
-
Rails.logger.error report_failure request.method_symbol, params, e
|
14
|
-
raise
|
15
8
|
end
|
16
9
|
|
17
10
|
def destroy
|
18
11
|
Rails.logger.debug "Receiving deleting #{druid}"
|
19
|
-
|
12
|
+
|
20
13
|
# If no subtarget is defined, delete from everywhere
|
21
14
|
if optional_subtarget_params.nil?
|
22
15
|
indexer.delete druid
|
@@ -26,16 +19,16 @@ module BaseIndexer
|
|
26
19
|
indexer.index druid, { subtarget_params => false }
|
27
20
|
end
|
28
21
|
head :ok
|
29
|
-
Rails.logger.debug "Completing deleting #{druid}"
|
30
|
-
rescue StandardError => e
|
31
|
-
Rails.logger.error report_failure request.method_symbol, params, e
|
32
|
-
raise
|
33
22
|
end
|
34
23
|
|
35
24
|
private
|
36
25
|
|
26
|
+
def indexer
|
27
|
+
BaseIndexer.indexer_class.constantize.new
|
28
|
+
end
|
29
|
+
|
37
30
|
def druid
|
38
|
-
|
31
|
+
params.require(:druid).gsub('druid:', '') # lop off druid prefix if sent
|
39
32
|
end
|
40
33
|
|
41
34
|
def optional_subtarget_params
|
data/base_indexer.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_dependency 'rails', '~> 5'
|
23
23
|
s.add_dependency 'discovery-indexer', '>= 2', '< 4'
|
24
24
|
s.add_dependency 'retries'
|
25
|
-
s.add_dependency '
|
25
|
+
s.add_dependency 'harvestdor-indexer'
|
26
26
|
s.add_dependency 'config'
|
27
27
|
|
28
28
|
s.add_development_dependency 'sqlite3'
|
data/config/routes.rb
CHANGED
data/lib/base_indexer.rb
CHANGED
@@ -16,29 +16,34 @@ module BaseIndexer
|
|
16
16
|
# indexer = BaseIndexer::MainIndexerEngine.new
|
17
17
|
# indexer.delete "ab123cd456"
|
18
18
|
class MainIndexerEngine
|
19
|
-
include DiscoveryIndexer
|
20
|
-
|
21
19
|
# It is the main indexing function
|
22
20
|
#
|
23
21
|
# @param druid [String] is the druid for an object e.g., ab123cd4567
|
24
22
|
# @param targets [Array] is an array with the targets list to index towards
|
25
23
|
#
|
26
24
|
# @raise it will raise erros if there is any problems happen in any level
|
27
|
-
def index(druid, targets
|
25
|
+
def index(druid, targets)
|
28
26
|
# Map the input to solr_doc
|
29
|
-
solr_doc =
|
27
|
+
solr_doc = mapper_class.new(druid).convert_to_solr_doc
|
30
28
|
|
31
29
|
# Get SOLR configuration and write
|
32
|
-
|
33
|
-
.process(druid, solr_doc, targets, Settings.SOLR_TARGETS.to_hash.deep_stringify_keys)
|
30
|
+
solr_writer.process(druid, solr_doc, targets)
|
34
31
|
end
|
35
32
|
|
36
33
|
# It deletes an item defined by druid from all registered solr core
|
37
34
|
# @param druid [String] is the druid for an object e.g., ab123cd4567
|
38
35
|
def delete(druid)
|
39
|
-
|
40
|
-
.solr_delete_from_all(druid, Settings.SOLR_TARGETS.to_hash.deep_stringify_keys)
|
36
|
+
solr_writer.solr_delete_from_all(druid)
|
41
37
|
end
|
42
38
|
|
39
|
+
private
|
40
|
+
|
41
|
+
def mapper_class
|
42
|
+
BaseIndexer.mapper_class_name.constantize
|
43
|
+
end
|
44
|
+
|
45
|
+
def solr_writer
|
46
|
+
BaseIndexer::Solr::Writer.new
|
47
|
+
end
|
43
48
|
end
|
44
49
|
end
|
@@ -6,6 +6,12 @@ module BaseIndexer
|
|
6
6
|
# Processes adds and deletes to the solr core
|
7
7
|
class Client
|
8
8
|
include DiscoveryIndexer::Logging
|
9
|
+
|
10
|
+
def self.logging_handler(id)
|
11
|
+
proc do |exception, attempt_number, _total_delay|
|
12
|
+
DiscoveryIndexer::Logging.logger.error "#{exception.class} on attempt #{attempt_number} for #{id}"
|
13
|
+
end
|
14
|
+
end
|
9
15
|
|
10
16
|
# Add the document to solr, retry if an error occurs.
|
11
17
|
# See https://github.com/ooyala/retries for docs on with_retries.
|
@@ -14,7 +20,19 @@ module BaseIndexer
|
|
14
20
|
# @param solr_connector [RSolr::Client] is an open connection with the solr core
|
15
21
|
# @param max_retries [Integer] the maximum number of tries before fail
|
16
22
|
def self.add(id, solr_doc, solr_connector, max_retries = 10)
|
17
|
-
|
23
|
+
with_retries(max_tries: max_retries, handler: logging_handler(id), base_sleep_seconds: 1, max_sleep_seconds: 5) do |attempt|
|
24
|
+
DiscoveryIndexer::Logging.logger.debug "Attempt #{attempt} for #{id}"
|
25
|
+
|
26
|
+
if allow_update?(solr_connector) && doc_exists?(id, solr_connector)
|
27
|
+
update_solr_doc(id, solr_doc, solr_connector)
|
28
|
+
DiscoveryIndexer::Logging.logger.info "Updating #{id} on attempt #{attempt}"
|
29
|
+
else
|
30
|
+
solr_connector.add(solr_doc, :add_attributes => {:commitWithin => 10000})
|
31
|
+
DiscoveryIndexer::Logging.logger.info "Indexing #{id} on attempt #{attempt}"
|
32
|
+
end
|
33
|
+
|
34
|
+
DiscoveryIndexer::Logging.logger.info "Completing #{id} successfully on attempt #{attempt}"
|
35
|
+
end
|
18
36
|
end
|
19
37
|
|
20
38
|
# Add the document to solr, retry if an error occurs.
|
@@ -23,35 +41,11 @@ module BaseIndexer
|
|
23
41
|
# @param solr_connector[RSolr::Client] is an open connection with the solr core
|
24
42
|
# @param max_retries [Integer] the maximum number of tries before fail
|
25
43
|
def self.delete(id, solr_connector, max_retries = 10)
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
# It's an internal method that receives all the requests and deal with
|
30
|
-
# SOLR core. This method can call add, delete, or update
|
31
|
-
#
|
32
|
-
# @param id [String] the document id, usually it will be druid.
|
33
|
-
# @param solr_doc [Hash] is the solr doc in hash format
|
34
|
-
# @param solr_connector [RSolr::Client] is an open connection with the solr core
|
35
|
-
# @param max_retries [Integer] the maximum number of tries before fail
|
36
|
-
def self.process(id, solr_doc, solr_connector, max_retries, is_delete = false)
|
37
|
-
handler = proc do |exception, attempt_number, _total_delay|
|
38
|
-
DiscoveryIndexer::Logging.logger.error "#{exception.class} on attempt #{attempt_number} for #{id}"
|
39
|
-
end
|
40
|
-
|
41
|
-
with_retries(max_tries: max_retries, handler: handler, base_sleep_seconds: 1, max_sleep_seconds: 5) do |attempt|
|
44
|
+
with_retries(max_tries: max_retries, handler: logging_handler(id), base_sleep_seconds: 1, max_sleep_seconds: 5) do |attempt|
|
42
45
|
DiscoveryIndexer::Logging.logger.debug "Attempt #{attempt} for #{id}"
|
43
46
|
|
44
|
-
|
45
|
-
|
46
|
-
DiscoveryIndexer::Logging.logger.info "Deleting #{id} on attempt #{attempt}"
|
47
|
-
elsif allow_update?(solr_connector) && doc_exists?(id, solr_connector)
|
48
|
-
update_solr_doc(id, solr_doc, solr_connector)
|
49
|
-
DiscoveryIndexer::Logging.logger.info "Updating #{id} on attempt #{attempt}"
|
50
|
-
else
|
51
|
-
solr_connector.add(solr_doc, :add_attributes => {:commitWithin => 10000})
|
52
|
-
DiscoveryIndexer::Logging.logger.info "Indexing #{id} on attempt #{attempt}"
|
53
|
-
end
|
54
|
-
#solr_connector.commit
|
47
|
+
solr_connector.delete_by_id(id, :add_attributes => {:commitWithin => 10000})
|
48
|
+
DiscoveryIndexer::Logging.logger.info "Deleting #{id} on attempt #{attempt}"
|
55
49
|
DiscoveryIndexer::Logging.logger.info "Completing #{id} successfully on attempt #{attempt}"
|
56
50
|
end
|
57
51
|
end
|
@@ -66,16 +60,10 @@ module BaseIndexer
|
|
66
60
|
# @param solr_connector [RSolr::Client] is an open connection with the solr core
|
67
61
|
# @return [Boolean] true if the solr doc defined by this id exists
|
68
62
|
def self.doc_exists?(id, solr_connector)
|
69
|
-
response = solr_connector.get 'select', params: { q: 'id:"' + id + '"' }
|
63
|
+
response = solr_connector.get 'select', params: { q: 'id:"' + id + '"', defType: 'lucene' }
|
70
64
|
response['response']['numFound'] == 1
|
71
65
|
end
|
72
66
|
|
73
|
-
# @param solr_connector [RSolr::Client] is an open connection with the solr core
|
74
|
-
# send hard commit to solr
|
75
|
-
def self.commit(solr_connector)
|
76
|
-
RestClient.post self.solr_url(solr_connector), {},:content_type => :json, :accept=>:json
|
77
|
-
end
|
78
|
-
|
79
67
|
# It is an internal method that updates the solr doc instead of adding a new one.
|
80
68
|
# @param id [String] the document id, usually it will be druid.
|
81
69
|
# @param solr_doc [Hash] is the solr doc in hash format
|
@@ -83,31 +71,12 @@ module BaseIndexer
|
|
83
71
|
def self.update_solr_doc(id, solr_doc, solr_connector)
|
84
72
|
# update_solr_doc can't used RSolr because updating hash doc is not supported
|
85
73
|
# so we need to build the json input manually
|
86
|
-
|
87
|
-
solr_doc.each do |
|
88
|
-
|
89
|
-
params += "\"#{field_name}\":"
|
90
|
-
new_values = [new_values] unless new_values.class == Array
|
91
|
-
new_values = new_values.map { |s| s.to_s.gsub('\\', '\\\\\\').gsub('"', '\"').strip } # strip leading/trailing spaces and escape quotes for each value
|
92
|
-
params += "{\"set\":[\"#{new_values.join('","')}\"]},"
|
74
|
+
hash = { id: id }
|
75
|
+
solr_doc.each do |k,v|
|
76
|
+
hash[k] = { set: v } unless k.to_sym == :id
|
93
77
|
end
|
94
|
-
params.
|
95
|
-
params += '}]'
|
96
|
-
RestClient.post self.solr_url(solr_connector), params, content_type: :json, accept: :json
|
78
|
+
solr_connector.update params: { commitWithin: 10000 }, data: Array.wrap(hash).to_json, headers: { 'Content-Type' => 'application/json' }
|
97
79
|
end
|
98
|
-
|
99
|
-
# adjust the solr_url so it works with or without a trailing /
|
100
|
-
# @param solr_connector [RSolr::Client] is an open connection with the solr core
|
101
|
-
# @return [String] the solr URL
|
102
|
-
def self.solr_url(solr_connector)
|
103
|
-
solr_url = solr_connector.options[:url]
|
104
|
-
if solr_url.end_with?('/')
|
105
|
-
"#{solr_url}update?commit=true"
|
106
|
-
else
|
107
|
-
"#{solr_url}/update?commit=true"
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
80
|
end
|
112
81
|
end
|
113
82
|
end
|
@@ -5,28 +5,30 @@ module BaseIndexer
|
|
5
5
|
module Solr
|
6
6
|
# Performs writes to solr client based upon true and false release flags
|
7
7
|
class Writer
|
8
|
-
attr_reader :solr_targets_configs
|
9
|
-
|
10
8
|
include DiscoveryIndexer::Logging
|
11
9
|
|
12
|
-
def process(id, index_doc, targets
|
13
|
-
@solr_targets_configs = targets_configs
|
10
|
+
def process(id, index_doc, targets)
|
14
11
|
index_targets = targets.select { |_, b| b }.keys
|
15
12
|
delete_targets = targets.reject { |_, b| b }.keys
|
16
13
|
|
17
14
|
# get targets with true
|
18
|
-
solr_index_client(id, index_doc, index_targets)
|
15
|
+
solr_index_client(id, index_doc, index_targets)
|
19
16
|
# get targets with false
|
20
|
-
solr_delete_client(id, delete_targets)
|
17
|
+
solr_delete_client(id, delete_targets)
|
21
18
|
end
|
22
19
|
|
23
|
-
def solr_delete_from_all(id
|
20
|
+
def solr_delete_from_all(id)
|
24
21
|
# Get a list of all registered targets
|
25
|
-
@solr_targets_configs = targets_configs
|
26
22
|
targets = solr_targets_configs.keys
|
27
23
|
solr_delete_client(id, targets)
|
28
24
|
end
|
29
25
|
|
26
|
+
def get_connector_for_target(solr_target)
|
27
|
+
solr_connector_targets[solr_target]
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
30
32
|
def solr_index_client(id, index_doc, targets)
|
31
33
|
targets.each do |solr_target|
|
32
34
|
solr_connector = get_connector_for_target(solr_target)
|
@@ -41,15 +43,16 @@ module BaseIndexer
|
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
config = solr_targets_configs[solr_target]
|
49
|
-
solr_connector = RSolr.connect(config.deep_symbolize_keys)
|
46
|
+
def solr_connector_targets
|
47
|
+
@solr_connector_targets ||= begin
|
48
|
+
solr_targets_configs.transform_values do |config|
|
49
|
+
RSolr.connect(config.deep_symbolize_keys)
|
50
50
|
end
|
51
51
|
end
|
52
|
-
|
52
|
+
end
|
53
|
+
|
54
|
+
def solr_targets_configs
|
55
|
+
Settings.SOLR_TARGETS.to_hash.stringify_keys
|
53
56
|
end
|
54
57
|
end
|
55
58
|
end
|
data/lib/base_indexer/version.rb
CHANGED
data/lib/tasks/index.rake
CHANGED
@@ -138,7 +138,7 @@ desc 'Index an entire collection, including the collection itself and all of its
|
|
138
138
|
#Run me: rake collection_indexer RAILS_ENV=production target=revs_prod collection_druid=oo000oo0001
|
139
139
|
# Examples:
|
140
140
|
task :collection_indexer => :environment do |t, args|
|
141
|
-
|
141
|
+
require 'harvestdor/indexer'
|
142
142
|
target = ENV['target'] # must pass in the target so specify solr core to index into
|
143
143
|
collection_druid = ENV['collection_druid']
|
144
144
|
|
@@ -160,14 +160,14 @@ task :collection_indexer => :environment do |t, args|
|
|
160
160
|
|
161
161
|
indexer = BaseIndexer.indexer_class.constantize.new
|
162
162
|
|
163
|
-
fetcher =
|
163
|
+
fetcher = Harvestdor::Indexer::PurlFetcher.new(url: Rails.application.config.fetcher_url)
|
164
164
|
|
165
165
|
collection_druid=collection_druid.gsub('druid:','')
|
166
166
|
|
167
167
|
indexer.index(collection_druid,{target=>true})
|
168
168
|
log my_logger,"Indexed collection: #{collection_druid}"
|
169
169
|
|
170
|
-
druids = fetcher.
|
170
|
+
druids = fetcher.druids_from_collection(collection_druid)
|
171
171
|
|
172
172
|
log my_logger,"** Found #{druids.size} members of the collection"
|
173
173
|
|
@@ -1,14 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe BaseIndexer::MainIndexerEngine do
|
3
|
+
RSpec.describe BaseIndexer::MainIndexerEngine do
|
4
4
|
before :all do
|
5
5
|
DiscoveryIndexer::PURL_DEFAULT = 'https://purl.stanford.edu'
|
6
6
|
end
|
7
7
|
|
8
8
|
describe '.delete' do
|
9
9
|
it 'should call solr_delete_from_all for delete call' do
|
10
|
-
expect_any_instance_of(BaseIndexer::Solr::Writer).to receive(:solr_delete_from_all)
|
11
|
-
.with('aa111aa1111', 'target1' => { 'url' => 'http://localhost:8983/solr/' }, 'target2' => { 'url' => 'http://localhost:8983/solr/' })
|
10
|
+
expect_any_instance_of(BaseIndexer::Solr::Writer).to receive(:solr_delete_from_all).with('aa111aa1111')
|
12
11
|
|
13
12
|
BaseIndexer::MainIndexerEngine.new.delete 'aa111aa1111'
|
14
13
|
end
|
@@ -1,47 +1,32 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe BaseIndexer::Solr::Client do
|
3
|
+
RSpec.describe BaseIndexer::Solr::Client do
|
4
4
|
let(:druid) { 'cb077vs7846' }
|
5
|
-
let
|
6
|
-
let(:max_retries) { 10 }
|
7
|
-
describe '.solr_url' do
|
8
|
-
it 'should correctly handle urls with both trailing and leading slashes' do
|
9
|
-
connectors=[RSolr.connect(url: 'http://localhost:8983/solr/'),RSolr.connect(url: 'http://localhost:8983/solr')]
|
10
|
-
connectors.each do |connector|
|
11
|
-
expect(described_class.solr_url(connector)).to eq 'http://localhost:8983/solr/update?commit=true'
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
5
|
+
let(:solr_doc) { { a: 1 } }
|
15
6
|
|
16
|
-
describe '
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
expect(solr_connector).to receive(:delete_by_id).with(druid, {:add_attributes=>{:commitWithin=>10000}})
|
22
|
-
BaseIndexer::Solr::Client.process(druid, {}, solr_connector, max_retries, is_delete)
|
23
|
-
end
|
7
|
+
describe 'delete' do
|
8
|
+
let (:solr_connector) { double('connector', { options: { url: 'http://localhost:8983/solr/' } } ) }
|
9
|
+
it 'should send a delete_by_id command' do
|
10
|
+
expect(solr_connector).to receive(:delete_by_id).with(druid, {:add_attributes=>{:commitWithin=>10000}})
|
11
|
+
BaseIndexer::Solr::Client.delete(druid, solr_connector)
|
24
12
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
BaseIndexer::Solr::Client.process(druid, solr_doc, solr_connector, max_retries, is_delete)
|
34
|
-
end
|
13
|
+
end
|
14
|
+
describe 'update' do
|
15
|
+
let(:response) { { 'response' => { 'numFound' => 1 } } }
|
16
|
+
let (:solr_connector) { double('connector', { options: { url: 'http://localhost:8983/solr/', allow_update: true } } ) }
|
17
|
+
it 'should send update_solr_doc' do
|
18
|
+
allow(solr_connector).to receive(:get).with("select", {:params=>{ :q=>"id:\"cb077vs7846\"", :defType => 'lucene'}}).and_return(response)
|
19
|
+
expect(solr_connector).to receive(:update).with(hash_including(data: [{ id: 'cb077vs7846', a: { set: 1 }}].to_json))
|
20
|
+
BaseIndexer::Solr::Client.add(druid, solr_doc, solr_connector)
|
35
21
|
end
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
22
|
+
end
|
23
|
+
describe 'add' do
|
24
|
+
let(:response) { double({}) }
|
25
|
+
let (:solr_connector) { double('connector', { options: { url: 'http://localhost:8983/solr/', allow_update: true, commitWithin: '10000'} } ) }
|
26
|
+
it 'should send an add command' do
|
27
|
+
allow(solr_connector).to receive(:get).with("select", {:params=>{:q=>"id:\"cb077vs7846\"", :defType => 'lucene'}}).and_return(:response)
|
28
|
+
expect(solr_connector).to receive(:add).with(solr_doc, :add_attributes => {:commitWithin => 10000})
|
29
|
+
BaseIndexer::Solr::Client.add(druid, solr_doc, solr_connector)
|
45
30
|
end
|
46
31
|
end
|
47
32
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe BaseIndexer::Solr::Writer do
|
3
|
+
RSpec.describe BaseIndexer::Solr::Writer do
|
4
4
|
let(:sw_connection) { { url: 'http://solr-core:8983/sw-prod/' } }
|
5
5
|
let(:preview_connection) { { url: 'http://solr-core:8983/sw-preview/' } }
|
6
6
|
let(:mix_targets) { { 'searchworks' => true, 'searchworks:preview' => false } }
|
@@ -20,17 +20,17 @@ describe BaseIndexer::Solr::Writer do
|
|
20
20
|
it 'should create two arrays index_targets and delete_targets' do
|
21
21
|
expect(subject).to receive(:solr_index_client).with(id, solr_doc, ['searchworks'])
|
22
22
|
expect(subject).to receive(:solr_delete_client).with(id, ['searchworks:preview'])
|
23
|
-
subject.process(id, solr_doc, mix_targets
|
23
|
+
subject.process(id, solr_doc, mix_targets)
|
24
24
|
end
|
25
25
|
it 'should not send delete messages when there are no delete targets' do
|
26
26
|
expect(subject).to receive(:solr_index_client).with(id, solr_doc, ['searchworks'])
|
27
|
-
expect(
|
28
|
-
subject.process(id, solr_doc, index_targets
|
27
|
+
expect(BaseIndexer::Solr::Client).not_to receive(:delete)
|
28
|
+
subject.process(id, solr_doc, index_targets)
|
29
29
|
end
|
30
30
|
it 'should not send index messages when there are no index targets' do
|
31
|
-
expect(
|
31
|
+
expect(BaseIndexer::Solr::Client).not_to receive(:add)
|
32
32
|
expect(subject).to receive(:solr_delete_client).with(id, ['searchworks:preview'])
|
33
|
-
subject.process(id, solr_doc, delete_targets
|
33
|
+
subject.process(id, solr_doc, delete_targets)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -38,12 +38,12 @@ describe BaseIndexer::Solr::Writer do
|
|
38
38
|
it 'should call solr client delete method for each target' do
|
39
39
|
expect(BaseIndexer::Solr::Client).to receive(:delete).with('aa111bb222', an_instance_of(RSolr::Client))
|
40
40
|
expect(BaseIndexer::Solr::Client).to receive(:delete).with('aa111bb222', an_instance_of(RSolr::Client))
|
41
|
-
subject.
|
41
|
+
subject.process('aa111bb222', {}, { 'searchworks' => false, 'searchworks:preview' => false })
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'should not call solr client delete method when there is no client for the given target' do
|
45
45
|
expect(BaseIndexer::Solr::Client).not_to receive(:delete)
|
46
|
-
subject.
|
46
|
+
subject.process('aa111bb222', {}, { 'blah' => false })
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -62,11 +62,5 @@ describe BaseIndexer::Solr::Writer do
|
|
62
62
|
solr_connector = subject.get_connector_for_target('nothing')
|
63
63
|
expect(solr_connector).to be_nil
|
64
64
|
end
|
65
|
-
|
66
|
-
it 'should return nil for a nil solr targets list' do
|
67
|
-
allow(subject).to receive(:solr_targets_configs).and_return(nil)
|
68
|
-
solr_connector = subject.get_connector_for_target('searchworks')
|
69
|
-
expect(solr_connector).to be_nil
|
70
|
-
end
|
71
65
|
end
|
72
66
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe BaseIndexer::ItemsController, type: :controller do
|
3
|
+
RSpec.describe BaseIndexer::ItemsController, type: :controller do
|
4
4
|
let(:my_instance) { instance_double(BaseIndexer::MainIndexerEngine) }
|
5
5
|
before do
|
6
6
|
allow(BaseIndexer::MainIndexerEngine).to receive(:new).and_return(my_instance)
|
data/spec/spec_helper.rb
CHANGED
@@ -65,48 +65,55 @@ RSpec.configure do |config|
|
|
65
65
|
|
66
66
|
# The settings below are suggested to provide a good initial experience
|
67
67
|
# with RSpec, but feel free to customize to your heart's content.
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
#
|
94
|
-
#
|
95
|
-
#
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
#
|
104
|
-
#
|
105
|
-
#
|
106
|
-
|
107
|
-
|
108
|
-
#
|
109
|
-
#
|
110
|
-
#
|
111
|
-
#
|
68
|
+
# These two settings work together to allow you to limit a spec run
|
69
|
+
# to individual examples or groups you care about by tagging them with
|
70
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
71
|
+
# get run.
|
72
|
+
config.filter_run :focus
|
73
|
+
config.run_all_when_everything_filtered = true
|
74
|
+
|
75
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
76
|
+
# recommended. For more details, see:
|
77
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
78
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
79
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
80
|
+
config.disable_monkey_patching!
|
81
|
+
|
82
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
83
|
+
|
84
|
+
# This allows you to limit a spec run to individual examples or groups
|
85
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
86
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
87
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
88
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
89
|
+
config.filter_run_when_matching :focus
|
90
|
+
|
91
|
+
config.example_status_persistence_file_path = 'spec/examples.txt'
|
92
|
+
|
93
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
94
|
+
# file, and it's useful to allow more verbose output when running an
|
95
|
+
# individual spec file.
|
96
|
+
if config.files_to_run.one?
|
97
|
+
# Use the documentation formatter for detailed output,
|
98
|
+
# unless a formatter has already been configured
|
99
|
+
# (e.g. via a command-line flag).
|
100
|
+
config.default_formatter = 'doc'
|
101
|
+
end
|
102
|
+
|
103
|
+
# Print the 10 slowest examples and example groups at the
|
104
|
+
# end of the spec run, to help surface which specs are running
|
105
|
+
# particularly slow.
|
106
|
+
config.profile_examples = 10
|
107
|
+
|
108
|
+
# Run specs in random order to surface order dependencies. If you find an
|
109
|
+
# order dependency and want to debug it, you can fix the order by providing
|
110
|
+
# the seed, which is printed after each run.
|
111
|
+
# --seed 1234
|
112
|
+
config.order = :random
|
113
|
+
|
114
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
115
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
116
|
+
# test failures related to randomization by passing the same `--seed` value
|
117
|
+
# as the one that triggered the failure.
|
118
|
+
Kernel.srand config.seed
|
112
119
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: base_indexer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ahmed Alsum
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-03-
|
12
|
+
date: 2018-03-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -60,7 +60,7 @@ dependencies:
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
63
|
+
name: harvestdor-indexer
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
@@ -242,7 +242,6 @@ files:
|
|
242
242
|
- Rakefile
|
243
243
|
- app/controllers/base_indexer/about_controller.rb
|
244
244
|
- app/controllers/base_indexer/application_controller.rb
|
245
|
-
- app/controllers/base_indexer/collections_controller.rb
|
246
245
|
- app/controllers/base_indexer/items_controller.rb
|
247
246
|
- app/helpers/base_indexer/application_helper.rb
|
248
247
|
- app/helpers/base_indexer/items_helper.rb
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require_dependency 'base_indexer/application_controller'
|
2
|
-
|
3
|
-
module BaseIndexer
|
4
|
-
class CollectionsController < ApplicationController
|
5
|
-
def update
|
6
|
-
druid = remove_prefix params[:id]
|
7
|
-
|
8
|
-
Rails.logger.debug "Receiving indexing of collection #{druid}"
|
9
|
-
targets = params[:subtargets]
|
10
|
-
|
11
|
-
# initial collection item itself
|
12
|
-
indexer = BaseIndexer.indexer_class.constantize.new
|
13
|
-
indexer.index druid, targets
|
14
|
-
|
15
|
-
# Determine collection item druids
|
16
|
-
fetcher = BaseIndexer.fetcher_class.constantize.new(service_url: Rails.application.config.fetcher_url)
|
17
|
-
item_druids = fetcher.druid_array(fetcher.get_collection(druid, {}))
|
18
|
-
|
19
|
-
Rails.logger.debug "Found #{item_druids.size} members of the collection #{druid}"
|
20
|
-
|
21
|
-
counter = 0
|
22
|
-
|
23
|
-
item_druids.each do |idruid|
|
24
|
-
druid = remove_prefix idruid
|
25
|
-
counter += 1
|
26
|
-
indexer.index druid, targets
|
27
|
-
Rails.logger.debug "#{counter} of #{item_druids.size}: #{druid}"
|
28
|
-
end
|
29
|
-
|
30
|
-
@status = report_success
|
31
|
-
head :ok
|
32
|
-
Rails.logger.debug "Completing indexing of collection #{druid}"
|
33
|
-
|
34
|
-
rescue Exception => e
|
35
|
-
@status = report_failure request.method_symbol, params, e
|
36
|
-
Rails.logger.error @status
|
37
|
-
raise
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|