internal/frontend: fix filter when not in first word
Previously, the search filter # only defaulted to symbol search mode
when it was on the first word of a search. It now works regardless of
which word has the filter.
For golang/go#44142
Change-Id: Id32010f9071c7f5db82127a490372fdf89548fe5
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/355229
Trust: Julie Qiu <julie@golang.org>
Run-TryBot: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
diff --git a/internal/frontend/search.go b/internal/frontend/search.go
index 2cf6e20..c43da71 100644
--- a/internal/frontend/search.go
+++ b/internal/frontend/search.go
@@ -326,8 +326,8 @@
if !experiment.IsActive(r.Context(), internal.ExperimentSymbolSearch) {
return searchModePackage
}
- q := rawSearchQuery(r)
- if strings.HasPrefix(q, symbolSearchFilter) {
+ q, filters := searchQueryAndFilters(r)
+ if len(filters) > 0 {
return searchModeSymbol
}
mode := rawSearchMode(r)
diff --git a/tests/search/scripts/default.txt b/tests/search/scripts/default.txt
index 33a9d3f..ba3b003 100644
--- a/tests/search/scripts/default.txt
+++ b/tests/search/scripts/default.txt
@@ -22,6 +22,10 @@
[symbol] #big.Float
Float math/big
+keyboard shorcut "#" in second word
+[symbol] big #Float
+Float math/big
+
keyboard shorcut "#"
[symbol] #foo
Foo gopkg.in/foo.v1