diff options
author | Paul Duncan <pabs@pablotron.org> | 2022-03-18 21:54:53 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2022-03-18 21:54:53 -0400 |
commit | dc0be0efa4b2320f5859a9df33de2f67199d69ef (patch) | |
tree | 4002ecf62b6a588b26d5f27d3382f282f707327a | |
parent | 3b148c9358a76bd7eabde4c8333f5c31fb1fb581 (diff) | |
download | cvez-dc0be0efa4b2320f5859a9df33de2f67199d69ef.tar.bz2 cvez-dc0be0efa4b2320f5859a9df33de2f67199d69ef.zip |
dbstore/cisasearchrow.go: add byRank sort.Interface
-rw-r--r-- | dbstore/cisasearchrow.go | 18 |
1 files changed, 18 insertions, 0 deletions
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] +} |