From b1696fe069674613dcdbebb867f48d25c505df2f Mon Sep 17 00:00:00 2001 From: Jane Sandberg Date: Thu, 30 Jan 2025 13:30:20 -0800 Subject: [PATCH] [Backport 8.x] Backport #3495: Ensure that facet suggestions are relevant 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 --- app/javascript/blacklight/facet_suggest.js | 2 +- spec/features/facets_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/javascript/blacklight/facet_suggest.js b/app/javascript/blacklight/facet_suggest.js index 3cbb7844c4..25d6f9c145 100644 --- a/app/javascript/blacklight/facet_suggest.js +++ b/app/javascript/blacklight/facet_suggest.js @@ -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() diff --git a/spec/features/facets_spec.rb b/spec/features/facets_spec.rb index 228d853bc8..bc55b732ba 100644 --- a/spec/features/facets_spec.rb +++ b/spec/features/facets_spec.rb @@ -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