-
Notifications
You must be signed in to change notification settings - Fork 1
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
Search parent metadata instead of no match found #234
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
# OVERRIDE: Blacklight IIIF Search v1.0.0 | ||
# IiifSearchDecorator module extends the functionality of the BlacklightIiifSearch::IiifSearch class | ||
# by overriding the solr_params method to modify the search query to include the parent's metadata. | ||
module IiifPrint | ||
module IiifSearchDecorator | ||
## | ||
# Overrides the solr_params method from BlacklightIiifSearch::IiifSearch to modify the search query. | ||
# The method adds an additional filter to the query to include either the object_relation_field OR the | ||
# parent document's id and removes the :f parameter from the query. | ||
# :object_relation_field refers to the CatalogController's configuration which is typically set to | ||
# 'is_page_of_ssim' in the host application which only searches child works by default. | ||
# | ||
# config.iiif_search = { | ||
# full_text_field: 'all_text_tsimv', | ||
# object_relation_field: 'is_page_of_ssim', | ||
# supported_params: %w[q page], | ||
# autocomplete_handler: 'iiif_suggest', | ||
# suggester_name: 'iiifSuggester' | ||
# } | ||
# | ||
# @return [Hash] A hash containing the modified Solr search parameters | ||
# | ||
def solr_params | ||
return { q: 'nil:nil' } unless q | ||
|
||
{ | ||
q: "#{q} AND (#{iiif_config[:object_relation_field]}:\"#{parent_document.id}\" OR id:\"#{parent_document.id}\")", | ||
rows: rows, | ||
page: page | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe IiifPrint::IiifSearchDecorator do | ||
let(:iiif_config) { { object_relation_field: 'is_page_of_ssim' } } | ||
let(:parent_document) { double(SolrDocument, id: 'abc123') } | ||
let(:iiif_search) { BlacklightIiifSearch::IiifSearch.new(params, iiif_config, parent_document) } | ||
|
||
describe '#solr_params' do | ||
subject { iiif_search.solr_params } | ||
|
||
context 'when q is nil' do | ||
let(:params) { { q: nil } } | ||
|
||
it 'returns nil:nil' do | ||
expect(subject).to eq({ q: 'nil:nil' }) | ||
end | ||
end | ||
|
||
context 'when q is not nil' do | ||
let(:params) { { q: 'catscan' } } | ||
|
||
it 'returns a query with the search term and filters for child or parent id' do | ||
expect(subject).to eq({ q: "catscan AND (is_page_of_ssim:\"abc123\" OR id:\"abc123\")", rows: 50, page: nil }) | ||
end | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if we don't have a
parent_document
? What happens ifiiif_config
doesn't have the key:object_relation_field
or ifiiif_config[:object_relation_field]
isnil
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like not having a
parent_document
should never happen because the work itself comes in as its own parent even when looking at a work that has no parent/child relationships.if
iiif_config
lost its:object_relation_field
or ifiiif_config[:object_relation_field]
isnil
, then most likely someone altered the code from the generator. I think maybe we need to raise an error at that point.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried commenting out the
:object_relation_field
and it does not cause a crash. This however seems like a programmer if the:object_relation_field
is missing (since it comes in through the generator). I'm rethinking if we need to raise an error just to account for this scenario.