Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable SolrCloud and Cleanup #103

Merged
merged 10 commits into from
Dec 15, 2023
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ node_modules/
public/browse.css
.bash_history
.cache/
.solargraph.yml
14 changes: 7 additions & 7 deletions catalog-browse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
require_relative "lib/utilities/string_cleaner"
require_relative "lib/models/browse_list"
require_relative "lib/models/browse_list_presenter"
require_relative "lib/models/callnumber_list"
require_relative "lib/models/callnumber_item"
require_relative "lib/models/call_number_list"
require_relative "lib/models/call_number_item"
require_relative "lib/models/author_list"
require_relative "lib/models/author_item"
require_relative "lib/models/subject_list"
Expand All @@ -20,7 +20,7 @@
require_relative "lib/models/datastores"

CatalogSolrClient.configure do |config|
config.solr_url = ENV.fetch("BIBLIO_SOLR")
config.solr_url = S.biblio_solr
end

get "/subject" do
Expand All @@ -47,13 +47,13 @@
erb :authors, locals: {list: list}
end
get "/callnumber" do
callnumber = params[:query]
reference_id = params[:reference_id] || callnumber
call_number = params[:query]
reference_id = params[:reference_id] || call_number
begin
list = CallnumberList.for(direction: params[:direction], reference_id: reference_id, num_rows_to_display: 20, original_reference: callnumber, banner_reference: params[:banner_reference])
list = CallNumberList.for(direction: params[:direction], reference_id: reference_id, num_rows_to_display: 20, original_reference: call_number, banner_reference: params[:banner_reference])
rescue => e
logger.error(e.message)
list = CallnumberList::Error.new(reference_id)
list = CallNumberList::Error.new(reference_id)
end
erb :call_number, locals: {list: list}
end
Expand Down
15 changes: 10 additions & 5 deletions env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
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'
SOLRCLOUD_URL='http://solr-cloud-server/solr'
CALL_NUMBER_COLLECTION='call_number_browse'
AUTHORITY_COLLECTION='authority_collection'
SOLR_USER='solr'
SOLR_PASSWORD='SolrRocks'
SOLR_CLOUD_ON='false'

SOLRCLOUD_ON='true'

#Legacy env vars
BROWSE_SOLR='http://catalog-solr-server/solr'
CALLNUMBER_CORE='callnumber_browse'
AUTHORITY_CORE='authority_core'
2 changes: 1 addition & 1 deletion lib/models/author_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def kind
end

def url
"#{ENV.fetch("BASE_URL")}/author?query=#{URI.encode_www_form_component(@author)}"
"#{S.base_url}/author?query=#{URI.encode_www_form_component(@author)}"
end

def heading_link?
Expand Down
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(solr_url: S.author_solr, core: S.authority_core, match_field: "term", q: "browse_field:name", solr_cloud_on: S.solr_cloud_on?)
browse_solr_client: BrowseSolrClient.new(core: S.authority_collection, match_field: "term", q: "browse_field:name")
)

new(browse_list: browse_list)
Expand Down
2 changes: 1 addition & 1 deletion lib/models/browse_list_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ def feedback_url
private

def nav_url(params)
"#{ENV.fetch("BASE_URL")}/#{path}?#{URI.encode_www_form(params)}"
"#{S.base_url}/#{path}?#{URI.encode_www_form(params)}"
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CallnumberItem
class CallNumberItem
def initialize(browse_doc:, catalog_doc:, exact_match:)
@browse_doc = browse_doc
@catalog_doc = catalog_doc || {}
Expand All @@ -13,6 +13,11 @@ def exact_match?
!!@exact_match
end

# for the view
def call_number
@browse_doc["callnumber"]&.strip
end

