Skip to content

Commit

Permalink
Merge pull request #102 from mlibrary/enable-solr-cloud-as-option
Browse files Browse the repository at this point in the history
solr cloud for authors is optional
  • Loading branch information
niquerio authored Nov 6, 2023
2 parents d0c0635 + c338e52 commit 6ea8aae
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ gem "puma"
gem "faraday"
gem "yabeda-puma-plugin"
gem "yabeda-prometheus"
gem "canister"

group :development do
gem "sinatra-contrib"
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ GEM
ast (2.4.2)
base64 (0.1.1)
byebug (11.1.3)
canister (0.9.2)
climate_control (1.2.0)
coderay (1.1.3)
concurrent-ruby (1.2.2)
Expand Down Expand Up @@ -145,6 +146,7 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
canister
climate_control
faraday
listen
Expand Down
1 change: 1 addition & 0 deletions catalog-browse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

require "yaml"

require_relative "lib/services"
require_relative "lib/catalog_solr_client"
require_relative "lib/utilities/browse_solr_client"
require_relative "lib/utilities/string_cleaner"
Expand Down
4 changes: 4 additions & 0 deletions env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
BIBLIO_SOLR='http://biblio-server/solr'
AUTHOR_SOLR='http://catalog-solr-server/solr'
BROWSE_SOLR='http://catalog-solr-server/solr'
CALLNUMBER_CORE='callnumbers'
AUTHORITY_CORE='authors'
SOLR_USER='solr'
SOLR_PASSWORD='SolrRocks'
SOLR_CLOUD_ON='false'
2 changes: 1 addition & 1 deletion lib/models/author_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def self.for(direction:, reference_id:, num_rows_to_display:, original_reference
num_rows_to_display: num_rows_to_display,
original_reference: original_reference,
banner_reference: banner_reference,
browse_solr_client: BrowseSolrClient.new(core: ENV.fetch("AUTHORITY_CORE"), match_field: "term", q: "browse_field:name")
browse_solr_client: BrowseSolrClient.new(solr_url: S.author_solr, core: S.authority_core, match_field: "term", q: "browse_field:name", solr_cloud_on: S.solr_cloud_on?)
)

new(browse_list: browse_list)
Expand Down
19 changes: 19 additions & 0 deletions lib/services.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require "canister"

Services = Canister.new
S = Services

S.register(:solr_cloud_on?) do
ENV["SOLR_CLOUD_ON"] == "true"
end

S.register(:author_solr) do
ENV["AUTHOR_SOLR"] || ENV["BROWSE_SOLR"]
end

[
"BROWSE_SOLR", "BIBLIO_SOLR", "SOLR_USER", "SOLR_PASSWORD",
"CALLNUMBER_CORE", "AUTHORITY_CORE"
].each do |e|
Services.register(e.downcase.to_sym) { ENV[e] }
end
3 changes: 2 additions & 1 deletion lib/utilities/browse_solr_client.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
require "faraday"

class BrowseSolrClient
def initialize(solr_url: ENV.fetch("BROWSE_SOLR"), core: ENV.fetch("CALLNUMBER_CORE"), match_field: "callnumber", q: "*:*")
def initialize(solr_url: ENV.fetch("BROWSE_SOLR"), core: ENV.fetch("CALLNUMBER_CORE"), match_field: "callnumber", q: "*:*", solr_cloud_on: false)
@conn = Faraday.new(
url: solr_url
) do |f|
f.request :json
f.request :authorization, :basic, ENV["SOLR_USER"], ENV["SOLR_PASSWORD"] if solr_cloud_on
# f.request :retry, {max: 1, retry_statuses: [500]}
f.response :json
end
Expand Down
5 changes: 5 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ module RSpecMixin
include Rack::Test::Methods
def app = Sinatra::Application
end

# set up dependencies
S.register(:author_solr) { S.browse_solr }
S.register(:solr_cloud_on?) { false }

RSpec.configure do |config|
config.include RSpecMixin
# rspec-expectations config goes here. You can use an alternate
Expand Down

0 comments on commit 6ea8aae

Please sign in to comment.