aboutsummaryrefslogtreecommitdiffstats
path: root/internal/web/search.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/web/search.go')
-rw-r--r--internal/web/search.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/internal/web/search.go b/internal/web/search.go
index 9af980d..e0c3533 100644
--- a/internal/web/search.go
+++ b/internal/web/search.go
@@ -5,6 +5,7 @@ import (
"html/template"
"regexp"
"strings"
+ "time"
"unicode/utf8"
"github.com/microcosm-cc/bluemonday"
@@ -14,8 +15,10 @@ import (
const (
searchPerPage = 20
- maxSearchRunes = 100 // longer queries are cut; nobody types more on purpose
- snippetContext = 80 // runes kept on each side of the match
+ maxSearchRunes = 100 // longer queries are cut; nobody types more on purpose
+ maxSearchWords = 8 // more ".*" joins only make the regex scan dearer, never the answer better
+ snippetContext = 80 // runes kept on each side of the match
+ searchDeadline = 5 * time.Second // the scan is unindexed; past this it is abuse or a blog too big for it
)
// searchPattern turns what the reader typed into the regular expression both
@@ -23,6 +26,9 @@ const (
// in between", so "go tem" finds "Go templates". Blank → "".
func searchPattern(q string) string {
words := strings.Fields(q)
+ if len(words) > maxSearchWords {
+ words = words[:maxSearchWords]
+ }
for i, w := range words {
words[i] = regexp.QuoteMeta(w)
}