From 5d5f95725f8a21fce51ec99df199af6ee39b91da Mon Sep 17 00:00:00 2001 From: Nazar Kanaev Date: Wed, 15 Jul 2020 20:39:39 +0100 Subject: [PATCH] search items --- server/handlers.go | 3 +++ storage/item.go | 11 +++++++++++ template/index.html | 11 +++++++---- template/static/javascripts/app.js | 13 +++++++++++-- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/server/handlers.go b/server/handlers.go index 980391c..c5be850 100644 --- a/server/handlers.go +++ b/server/handlers.go @@ -308,6 +308,9 @@ func ItemListHandler(rw http.ResponseWriter, req *http.Request) { statusValue := storage.StatusValues[status] filter.Status = &statusValue } + if search := query.Get("search"); len(search) != 0 { + filter.Search = &search + } items := db(req).ListItems(filter, (curPage-1)*perPage, perPage) count := db(req).CountItems(filter) rw.WriteHeader(http.StatusOK) diff --git a/storage/item.go b/storage/item.go index 78b18c0..d9fcbb3 100644 --- a/storage/item.go +++ b/storage/item.go @@ -60,6 +60,7 @@ type ItemFilter struct { FolderID *int64 FeedID *int64 Status *ItemStatus + Search *string } func (s *Storage) CreateItems(items []Item) bool { @@ -112,6 +113,16 @@ func listQueryPredicate(filter ItemFilter) (string, []interface{}) { cond = append(cond, "i.status = ?") args = append(args, *filter.Status) } + if filter.Search != nil { + words := strings.Fields(*filter.Search) + terms := make([]string, len(words)) + for idx, word := range words { + terms[idx] = word + "*" + } + + cond = append(cond, "i.search_rowid in (select rowid from search where search match ?)") + args = append(args, strings.Join(terms, " ")) + } predicate := "1" if len(cond) > 0 { diff --git a/template/index.html b/template/index.html index e5230b8..5e7b066 100644 --- a/template/index.html +++ b/template/index.html @@ -72,10 +72,13 @@
-
- +
+ +
+ +