From 0bd586a3c8a967d0e80829340c22608612fd726c Mon Sep 17 00:00:00 2001 From: pk910 Date: Mon, 4 Sep 2023 13:30:56 +0200 Subject: [PATCH] fixed search --- dbtypes/search.go | 4 ++++ handlers/search.go | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/dbtypes/search.go b/dbtypes/search.go index 3b0b9079..f54c2b7d 100644 --- a/dbtypes/search.go +++ b/dbtypes/search.go @@ -10,6 +10,10 @@ type SearchGraffitiResult struct { Graffiti string `db:"graffiti"` } +type SearchNameResult struct { + Name string `db:"name"` +} + type SearchAheadEpochsResult []struct { Epoch uint64 `db:"epoch"` } diff --git a/handlers/search.go b/handlers/search.go index 089876d9..59b6d48e 100644 --- a/handlers/search.go +++ b/handlers/search.go @@ -71,19 +71,20 @@ func Search(w http.ResponseWriter, r *http.Request) { } } - var namesCount uint64 - err = db.ReaderDb.Get(namesCount, db.EngineQuery(map[dbtypes.DBEngineType]string{ + names := &dbtypes.SearchNameResult{} + err = db.ReaderDb.Get(names, db.EngineQuery(map[dbtypes.DBEngineType]string{ dbtypes.DBEnginePgsql: ` - SELECT COUNT(*) + SELECT name FROM validator_names WHERE name ILIKE LOWER($1) LIMIT 1`, dbtypes.DBEngineSqlite: ` - SELECT COUNT(*) + SELECT name FROM validator_names WHERE name LIKE LOWER($1) LIMIT 1`, }), "%"+searchQuery+"%") + fmt.Printf("err: %v\n", err) if err == nil { http.Redirect(w, r, "/slots/filtered?f&f.missing=1&f.orphaned=1&f.pname="+searchQuery, http.StatusMovedPermanently) return