-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.go
32 lines (28 loc) · 909 Bytes
/
search.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Content managed by Project Forge, see [projectforge.md] for details.
package clib
import (
"fmt"
"github.com/valyala/fasthttp"
"admini.dev/admini/app"
"admini.dev/admini/app/controller"
"admini.dev/admini/app/controller/cutil"
"admini.dev/admini/app/lib/search"
"admini.dev/admini/views/vsearch"
)
func Search(rc *fasthttp.RequestCtx) {
controller.Act("search", rc, func(as *app.State, ps *cutil.PageState) (string, error) {
q := string(rc.URI().QueryArgs().Peek("q"))
params := &search.Params{Q: q, PS: ps.Params}
results, errs := search.Search(ps.Context, params, as, ps)
ps.Title = "Search Results"
if q != "" {
ps.Title = fmt.Sprintf("[%s] %s", q, ps.Title)
}
ps.Data = results
bc := []string{"Search||/search"}
if q != "" {
bc = append(bc, q)
}
return controller.Render(rc, as, &vsearch.Results{Params: params, Results: results, Errors: errs}, ps, bc...)
})
}