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

Show Hyrax::PcdmCollection resources in search results #5515

Merged
merged 3 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,4 @@
<div class="search-results-title-row">
<h3 class="search-result-title"><%= link_to document.title_or_label, [hyrax, document] %></h3>
<%= Hyrax::CollectionPresenter.new(document, current_ability).collection_type_badge %>
</div>
2 changes: 2 additions & 0 deletions config/metadata/basic_metadata.yaml
Expand Up @@ -50,6 +50,8 @@ attributes:
multiple: true
form:
primary: false
index_keys:
- "description_tesim"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- "description_tesim"
- "description_sim"
- "description_tesim"

Should this have the string version as well? It is pretty common to include both, but the string stores as the exact string typically used for exact matching. I don't imagine that someone would be looking for an exact match for the entire description.

String stores a word/sentence as an exact string without performing tokenization etc. Commonly useful for storing exact matches, e.g, for facetting.

Text typically performs tokenization, and secondary processing (such as lower-casing etc.). Useful for all scenarios when we want to match part of a sentence.

Copy link
Member Author

Choose a reason for hiding this comment

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

From what I can tell description was only every indexed as _tesim. (https://github.com/samvera/hyrax/blob/main/app/indexers/hyrax/basic_metadata_indexer.rb#L7)

identifier:
type: string
multiple: true
Expand Down
2 changes: 2 additions & 0 deletions lib/hyrax/collection_name.rb
Expand Up @@ -14,6 +14,8 @@ def initialize(klass, namespace = nil, name = nil)
@plural = 'collections'
@route_key = 'collections'
@singular_route_key = 'collection'
@collection = 'collections'
@element = 'collection'
end
end
end
63 changes: 63 additions & 0 deletions spec/features/search_spec_valkyrie.rb
@@ -0,0 +1,63 @@
# frozen_string_literal: true
RSpec.describe 'searching', index_adapter: :solr_index do
let(:user) { create :user }
Copy link
Contributor

Choose a reason for hiding this comment

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

First fully valkyrie feature test. 💯

let(:subject_value) { 'mustache' }
let!(:work) do
FactoryBot.valkyrie_create(:monograph, :public,
title: ["Toothbrush"],
keyword: [subject_value, 'taco'])
end

let!(:collection) do
FactoryBot.valkyrie_create(:hyrax_collection, :public, title: ['collection title abc'], description: [subject_value], members: [work])
end

before { allow(Hyrax.config).to receive(:collection_model).and_return('Hyrax::PcdmCollection') }

context "as a public user", :clean_repo do
it "using the gallery view" do
visit '/'
fill_in "search-field-header", with: "Toothbrush"
click_button "search-submit-header"
expect(page).to have_content "1 entry found"
within "#search-results" do
expect(page).to have_content "Toothbrush"
end

click_link "Gallery"
expect(page).to have_content "Filtering by: Toothbrush"
within "#documents" do
expect(page).to have_content "Toothbrush"
end
end

it "only searches all and does not display search options for dashboard files" do
visit '/'

# it "does not display search options for dashboard files" do
# This section was tested on its own, and required a full setup.
within(".input-group-btn") do
expect(page).not_to have_content("All")
expect(page).not_to have_content("My Works")
expect(page).not_to have_content("My Collections")
expect(page).not_to have_content("My Shares")
end

expect(page).not_to have_css("a[data-search-label*=All]", visible: false)
expect(page).not_to have_css("a[data-search-label*='My Works']", visible: false)
expect(page).not_to have_css("a[data-search-label*='My Collections']", visible: false)
expect(page).not_to have_css("a[data-search-label*='My Highlights']", visible: false)
expect(page).not_to have_css("a[data-search-label*='My Shares']", visible: false)

fill_in "search-field-header", with: subject_value
click_button("Go")
expect(page).to have_content('Search Results')
expect(page).to have_content "Toothbrush"
expect(page).to have_content('collection title abc')
expect(page).to have_selector("//img")

expect(page.body).to include "<span itemprop=\"keywords\"><a href=\"/catalog?f%5Bkeyword_sim%5D%5B%5D=taco&amp;locale=en\">taco</a></span>"
expect(page.body).to include "<span itemprop=\"keywords\"><a href=\"/catalog?f%5Bkeyword_sim%5D%5B%5D=mustache&amp;locale=en\">mustache</a></span>"
end
end
end
8 changes: 8 additions & 0 deletions spec/models/concerns/hyrax/solr_document_behavior_spec.rb
Expand Up @@ -35,6 +35,14 @@
expect(solr_document.to_model.to_partial_path).to eq 'hyrax/monographs/monograph'
end
end

context 'with Hyrax::PcdmCollection' do
let(:solr_hash) { { 'has_model_ssim' => 'Hyrax::PcdmCollection' } }

it 'resolves to collection path' do
expect(solr_document.to_model.to_partial_path).to eq 'hyrax/collections/collection'
end
end
end

describe '#hydra_model' do
Expand Down
8 changes: 8 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -303,6 +303,14 @@ def clean_active_fedora_repository
Valkyrie::IndexingAdapter.find(adapter_name).wipe!
end

# Configure blacklight to use the valkyrie solr index
config.around(:example, index_adapter: :solr_index) do |example|
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice to have this in place. It will help with future tests that need the valkyrie core to be primary.

blacklight_connection_url = CatalogController.blacklight_config.connection_config[:url]
CatalogController.blacklight_config.connection_config[:url] = Valkyrie::IndexingAdapter.find(:solr_index).connection.options[:url]
example.run
CatalogController.blacklight_config.connection_config[:url] = blacklight_connection_url
end

config.before(:example, :valkyrie_adapter) do |example|
adapter_name = example.metadata[:valkyrie_adapter]

Expand Down