Skip to content

Commit

Permalink
Merge pull request #6727 from samvera/6724-fix-catalog-solr
Browse files Browse the repository at this point in the history
New query strategy to join FileSet solr documents
  • Loading branch information
bwatson78 authored Feb 29, 2024
2 parents 8c47b1e + c7e8ce5 commit 65e0658
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
8 changes: 7 additions & 1 deletion app/search_builders/hyrax/catalog_search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ def dismax_query

# join from file id to work relationship solrized member_ids_ssim
def join_for_works_from_files
"{!join from=#{Hyrax.config.id_field} to=member_ids_ssim v=has_model_ssim:*FileSet}#{dismax_query}"
"{!join from=#{Hyrax.config.id_field} to=member_ids_ssim}#{file_set_filter}#{dismax_query}"
end

# Query segment to filter out non-FileSet documents
# A wildcard * is used to avoid attempting to escape the :: in Hyrax::FileSet
def file_set_filter
"{!lucene q.op=AND}has_model_ssim:*FileSet"
end
end
12 changes: 8 additions & 4 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,22 @@
let(:objects) { [collection, rocks, clouds] }

it 'finds collections' do
get :index, params: { q: 'rocks' }, xhr: true
get :index, params: { q: 'rocks', search_field: 'all_fields' }, xhr: true
expect(response).to be_successful
doc_list = assigns(:response).documents
expect(doc_list.map(&:id)).to match_array [collection.id, rocks.id]
end
end

describe 'term search' do
let(:objects) { [rocks, clouds] }
# An attached fileset needs to be present in the index to trigger the
# {!join} in Hyrax::CatalogSearchBuilder#join_for_works_from_files
# and ensure it does not interfere with query results
let(:unrelated) { valkyrie_create(:monograph, :with_one_file_set, title: ['Unrelated'], read_groups: ['public']) }
let(:objects) { [rocks, clouds, unrelated] }

it 'finds works with the given search term' do
get :index, params: { q: 'rocks', owner: 'all' }
get :index, params: { q: 'rocks', search_field: 'all_fields' }
expect(response).to be_successful
expect(response).to render_template('catalog/index')
expect(assigns(:response).documents.map(&:id)).to contain_exactly(rocks.id)
Expand All @@ -74,7 +78,7 @@
let(:objects) { [rocks, clouds] }

it 'finds matching records' do
get :index, params: { q: 'full_textfull_text' }
get :index, params: { q: 'full_textfull_text', search_field: 'all_fields' }
expect(response).to be_successful
expect(response).to render_template('catalog/index')
expect(assigns(:response).documents.map(&:id)).to contain_exactly(clouds.id)
Expand Down
2 changes: 1 addition & 1 deletion spec/search_builders/hyrax/catalog_search_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
it "creates a valid solr join for works and files" do
subject
expect(solr_params[:user_query]).to eq user_query
expect(solr_params[:q]).to eq '{!lucene}_query_:"{!dismax v=$user_query}" _query_:"{!join from=id to=member_ids_ssim v=has_model_ssim:*FileSet}{!dismax v=$user_query}"'
expect(solr_params[:q]).to eq '{!lucene}_query_:"{!dismax v=$user_query}" _query_:"{!join from=id to=member_ids_ssim}{!lucene q.op=AND}has_model_ssim:*FileSet{!dismax v=$user_query}"'
end
end

Expand Down

0 comments on commit 65e0658

Please sign in to comment.