1package search
2
3import "strings"
4
5type HitType string
6
7const (
8	DashHitDB     HitType = "dash-db"
9	DashHitHome   HitType = "dash-home"
10	DashHitFolder HitType = "dash-folder"
11)
12
13type Hit struct {
14	ID           int64    `json:"id"`
15	UID          string   `json:"uid"`
16	Title        string   `json:"title"`
17	URI          string   `json:"uri"`
18	URL          string   `json:"url"`
19	Slug         string   `json:"slug"`
20	Type         HitType  `json:"type"`
21	Tags         []string `json:"tags"`
22	IsStarred    bool     `json:"isStarred"`
23	FolderID     int64    `json:"folderId,omitempty"`
24	FolderUID    string   `json:"folderUid,omitempty"`
25	FolderTitle  string   `json:"folderTitle,omitempty"`
26	FolderURL    string   `json:"folderUrl,omitempty"`
27	SortMeta     int64    `json:"sortMeta"`
28	SortMetaName string   `json:"sortMetaName,omitempty"`
29}
30
31type HitList []*Hit
32
33func (s HitList) Len() int      { return len(s) }
34func (s HitList) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
35func (s HitList) Less(i, j int) bool {
36	if s[i].Type == "dash-folder" && s[j].Type == "dash-db" {
37		return true
38	}
39
40	if s[i].Type == "dash-db" && s[j].Type == "dash-folder" {
41		return false
42	}
43
44	return strings.ToLower(s[i].Title) < strings.ToLower(s[j].Title)
45}
46