Skip to content

Commit

Permalink
New query strategy to join FileSet solr documents
Browse files Browse the repository at this point in the history
Fixes #6724
The previous attempt to join FileSet documents in the catalog search query failed to actually filter results. Due to a bad
or outdated test, this was not detected when running specs.

Updates the "term search" catalog controller spec to use the `all_fields` search. Prior to this change the spec did not follow
a code path to `join_for_works_from_files`. `all_fields` appears to be set for all queries originating from the hyrax web
interface (others are defined but unused in an unmodified CatalogController), so other specs that specify a `q` param
have had `all_fields` added.

Furthermore, the {!join} query did not have any effect when no FileSet documents are present in the solr index. Without a
FileSet in the mix, bad query results caused by the join were not detected by the spec.
  • Loading branch information
dlpierce committed Feb 29, 2024
1 parent 8c47b1e commit c7e8ce5
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 c7e8ce5

Please sign in to comment.