From ff92e87a633a7922473b61422c7c9878bb577b46 Mon Sep 17 00:00:00 2001 From: kazymovae Date: Thu, 3 Aug 2023 15:23:40 -0400 Subject: [PATCH] Truncate call number at 50 terms --- lib/argon_call_number_search.rb | 1 + .../search_builder_behavior.rb | 6 ++++++ lib/argon_call_number_search/version.rb | 2 +- .../search_builder_behavior_spec.rb | 14 ++++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/argon_call_number_search.rb b/lib/argon_call_number_search.rb index e56db7c..bf2791b 100644 --- a/lib/argon_call_number_search.rb +++ b/lib/argon_call_number_search.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'argon_call_number_search/version' +require 'lcsort' module ArgonCallNumberSearch autoload :Configurable, 'argon_call_number_search/configurable' diff --git a/lib/argon_call_number_search/search_builder_behavior.rb b/lib/argon_call_number_search/search_builder_behavior.rb index 9ee6564..d875d55 100644 --- a/lib/argon_call_number_search/search_builder_behavior.rb +++ b/lib/argon_call_number_search/search_builder_behavior.rb @@ -11,6 +11,7 @@ def add_call_number_query_to_solr(solr_parameters) solr_parameters[:q].gsub("_query_:\"{!edismax}#{call_number_query_str}\"", "(#{call_number_queries})") else + truncate_call_number if TrlnArgon::Engine.configuration.enable_query_truncation.present? call_number_queries end end @@ -21,6 +22,11 @@ def call_number_query_present? default_call_num_search? || advanced_call_num_search? end + def truncate_call_number + blacklight_params[:q] = blacklight_params[:q].truncate_words(50, separator: /\W+/, omission: '') unless + blacklight_params[:q].split(/\b/).select { |x| x.match?(/\w/) }.length <= 50 + end + def default_call_num_search? blacklight_params.key?(:search_field) && blacklight_params[:search_field] == 'call_number' && diff --git a/lib/argon_call_number_search/version.rb b/lib/argon_call_number_search/version.rb index 7cecdc9..ed1555e 100644 --- a/lib/argon_call_number_search/version.rb +++ b/lib/argon_call_number_search/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module ArgonCallNumberSearch - VERSION = '0.1.4' + VERSION = '0.1.5' end diff --git a/spec/argon_call_number_search/search_builder_behavior_spec.rb b/spec/argon_call_number_search/search_builder_behavior_spec.rb index 9406406..4622bf9 100644 --- a/spec/argon_call_number_search/search_builder_behavior_spec.rb +++ b/spec/argon_call_number_search/search_builder_behavior_spec.rb @@ -12,6 +12,20 @@ module Fields end end +module TrlnArgon + module Engine + class Configuration + def enable_query_truncation + true + end + end + + def self.configuration + Configuration.new + end + end +end + class SearchBuilderTestClass include ArgonCallNumberSearch::SearchBuilderBehavior include TrlnArgon::Fields