diff --git a/app/search_builders/hyrax/catalog_search_builder.rb b/app/search_builders/hyrax/catalog_search_builder.rb index 9aa86f4337..e221706b9f 100644 --- a/app/search_builders/hyrax/catalog_search_builder.rb +++ b/app/search_builders/hyrax/catalog_search_builder.rb @@ -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 diff --git a/spec/controllers/catalog_controller_spec.rb b/spec/controllers/catalog_controller_spec.rb index e59a4e86c9..c9cdcd71a6 100644 --- a/spec/controllers/catalog_controller_spec.rb +++ b/spec/controllers/catalog_controller_spec.rb @@ -38,7 +38,7 @@ 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] @@ -46,10 +46,14 @@ 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) @@ -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) diff --git a/spec/search_builders/hyrax/catalog_search_builder_spec.rb b/spec/search_builders/hyrax/catalog_search_builder_spec.rb index ec6f9717c9..16c8b161cc 100644 --- a/spec/search_builders/hyrax/catalog_search_builder_spec.rb +++ b/spec/search_builders/hyrax/catalog_search_builder_spec.rb @@ -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