Skip to content

Commit 65e0658

Browse files
authored
Merge pull request #6727 from samvera/6724-fix-catalog-solr
New query strategy to join FileSet solr documents
2 parents 8c47b1e + c7e8ce5 commit 65e0658

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

app/search_builders/hyrax/catalog_search_builder.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ def dismax_query
8080

8181
# join from file id to work relationship solrized member_ids_ssim
8282
def join_for_works_from_files
83-
"{!join from=#{Hyrax.config.id_field} to=member_ids_ssim v=has_model_ssim:*FileSet}#{dismax_query}"
83+
"{!join from=#{Hyrax.config.id_field} to=member_ids_ssim}#{file_set_filter}#{dismax_query}"
84+
end
85+
86+
# Query segment to filter out non-FileSet documents
87+
# A wildcard * is used to avoid attempting to escape the :: in Hyrax::FileSet
88+
def file_set_filter
89+
"{!lucene q.op=AND}has_model_ssim:*FileSet"
8490
end
8591
end

spec/controllers/catalog_controller_spec.rb

+8-4
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,22 @@
3838
let(:objects) { [collection, rocks, clouds] }
3939

4040
it 'finds collections' do
41-
get :index, params: { q: 'rocks' }, xhr: true
41+
get :index, params: { q: 'rocks', search_field: 'all_fields' }, xhr: true
4242
expect(response).to be_successful
4343
doc_list = assigns(:response).documents
4444
expect(doc_list.map(&:id)).to match_array [collection.id, rocks.id]
4545
end
4646
end
4747

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

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

7680
it 'finds matching records' do
77-
get :index, params: { q: 'full_textfull_text' }
81+
get :index, params: { q: 'full_textfull_text', search_field: 'all_fields' }
7882
expect(response).to be_successful
7983
expect(response).to render_template('catalog/index')
8084
expect(assigns(:response).documents.map(&:id)).to contain_exactly(clouds.id)

spec/search_builders/hyrax/catalog_search_builder_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
it "creates a valid solr join for works and files" do
1414
subject
1515
expect(solr_params[:user_query]).to eq user_query
16-
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}"'
16+
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}"'
1717
end
1818
end
1919

0 commit comments

Comments
 (0)