Show search source badges only with show_sources param

The badges are a debugging aid - render them only when explicitly
requested via ?show_sources=1 instead of on every search.
This commit is contained in:
Christoph Haas 2026-08-23 10:49:32 +02:00
parent 323b7004ed
commit 4c736096ae
3 changed files with 19 additions and 4 deletions

View file

@ -1,4 +1,10 @@
module PackagesHelper
# Search result origin badges are only shown when explicitly
# requested via ?show_sources=1
def search_sources_visible?
params[:show_sources].present?
end
# Human readable label for the search strategy that put a package
# into the search results (see PackagesController#search_packages)
def search_source_label(source)

View file

@ -24,7 +24,7 @@
= pkg.name
.text
= pkg.description
- if @search_sources[pkg.id]
- if search_sources_visible? && @search_sources[pkg.id]
.text.search-source
span.label.secondary = search_source_label(@search_sources[pkg.id])
- elsif @view_style==:list
@ -40,7 +40,7 @@
a href=package_path(name: pkg.name)
=pkg.name
p =pkg.description
- if @search_sources[pkg.id]
- if search_sources_visible? && @search_sources[pkg.id]
p
span.label.secondary = search_source_label(@search_sources[pkg.id])
.listview.longdescription

View file

@ -25,7 +25,7 @@ class PackagesControllerTest < ActionController::TestCase
test 'exact package name search wins without calling the vector service' do
with_stubbed_method(Package, :nearest_to_text,
->(_text) { flunk 'should not call vector search' }) do
get :grid, params: { search: 'vim' }
get :grid, params: { search: 'vim', show_sources: '1' }
assert_response :success
assert_select 'div', 'vim'
assert_equal({ packages(:vim).id => :exact }, assigns(:search_sources))
@ -75,7 +75,7 @@ class PackagesControllerTest < ActionController::TestCase
# "fire fox" should find "firefox" via name substring matching
with_stubbed_method(Package, :nearest_to_text,
->(_text, **_opts) { Package.none }) do
get :grid, params: { search: 'fire fox' }
get :grid, params: { search: 'fire fox', show_sources: '1' }
assert_response :success
assert_select 'div', text: 'firefox', count: 1
assert_equal({ packages(:firefox).id => :name_contains },
@ -84,6 +84,15 @@ class PackagesControllerTest < ActionController::TestCase
end
end
test 'search source badges stay hidden without show_sources param' do
with_stubbed_method(Package, :nearest_to_text,
->(_text, **_opts) { Package.none }) do
get :grid, params: { search: 'fire fox' }
assert_response :success
assert_select '.search-source', count: 0
end
end
test 'details shows semantically related packages' do
packages(:vim).update_column(:embedding, Array.new(384, 0.25))
packages(:firefox).update_column(:embedding, Array.new(384, 0.75))