Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ def query_primo(per_page, offset)
end

def execute_geospatial_query(query)
query = query.except('queryMode')
query = query.except('queryMode', 'semanticDropBoostThreshold', 'semanticMustBoostThreshold',
'semanticShortQueryMaxTokens')

if query['geobox'] == 'true' && query[:geodistance] == 'true'
TimdexBase::Client.query(TimdexSearch::AllQuery, variables: query)
Expand Down
3 changes: 2 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def index_page_title
def results_page_title(query, character_limit = 50)
return index_page_title unless query.present?

ignored_terms = %i[page advanced geobox geodistance booleanType tab queryMode]
ignored_terms = %i[page advanced geobox geodistance booleanType tab queryMode semanticDropBoostThreshold
semanticMustBoostThreshold semanticShortQueryMaxTokens]
terms = query.reject { |term| ignored_terms.include? term }.values.join(' ')
terms = "#{terms.first(character_limit)}..." if terms.length > character_limit
"#{terms} | #{index_page_title}"
Expand Down
3 changes: 2 additions & 1 deletion app/models/enhancer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class Enhancer
attr_accessor :enhanced_query

QUERY_PARAMS = %i[q citation contentType contributors fundingInformation identifiers locations subjects title queryMode].freeze
QUERY_PARAMS = %i[q citation contentType contributors fundingInformation identifiers locations subjects title
queryMode semanticDropBoostThreshold semanticMustBoostThreshold semanticShortQueryMaxTokens].freeze
FILTER_PARAMS = %i[accessToFilesFilter contentTypeFilter contributorsFilter formatFilter languagesFilter
literaryFormFilter placesFilter sourceFilter subjectsFilter].freeze
GEO_PARAMS = %i[geoboxMinLongitude geoboxMinLatitude geoboxMaxLongitude geoboxMaxLatitude geodistanceLatitude
Expand Down
8 changes: 8 additions & 0 deletions app/models/query_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class QueryBuilder
GEO_PARAMS = %w[geoboxMinLongitude geoboxMinLatitude geoboxMaxLongitude geoboxMaxLatitude geodistanceLatitude
geodistanceLongitude geodistanceDistance].freeze
VALID_QUERY_MODES = %w[keyword semantic hybrid].freeze
TOKENIZATION_PARAMS = %w[semanticDropBoostThreshold semanticMustBoostThreshold semanticShortQueryMaxTokens].freeze

def initialize(enhanced_query)
@query = {}
Expand All @@ -22,6 +23,7 @@ def initialize(enhanced_query)
extract_geosearch(enhanced_query)
extract_filters(enhanced_query)
evaluate_query_mode(enhanced_query)
extract_tokenization_params(enhanced_query)
@query['index'] = ENV.fetch('TIMDEX_INDEX', nil)
@query['booleanType'] = enhanced_query[:booleanType]
@query.compact!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 2 issues:

1. Assignment Branch Condition size for initialize is too high. [<7, 20, 5> 21.77/17] [rubocop:Metrics/AbcSize]


2. Method has too many lines. [15/10] [rubocop:Metrics/MethodLength]

Expand Down Expand Up @@ -59,6 +61,12 @@ def extract_filters(enhanced_query)
end
end

def extract_tokenization_params(enhanced_query)
TOKENIZATION_PARAMS.each do |tp|
@query[tp] = enhanced_query[tp.to_sym]&.strip.to_f if enhanced_query[tp.to_sym].present?
end
end

# The GraphQL API requires that lat/long in geospatial fields be floats
def coerce_to_float?(geo_param)
geo_param.to_s.include?('Longitude') || geo_param.to_s.include?('Latitude')
Expand Down