# for the view
def callnumber
@browse_doc["callnumber"]&.strip
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CallnumberList < BrowseListPresenter
class CallNumberList < BrowseListPresenter
def self.for(direction:, reference_id:, num_rows_to_display:, original_reference:, banner_reference:)
browse_list = BrowseList.for(
direction: direction,
Expand Down Expand Up @@ -37,7 +37,7 @@ def items
exact_match = exact_matches.any?(browse_doc["id"])
banner_match = (banner_reference == browse_doc["id"])
banner_index = index if (exact_match || banner_match) && banner_index.nil?
CallnumberItem.new(browse_doc: browse_doc, catalog_doc: catalog_doc(browse_doc["bib_id"]), exact_match: exact_match)
CallNumberItem.new(browse_doc: browse_doc, catalog_doc: catalog_doc(browse_doc["bib_id"]), exact_match: exact_match)
end
banner_index.nil? ? my_items : my_items.insert(banner_index, match_notice)
end
Expand All @@ -53,7 +53,7 @@ def catalog_doc(bib_id)
end
end

class CallnumberList::Error < CallnumberList
class CallNumberList::Error < CallNumberList
attr_reader :original_reference
def initialize(original_reference = "")
@original_reference = original_reference
Expand Down
2 changes: 1 addition & 1 deletion lib/models/datastores.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def label
end

def href
ENV.fetch("SEARCH_URL") + @datastore[:href]
S.search_url + @datastore[:href]
end

def current?
Expand Down
10 changes: 5 additions & 5 deletions lib/models/search_dropdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class SearchDropdown::Browse < SearchDropdown
def url
case @type
when "browse_by_callnumber"
"#{ENV.fetch("BASE_URL")}/callnumber?query=#{encoded_query}"
"#{S.base_url}/callnumber?query=#{encoded_query}"
when "browse_by_author"
"#{ENV.fetch("BASE_URL")}/author?query=#{encoded_query}"
"#{S.base_url}/author?query=#{encoded_query}"
when "browse_by_subject"
"#{ENV.fetch("BASE_URL")}/subject?query=#{encoded_query}"
"#{S.base_url}/subject?query=#{encoded_query}"
else
# Users shouldn't be able to do this;
# Send them back to search without their query if it happens.
ENV.fetch("SEARCH_URL")
S.search_url
end
end

Expand All @@ -38,7 +38,7 @@ def encoded_query

class SearchDropdown::Search < SearchDropdown
def url
"#{ENV.fetch("SEARCH_URL")}/catalog?query=#{encoded_query}"
"#{S.search_url}/catalog?query=#{encoded_query}"
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/models/subject_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def record_text
end

def url
"#{ENV.fetch("BASE_URL")}/subject?query=#{URI.encode_www_form_component(@subject)}"
"#{S.base_url}/subject?query=#{URI.encode_www_form_component(@subject)}"
end

def heading_link?
Expand Down
2 changes: 1 addition & 1 deletion lib/models/subject_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:subject")
browse_solr_client: BrowseSolrClient.new(core: S.authority_collection, match_field: "term", q: "browse_field:subject")
)

new(browse_list: browse_list)
Expand Down
19 changes: 13 additions & 6 deletions lib/services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@
Services = Canister.new
S = Services

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

S.register(:author_solr) do
ENV["AUTHOR_SOLR"] || ENV["BROWSE_SOLR"]
S.register(:call_number_collection) do
S.solrcloud_on? ? ENV["CALL_NUMBER_COLLECTION"] : ENV["CALLNUMBER_CORE"]
end

S.register(:authority_collection) do
S.solrcloud_on? ? ENV["AUTHORITY_COLLECTION"] : ENV["AUTHORITY_CORE"]
end

S.register(:solr_url) do
S.solrcloud_on? ? ENV["SOLRCLOUD_URL"] : ENV["BROWSE_SOLR"]
end

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

class BrowseSolrClient
def initialize(solr_url: ENV.fetch("BROWSE_SOLR"), core: ENV.fetch("CALLNUMBER_CORE"), match_field: "callnumber", q: "*:*", solr_cloud_on: false)
def initialize(solr_url: S.solr_url, core: S.call_number_collection, match_field: "callnumber", q: "*:*")
@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 :authorization, :basic, S.solr_user, S.solr_password if S.solrcloud_on?
# f.request :retry, {max: 1, retry_statuses: [500]}
f.response :json
end
Expand Down Expand Up @@ -39,7 +39,7 @@ def browse(rows:, sort:, range:)
@conn.public_send(:get, "#{@path_prefix}/select", query)
end

