diff --git a/Gemfile b/Gemfile index ed976a845..6cb95eb79 100644 --- a/Gemfile +++ b/Gemfile @@ -71,7 +71,7 @@ group :test do gem "webdrivers" end -gem 'blacklight', ">= 6.1" +gem 'blacklight', "= 8.0.1" group :development, :test do gem "solr_wrapper", ">= 0.3" @@ -79,4 +79,4 @@ end gem "rsolr", ">= 1.0", "< 3" gem "bootstrap", "\~\>\ 5.1" gem "sassc-rails", "~> 2.1" -gem "blacklight-marc", "~> 8.0" \ No newline at end of file +gem "blacklight-marc", "= 8.1.0" \ No newline at end of file diff --git a/app/components/legacy_ocr_search_component.rb b/app/components/legacy_ocr_search_component.rb index 0e28a5c1a..b5e304961 100644 --- a/app/components/legacy_ocr_search_component.rb +++ b/app/components/legacy_ocr_search_component.rb @@ -7,7 +7,7 @@ def initialize(documentId:, term:, prefix:) @prefix = prefix puts term.length if @term.length != 0 - rsolr = RSolr.connect :url => 'http://159.203.33.98:8983/solr/page' + rsolr = RSolr.connect :url => 'http://solr:8983/solr/page' if term != "*:*" @legacy_ocr_search_request= rsolr.get 'select', :params => { :rows => 500, diff --git a/config/blacklight.yml b/config/blacklight.yml index a905c6500..0aaeb3df2 100644 --- a/config/blacklight.yml +++ b/config/blacklight.yml @@ -1,10 +1,10 @@ load_defaults: 8.0.1 development: adapter: solr - url: <%= ENV['SOLR_URL'] || "http://159.203.33.98:8983/solr/blacklight" %> + url: <%= ENV['SOLR_URL'] || "http://solr:8983/solr/blacklight" %> test: &test adapter: solr - url: <%= ENV['SOLR_URL'] || "http://159.203.33.98:8983/solr/blacklight" %> + url: <%= ENV['SOLR_URL'] || "http://solr:8983/solr/blacklight" %> production: adapter: solr - url: <%= ENV['SOLR_URL'] || "http://159.203.33.98:8983/solr/blacklight" %> + url: <%= ENV['SOLR_URL'] || "http://solr:8983/solr/blacklight" %> diff --git a/config/initializers/blacklight/solr/response/repository.rb b/config/initializers/blacklight/solr/response/repository.rb deleted file mode 100644 index 5703eb404..000000000 --- a/config/initializers/blacklight/solr/response/repository.rb +++ /dev/null @@ -1,157 +0,0 @@ -# frozen_string_literal: true -require "pp" -module Blacklight::Solr - class Repository < Blacklight::AbstractRepository - ## - # Find a single solr document result (by id) using the document configuration - # @param [String] id document's unique key value - # @param [Hash] params additional solr query parameters - def find id, params = {} - doc_params = params.reverse_merge(blacklight_config.default_document_solr_params) - .reverse_merge(qt: blacklight_config.document_solr_request_handler) - .merge(blacklight_config.document_unique_id_param => id) - - solr_response = send_and_receive blacklight_config.document_solr_path || blacklight_config.solr_path, doc_params - raise Blacklight::Exceptions::RecordNotFound if solr_response.documents.empty? - - solr_response - end - - ## - # Execute a search query against solr - # @param [Hash] params solr query parameters - def search params = {} - #puts "Orig" - #puts params.class - #puts params.blacklight_params - - #if params.blacklight_params[:q].nil? || params.blacklight_params[:q].empty? - # puts "Pass" - # # {"search_field"=>"title_tsim", "q"=>"British", "controller"=>"catalog", "action"=>"index"} - # params.blacklight_params[:q] = "*:*" - # #params.delete("q") - #end - #puts "After" - #puts params.blacklight_params - send_and_receive search_path(params), params.reverse_merge(qt: blacklight_config.qt) - end - - # @param [Hash] request_params - # @return [Blacklight::Suggest::Response] - def suggestions(request_params) - suggest_results = connection.send_and_receive(suggest_handler_path, params: request_params) - Blacklight::Suggest::Response.new suggest_results, request_params, suggest_handler_path, suggester_name - end - - ## - # Gets a list of available fields - # @return [Hash] - def reflect_fields - send_and_receive('admin/luke', params: { fl: '*', 'json.nl' => 'map' })['fields'] - end - - ## - # @return [boolean] true if the repository is reachable - def ping - response = connection.send_and_receive 'admin/ping', {} - Blacklight.logger&.info("Ping [#{connection.uri}] returned: '#{response['status']}'") - response['status'] == "OK" - end - - ## - # Execute a solr query - # TODO: Make this private after we have a way to abstract admin/luke and ping - # @see [RSolr::Client#send_and_receive] - # @overload find(solr_path, params) - # Execute a solr query at the given path with the parameters - # @param [String] solr path (defaults to blacklight_config.solr_path) - # @param [Hash] parameters for RSolr::Client#send_and_receive - # @overload find(params) - # @param [Hash] parameters for RSolr::Client#send_and_receive - # @return [Blacklight::Solr::Response] the solr response object - def send_and_receive(path, solr_params = {}) - benchmark("Solr fetch", level: :debug) do - res = connection.send_and_receive(path, build_solr_request(solr_params)) - solr_response = blacklight_config.response_model.new(res, solr_params, document_model: blacklight_config.document_model, blacklight_config: blacklight_config) - - Blacklight.logger&.debug("Solr query: #{blacklight_config.http_method} #{path} #{solr_params.to_hash.inspect}") - Blacklight.logger&.debug("Solr response: #{solr_response.inspect}") if defined?(::BLACKLIGHT_VERBOSE_LOGGING) && ::BLACKLIGHT_VERBOSE_LOGGING - solr_response - end - rescue *defined_rsolr_timeout_exceptions => e - raise Blacklight::Exceptions::RepositoryTimeout, "Timeout connecting to Solr instance using #{connection.inspect}: #{e.inspect}" - rescue Errno::ECONNREFUSED => e - # intended for and likely to be a RSolr::Error:ConnectionRefused, specifically. - raise Blacklight::Exceptions::ECONNREFUSED, "Unable to connect to Solr instance using #{connection.inspect}: #{e.inspect}" - rescue RSolr::Error::Http => e - raise Blacklight::Exceptions::InvalidRequest, e.message - end - - # @return [Hash] - # @!visibility private - def build_solr_request(solr_params) - if uses_json_query_dsl?(solr_params) - puts "One" - solr_params[:json][:query][:bool][:must].delete("") - pp solr_params - tcjn = { params: solr_params.to_hash.except(:json) }.merge(solr_params[:json]) - pp tcjn - { - data: tcjn.to_json, - method: :post, - headers: { 'Content-Type' => 'application/json' } - } - else - puts "Two" - tcjn = solr_params.to_hash - key = blacklight_config.http_method == :post ? :data : :params - { - key => tcjn, - method: blacklight_config.http_method - } - end - end - - private - - ## - # @return [String] - def suggest_handler_path - blacklight_config.autocomplete_path - end - - def suggester_name - blacklight_config.autocomplete_suggester - end - - def build_connection - RSolr.connect(connection_config.merge(adapter: connection_config[:http_adapter])) - end - - # RSolr 2.4.0+ has a RSolr::Error::Timeout that we'd like to treat specially - # instead of lumping into RSolr::Error::Http. Before that we can not rescue - # specially, so return an empty array. - # - # @return [Array] that can be used, with a splat, as argument - # to a ruby rescue - def defined_rsolr_timeout_exceptions - if defined?(RSolr::Error::Timeout) - [RSolr::Error::Timeout] - else - [] - end - end - - # @return [String] - def search_path(solr_params) - return blacklight_config.json_solr_path if blacklight_config.json_solr_path && uses_json_query_dsl?(solr_params) - - blacklight_config.solr_path - end - - # @return [Boolean] - def uses_json_query_dsl?(solr_params) - solr_params[:json].present? - end - end - end \ No newline at end of file diff --git a/config/initializers/blacklight/solr/search_builder.rb b/config/initializers/blacklight/solr/search_builder.rb deleted file mode 100644 index 989eb6eb3..000000000 --- a/config/initializers/blacklight/solr/search_builder.rb +++ /dev/null @@ -1,265 +0,0 @@ -# frozen_string_literal: true - -module Blacklight - ## - # Blacklight's SearchBuilder converts blacklight request parameters into - # query parameters appropriate for search index. It does so by evaluating a - # chain of processing methods to populate a result hash (see {#to_hash}). - class SearchBuilder - class_attribute :default_processor_chain - self.default_processor_chain = [] - - attr_reader :processor_chain, :search_state, :blacklight_params, :params - - # @overload initialize(scope) - # @param [Object] scope scope the scope where the filter methods reside in. - # @overload initialize(processor_chain, scope) - # @param [List,TrueClass] processor_chain options a list of filter methods to run or true, to use the default methods - # @param [Object] scope the scope where the filter methods reside in. - def initialize(*options) - case options.size - when 1 - @processor_chain = default_processor_chain.dup - @scope = options.first - when 2 - @processor_chain, @scope = options - else - raise ArgumentError, "wrong number of arguments. (#{options.size} for 1..2)" - end - - @blacklight_params = {} - search_state_class = @scope.try(:search_state_class) || Blacklight::SearchState - @search_state = search_state_class.new(@blacklight_params, @scope&.blacklight_config, @scope) - @additional_filters = {} - @merged_params = {} - @reverse_merged_params = {} - end - - ## - # Set the parameters to pass through the processor chain - def with(blacklight_params_or_search_state = {}) - params_will_change! - @search_state = blacklight_params_or_search_state.is_a?(Blacklight::SearchState) ? blacklight_params_or_search_state : @search_state.reset(blacklight_params_or_search_state) - @blacklight_params = @search_state.params.dup - self - end - - ## - # Update the :q (query) parameter - # @param [Hash] conditions the field and values to query on - # @example - # search_builder.where(id: [1,2,3]) # produces: q:"{!lucene}id:(1 OR 2 OR 3)" - def where(conditions) - params_will_change! - @search_state = @search_state.reset(@search_state.params.merge(q: conditions)) - @blacklight_params = @search_state.params - @additional_filters = conditions - self - end - - ## - # Append additional processor chain directives - def append(*addl_processor_chain) - params_will_change! - builder = self.class.new(processor_chain + addl_processor_chain, scope) - .with(search_state) - .merge(@merged_params) - .reverse_merge(@reverse_merged_params) - - builder.start = @start if @start - builder.rows = @rows if @rows - builder.page = @page if @page - builder.facet = @facet if @facet - builder - end - - ## - # Converse to append, remove processor chain directives, - # returning a new builder that's a copy of receiver with - # specified change. - # - # Methods in argument that aren't currently in processor - # chain are ignored as no-ops, rather than raising. - def except(*except_processor_chain) - builder = self.class.new(processor_chain - except_processor_chain, scope) - .with(search_state) - .merge(@merged_params) - .reverse_merge(@reverse_merged_params) - - builder.start = @start if @start - builder.rows = @rows if @rows - builder.page = @page if @page - builder.facet = @facet if @facet - builder - end - - ## - # Merge additional, repository-specific parameters - def merge(extra_params, &block) - if extra_params - params_will_change! - @merged_params.merge!(extra_params.to_hash, &block) - end - self - end - - ## - # "Reverse merge" additional, repository-specific parameters - def reverse_merge(extra_params, &block) - if extra_params - params_will_change! - @reverse_merged_params.reverse_merge!(extra_params.to_hash, &block) - end - self - end - - delegate :[], :key?, to: :to_hash - - # a solr query method - # @return [Blacklight::Solr::Response] the solr response object - def to_hash - return @params unless params_need_update? - - @params = processed_parameters - .reverse_merge(@reverse_merged_params) - .merge(@merged_params) - .tap { clear_changes } - end - - alias_method :query, :to_hash - alias_method :to_h, :to_hash - - # The CatalogController #index action uses this. - # Solr parameters can come from a number of places. From lowest - # precedence to highest: - # 1. General defaults in blacklight config (are trumped by) - # 2. defaults for the particular search field identified by params[:search_field] (are trumped by) - # 3. certain parameters directly on input HTTP query params - # * not just any parameter is grabbed willy nilly, only certain ones are allowed by HTTP input) - # * for legacy reasons, qt in http query does not over-ride qt in search field definition default. - # 4. extra parameters passed in as argument. - # - # spellcheck.q will be supplied with the [:q] value unless specifically - # specified otherwise. - # - # Incoming parameter :f is mapped to :fq solr parameter. - # - # @return a params hash for searching solr. - def processed_parameters - request.tap do |request_parameters| - processor_chain.each do |method_name| - send(method_name, request_parameters) - end - end - end - - delegate :blacklight_config, to: :scope - - def start=(value) - params_will_change! - @start = value.to_i - end - - # @param [#to_i] value - def start(value = nil) - if value - self.start = value - return self - end - @start ||= (page - 1) * (rows || 10) - val = @start || 0 - val = 0 if @start < 0 - val - end - alias_method :padding, :start - - def page=(value) - params_will_change! - @page = value.to_i - @page = 1 if @page < 1 - end - - # @param [#to_i] value - def page(value = nil) - if value - self.page = value - return self - end - @page ||= search_state.page - end - - def rows=(value) - params_will_change! - @rows = [value, blacklight_config.max_per_page].map(&:to_i).min - end - - # @param [#to_i] value - def rows(value = nil) - if value - self.rows = value - return self - end - @rows ||= begin - # user-provided parameters should override any default row - r = search_state.per_page - # ensure we don't excede the max page size - r.nil? ? nil : [r, blacklight_config.max_per_page].map(&:to_i).min - end - end - - alias per rows - - # sets the facet that this query pertains to, for the purpose of facet pagination - def facet=(value) - params_will_change! - @facet = value - end - - # @param [Object] value - def facet(value = nil) - if value - self.facet = value - return self - end - @facet - end - - # Decode the user provided 'sort' parameter into a sort string that can be - # passed to the search. This sanitizes the input by ensuring only - # configured search values are passed through to the search. - # @return [String] the field/fields to sort by - def sort - search_state.sort_field&.sort - end - - delegate :search_field, to: :search_state - - private - - def request - Blacklight::Solr::Request.new - end - - def should_add_field_to_request? _field_name, field - field.include_in_request || (field.include_in_request.nil? && blacklight_config.add_field_configuration_to_solr_request) - end - - attr_reader :scope - - def params_will_change! - @dirty = true - end - - def params_changed? - !!@dirty - end - - def params_need_update? - params_changed? || @params.nil? - end - - def clear_changes - @dirty = false - end - end -end \ No newline at end of file