-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #322 from pulibrary/issues-218-jrgriffiniii-search…
…-quotes-fix Ensuring that quotes are properly escaped within the dismax parameters for joining on child resource Documents
- Loading branch information
Showing
4 changed files
with
134 additions
and
3 deletions.
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 |
---|---|---|
@@ -1,15 +1,24 @@ | ||
# Class for extending the default Blacklight builder for Solr queries | ||
# @see https://github.com/projectblacklight/blacklight/wiki/Extending-or-Modifying-Blacklight-Search-Behavior | ||
class SearchBuilder < Blacklight::SearchBuilder | ||
include Blacklight::Solr::SearchBuilderBehavior | ||
include Spotlight::AccessControlsEnforcementSearchBuilder | ||
|
||
self.default_processor_chain += [:hide_parented_resources, :join_from_parent] | ||
# Names for methods invoked when the Solr query is being built | ||
self.default_processor_chain += %i(hide_parented_resources join_from_parent) | ||
|
||
# Modifies the filter query in the Solr parameters to hide collections from being returned for all items in search results | ||
# @see https://lucene.apache.org/solr/guide/6_6/common-query-parameters.html#CommonQueryParameters-Thefq_FilterQuery_Parameter | ||
# @param solr_params [Blacklight::Solr::Request] the Solr query parameters being modified | ||
def hide_parented_resources(solr_params) | ||
solr_params[:fq] ||= [] | ||
solr_params[:fq] << "!#{Spotlight::Resources::Iiif::Engine.config.collection_id_field}:['' TO *]" | ||
end | ||
|
||
# Modifies the Solr query in order to retrieve child resources for all collections within search results | ||
# @param solr_params [Blacklight::Solr::Request] the Solr query parameters being modified | ||
def join_from_parent(solr_params) | ||
solr_params[:q] = JoinChildrenQuery.new(solr_params[:q]).to_s | ||
parent_query = solr_params[:q] | ||
solr_params[:q] = JoinChildrenQuery.new(parent_query).to_s | ||
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
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,89 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.feature 'Catalog', type: :feature do | ||
let(:exhibit) { FactoryBot.create(:exhibit) } | ||
let(:id) { 'd279a557a62937a8895eebbca2d4744c' } | ||
let(:title) { 'Panoramic alphabet of peace' } | ||
let(:rights) { 'http://rightsstatements.org/vocab/NKC/1.0/' } | ||
let(:document) do | ||
SolrDocument.new( | ||
id: id, | ||
readonly_title_tesim: [ | ||
title | ||
], | ||
'exhibit_abc_books_readonly_edm-rights_ssim': [ | ||
rights | ||
], | ||
'readonly_edm-rights_tesim': [ | ||
rights | ||
], | ||
exhibit_abc_books_readonly_license_ssim: [ | ||
rights | ||
], | ||
readonly_license_tesim: [ | ||
rights | ||
], | ||
access_identifier_ssim: [ | ||
"1r66j4408" | ||
], | ||
full_title_tesim: [ | ||
title | ||
], | ||
readonly_title_ssim: [ | ||
title | ||
], | ||
'readonly_title-sort_ssim': [ | ||
title | ||
], | ||
'readonly_edm-rights_ssim': [ | ||
rights | ||
], | ||
readonly_license_ssim: [ | ||
rights | ||
], | ||
_version_: 159, | ||
timestamp: "2018-02-19T22:19:52.244Z" | ||
) | ||
end | ||
|
||
context 'logged in as a site admin.' do | ||
let(:user) { FactoryBot.create(:site_admin, exhibit: exhibit) } | ||
|
||
before do | ||
sign_in user | ||
document.make_public! exhibit | ||
document.reindex | ||
Blacklight.default_index.connection.commit | ||
end | ||
|
||
scenario 'user searches for a collections with a keyword' do | ||
visit spotlight.search_exhibit_catalog_path(exhibit, search_field: 'all_fields', q: id) | ||
expect(page).to have_css '#documents .document h3.index_title', text: id | ||
end | ||
|
||
context 'when the document has metadata attributes with quotes' do | ||
before do | ||
exhibit2 = Spotlight::Exhibit.create title: 'Exhibit B', published: true | ||
document2 = SolrDocument.new(id: 'd279a557a62937a8895eebbca2d4744c', exhibit: exhibit) | ||
Spotlight::SolrDocumentSidecar.create!( | ||
document: document2, exhibit: exhibit2, | ||
data: { 'full_title_tesim' => ['"title1"'] } | ||
) | ||
document2.make_private!(exhibit2) | ||
document2.save | ||
Blacklight.default_index.connection.commit | ||
end | ||
|
||
scenario 'user searches for a collections with a keyword in quotes' do | ||
visit spotlight.search_exhibit_catalog_path(exhibit, search_field: 'all_fields', q: '"title1"') | ||
expect(page).to have_css '#documents .document h3.index_title', text: '"title1"' | ||
end | ||
end | ||
|
||
scenario 'user browses all collections' do | ||
visit spotlight.search_exhibit_catalog_path(exhibit, search_field: 'all_fields', q: '') | ||
expect(page).to have_link 'Home', href: '/exhibit-title-2' | ||
expect(page).to have_css '#documents .document h3.index_title', text: id | ||
end | ||
end | ||
end |