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

🐛 Fix additional query terms removal #241

Merged
merged 2 commits into from
May 17, 2023
Merged
Changes from 1 commit
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
13 changes: 7 additions & 6 deletions lib/iiif_print/blacklight_iiif_search/annotation_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def coordinates
return default_coords if query.blank?
coords_json = fetch_and_parse_coords
return default_coords unless coords_json && coords_json['coords']
query.gsub!(additional_query_terms, '')
query_terms = query.split(' ').map(&:downcase)
sanitized_query = query.match(additional_query_terms_regex)[1].strip
query_terms = sanitized_query.split(' ').map(&:downcase)
matches = coords_json['coords'].select do |k, _v|
k.downcase =~ /(#{query_terms.join('|')})/
end
Expand Down Expand Up @@ -88,10 +88,11 @@ def file_set_id
# query. This resulted in the query split here returning more than the actual query term.
#
# @see IiifPrint::IiifSearchDecorator#solr_params
# @return [String] Returns a string containing additional query terms based on the parent document's id.
def additional_query_terms
parent_id = document['is_page_of_ssim'].first
" AND (is_page_of_ssim:\"#{parent_id}\" OR id:\"#{parent_id}\")"
# @return [Regexp] A regular expression to find the last AND and everything after it
# @example
# 'foo AND (is_page_of_ssim:\"123123\" OR id:\"123123\")' #=> 'foo'
def additional_query_terms_regex
/(.*)(?= AND (\(.+\)|\w+)$)/
end
end
end
Expand Down