Skip to content

Commit

Permalink
[Backport 8.x] Backport #3495: Ensure that facet suggestions are rele…
Browse files Browse the repository at this point in the history
…vant to the user's query (#3501)

* Ensure that facet suggestions are relevant to the user's query

Before this commit, the facet suggest javascript sent HTTP
requests that included only the name of the facet and the
fragment that the user entered to filter down the facets.

This commit also sends any URL params that were in the user's
original search, so that the facet suggestions are relevant
to the search, rather than being just the most popular facet
values from the entire corpus.

Closes #3494

* Put test into configured context

---------

Co-authored-by: Max Kadel <mkadel@princeton.edu>
  • Loading branch information
sandbergja and maxkadel authored Jan 30, 2025
1 parent e85656b commit b1696fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/javascript/blacklight/facet_suggest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const FacetSuggest = async (e) => {
const facetField = e.target.dataset.facetField;
if (!facetField) { return; }

const urlToFetch = `/catalog/facet_suggest/${facetField}/${queryFragment}`
const urlToFetch = `/catalog/facet_suggest/${facetField}/${queryFragment}${window.location.search}`
const response = await fetch(urlToFetch);
if (response.ok) {
const blob = await response.blob()
Expand Down
8 changes: 8 additions & 0 deletions spec/features/facets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@
expect(page).to have_link 'Old age'
expect(page).to have_css 'a.facet-select', count: 2
end

it 'shows the user facet suggestions that are relevant to their q param', :js do
visit '/catalog/facet/subject_ssim?q=tibet&search_field=all_fields'
fill_in 'facet_suggest_subject_ssim', with: 'la'

expect(page).to have_link 'Tibetan language'
expect(page).to have_css 'a.facet-select', count: 1
end
end
end
end

0 comments on commit b1696fe

Please sign in to comment.