From dc0be0efa4b2320f5859a9df33de2f67199d69ef Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Fri, 18 Mar 2022 21:54:53 -0400 Subject: dbstore/cisasearchrow.go: add byRank sort.Interface --- dbstore/cisasearchrow.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'dbstore') diff --git a/dbstore/cisasearchrow.go b/dbstore/cisasearchrow.go index 9c90eee..19dd04c 100644 --- a/dbstore/cisasearchrow.go +++ b/dbstore/cisasearchrow.go @@ -19,3 +19,21 @@ type CisaSearchRow struct { DueAt rfc3339.Date `json:"due_at"` // Date due Rank float32 `json:"rank"` // search result rank } + +// sort.Interface for CisaSearchRow slice, sorted by rank. +type byRank []CisaSearchRow + +// Required by sort.Interface. +func (r byRank) Len() int { + return len(r) +} + +// Required by sort.Interface. +func (r byRank) Less(i, j int) bool { + return r[i].Rank < r[j].Rank +} + +// Required by sort.Interface. +func (r byRank) Swap(i, j int) { + r[i], r[j] = r[j], r[i] +} -- cgit v1.2.3