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:
parent
323b7004ed
commit
4c736096ae
3 changed files with 19 additions and 4 deletions
|
|
@ -1,4 +1,10 @@
|
||||||
module PackagesHelper
|
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
|
# Human readable label for the search strategy that put a package
|
||||||
# into the search results (see PackagesController#search_packages)
|
# into the search results (see PackagesController#search_packages)
|
||||||
def search_source_label(source)
|
def search_source_label(source)
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
= pkg.name
|
= pkg.name
|
||||||
.text
|
.text
|
||||||
= pkg.description
|
= pkg.description
|
||||||
- if @search_sources[pkg.id]
|
- if search_sources_visible? && @search_sources[pkg.id]
|
||||||
.text.search-source
|
.text.search-source
|
||||||
span.label.secondary = search_source_label(@search_sources[pkg.id])
|
span.label.secondary = search_source_label(@search_sources[pkg.id])
|
||||||
- elsif @view_style==:list
|
- elsif @view_style==:list
|
||||||
|
|
@ -40,7 +40,7 @@
|
||||||
a href=package_path(name: pkg.name)
|
a href=package_path(name: pkg.name)
|
||||||
=pkg.name
|
=pkg.name
|
||||||
p =pkg.description
|
p =pkg.description
|
||||||
- if @search_sources[pkg.id]
|
- if search_sources_visible? && @search_sources[pkg.id]
|
||||||
p
|
p
|
||||||
span.label.secondary = search_source_label(@search_sources[pkg.id])
|
span.label.secondary = search_source_label(@search_sources[pkg.id])
|
||||||
.listview.longdescription
|
.listview.longdescription
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ class PackagesControllerTest < ActionController::TestCase
|
||||||
test 'exact package name search wins without calling the vector service' do
|
test 'exact package name search wins without calling the vector service' do
|
||||||
with_stubbed_method(Package, :nearest_to_text,
|
with_stubbed_method(Package, :nearest_to_text,
|
||||||
->(_text) { flunk 'should not call vector search' }) do
|
->(_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_response :success
|
||||||
assert_select 'div', 'vim'
|
assert_select 'div', 'vim'
|
||||||
assert_equal({ packages(:vim).id => :exact }, assigns(:search_sources))
|
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
|
# "fire fox" should find "firefox" via name substring matching
|
||||||
with_stubbed_method(Package, :nearest_to_text,
|
with_stubbed_method(Package, :nearest_to_text,
|
||||||
->(_text, **_opts) { Package.none }) do
|
->(_text, **_opts) { Package.none }) do
|
||||||
get :grid, params: { search: 'fire fox' }
|
get :grid, params: { search: 'fire fox', show_sources: '1' }
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_select 'div', text: 'firefox', count: 1
|
assert_select 'div', text: 'firefox', count: 1
|
||||||
assert_equal({ packages(:firefox).id => :name_contains },
|
assert_equal({ packages(:firefox).id => :name_contains },
|
||||||
|
|
@ -84,6 +84,15 @@ class PackagesControllerTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
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
|
test 'details shows semantically related packages' do
|
||||||
packages(:vim).update_column(:embedding, Array.new(384, 0.25))
|
packages(:vim).update_column(:embedding, Array.new(384, 0.25))
|
||||||
packages(:firefox).update_column(:embedding, Array.new(384, 0.75))
|
packages(:firefox).update_column(:embedding, Array.new(384, 0.75))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue