Skip to content

Commit

Permalink
Enable facet limits
Browse files Browse the repository at this point in the history
  • Loading branch information
eliotjordan committed Nov 27, 2018
1 parent 99da39b commit 38307aa
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
14 changes: 11 additions & 3 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def search_across_settings
return if current_exhibit
blacklight_config.add_index_field 'readonly_creator_ssim', label: 'Creator'

blacklight_config.add_facet_field 'readonly_language_ssim', label: 'Language'
blacklight_config.add_facet_field 'readonly_subject_ssim', label: 'Subject'
blacklight_config.add_facet_field 'readonly_language_ssim', label: 'Language', limit: 10
blacklight_config.add_facet_field 'readonly_subject_ssim', label: 'Subject', limit: 10
unique_custom_fields.each do |field|
blacklight_config.add_show_field field.field, label: field.configuration["label"]
end
Expand Down Expand Up @@ -58,7 +58,7 @@ def unique_custom_fields
config.add_sort_field 'sort_author', sort: 'sort_author_ssi asc, sort_title_ssi asc', label: 'Author'

config.add_facet_field 'spotlight_resource_type_ssim'
config.add_facet_field 'readonly_collections_ssim', label: 'Collections'
config.add_facet_field 'readonly_collections_ssim', label: 'Collections', limit: 10
config.add_index_field 'readonly_collections_ssim', label: 'Collections'
config.index.thumbnail_field = 'thumbnail_ssim'

Expand All @@ -73,6 +73,14 @@ def unique_custom_fields
config.http_method = :post
end

# Overrides the spotlight search_facet_url method to use
# facet_catalog_url named route instead of catalog_facet_url.
# https://github.com/projectblacklight/spotlight/blob/v1.4.1/app/controllers/concerns/spotlight/controller.rb#L63
def search_facet_url(*args)
return super if current_exhibit
main_app.facet_catalog_url(*args)
end

# get a single document from the index
# to add responses for formats other than html or json see _Blacklight::Document::Export_
def show
Expand Down
40 changes: 38 additions & 2 deletions spec/features/catalog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
sign_in user
document.make_public! exhibit
document.reindex
Blacklight.default_index.connection.commit
index.commit
end

scenario 'user searches for a collections with a keyword' do
Expand All @@ -71,7 +71,7 @@
)
document2.make_private!(exhibit2)
document2.save
Blacklight.default_index.connection.commit
index.commit
end

scenario 'user searches for a collections with a keyword in quotes' do
Expand All @@ -86,4 +86,40 @@
expect(page).to have_css '#documents .document h3.index_title', text: id
end
end

context 'when searching across a catalog with many languages' do
let(:languages) {
[
'Language 1',
'Language 2',
'Language 3',
'Language 4',
'Language 5',
'Language 6',
'Language 7',
'Language 8',
'Language 9',
'Language 10',
'Language 11'
]
}

before do
index.add(id: '1',
full_title_ssim: ['Test Item'],
readonly_title_ssim: ['Test Item'],
spotlight_resource_type_ssim: ['iiif_resources'],
readonly_language_ssim: languages)
index.commit
end

it 'renders the languages facet with a more facets link' do
visit main_app.search_catalog_path(q: '')
expect(page).to have_link("more", href: '/catalog/facet/readonly_language_ssim')
end
end

def index
Blacklight.default_index.connection
end
end

0 comments on commit 38307aa

Please sign in to comment.