Skip to content

Commit

Permalink
Truncate call number at 50 terms
Browse files Browse the repository at this point in the history
  • Loading branch information
kazymovae authored Aug 3, 2023
1 parent 627e906 commit ff92e87
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/argon_call_number_search.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
6 changes: 6 additions & 0 deletions lib/argon_call_number_search/search_builder_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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' &&
Expand Down
2 changes: 1 addition & 1 deletion lib/argon_call_number_search/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ArgonCallNumberSearch
VERSION = '0.1.4'
VERSION = '0.1.5'
end
14 changes: 14 additions & 0 deletions spec/argon_call_number_search/search_builder_behavior_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ff92e87

Please sign in to comment.