def exact_matches(value: callnumber)
def exact_matches(value:)
query = {
q: @q,
fq: %(#{@match_field}:"#{value}"),
Expand Down
4 changes: 2 additions & 2 deletions spec/models/author_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
context "#previous_url" do
it "returns appropriate url" do
allow(@browse_list).to receive(:previous_url_params).and_return({param_1: "value_1", param_2: "value_2"})
expect(subject.previous_url).to eq("#{ENV.fetch("BASE_URL")}/author?param_1=value_1&param_2=value_2")
expect(subject.previous_url).to eq("#{S.base_url}/author?param_1=value_1&param_2=value_2")
end
end
context "#next_url" do
it "returns appropriate url" do
allow(@browse_list).to receive(:next_url_params).and_return({param_1: "value_1", param_2: "value_2"})
expect(subject.next_url).to eq("#{ENV.fetch("BASE_URL")}/author?param_1=value_1&param_2=value_2")
expect(subject.next_url).to eq("#{S.base_url}/author?param_1=value_1&param_2=value_2")
end
end
end
Expand Down
5 changes: 4 additions & 1 deletion spec/models/callnumber_item_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative "../spec_helper"
describe CallnumberItem do
describe CallNumberItem do
before(:each) do
@catalog_doc = JSON.parse(fixture("zhizn_bib.json"))
@index_doc = JSON.parse(fixture("zhizn_browse.json"))
Expand All @@ -11,6 +11,9 @@
it "has false match_notice?" do
expect(subject.match_notice?).to eq(false)
end
it "shows call_number" do
expect(subject.call_number).to eq("PQ 1852 .B85 1992")
end
it "shows callnumber" do
expect(subject.callnumber).to eq("PQ 1852 .B85 1992")
end
Expand Down
8 changes: 4 additions & 4 deletions spec/models/callnumber_list_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe CallnumberList do
describe CallNumberList do
before(:each) do
@browse_list = instance_double(BrowseList, original_reference: "callnumber")
end
Expand Down Expand Up @@ -36,17 +36,17 @@
context "#previous_url" do
it "returns appropriate url" do
allow(@browse_list).to receive(:previous_url_params).and_return({param_1: "value_1", param_2: "value_2"})
expect(subject.previous_url).to eq("#{ENV.fetch("BASE_URL")}/callnumber?param_1=value_1&param_2=value_2")
expect(subject.previous_url).to eq("#{S.base_url}/callnumber?param_1=value_1&param_2=value_2")
end
end
context "#next_url" do
it "returns appropriate url" do
allow(@browse_list).to receive(:next_url_params).and_return({param_1: "value_1", param_2: "value_2"})
expect(subject.next_url).to eq("#{ENV.fetch("BASE_URL")}/callnumber?param_1=value_1&param_2=value_2")
expect(subject.next_url).to eq("#{S.base_url}/callnumber?param_1=value_1&param_2=value_2")
end
end
end
describe CallnumberList::Error do
describe CallNumberList::Error do
before(:each) do
@params = {
original_reference: "OSU"
Expand Down
2 changes: 1 addition & 1 deletion spec/models/datastores_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
end
context "#href" do
it "has an href" do
expect(datastore.href).to eq("#{ENV.fetch("SEARCH_URL")}/datastore")
expect(datastore.href).to eq("#{S.search_url}/datastore")
end
end
context "#current?" do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/search_dropdown_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def encoded_query(query)
end
it "returns appropriate browse url" do
@type = "browse_by_callnumber"
expect(subject).to eq("#{ENV.fetch("BASE_URL")}/callnumber?query=#{encoded_query("Things")}")
expect(subject).to eq("#{S.base_url}/callnumber?query=#{encoded_query("Things")}")
end
it "sends the user to search if they submit nonexistent browse_by type" do
@type = "browse_by_something_that_does_not_exist"
Expand Down
4 changes: 2 additions & 2 deletions spec/models/subject_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
context "#previous_url" do
it "returns appropriate url" do
allow(@browse_list).to receive(:previous_url_params).and_return({param_1: "value_1", param_2: "value_2"})
expect(subject.previous_url).to eq("#{ENV.fetch("BASE_URL")}/subject?param_1=value_1&param_2=value_2")
expect(subject.previous_url).to eq("#{S.base_url}/subject?param_1=value_1&param_2=value_2")
end
end
context "#next_url" do
it "returns appropriate url" do
allow(@browse_list).to receive(:next_url_params).and_return({param_1: "value_1", param_2: "value_2"})
expect(subject.next_url).to eq("#{ENV.fetch("BASE_URL")}/subject?param_1=value_1&param_2=value_2")
expect(subject.next_url).to eq("#{S.base_url}/subject?param_1=value_1&param_2=value_2")
end
end
end
Expand Down
Loading