From 3bda112c5f62e8bdc47190c2a4d090293f1e2a27 Mon Sep 17 00:00:00 2001 From: idafurjes <36131195+idafurjes@users.noreply.github.com> Date: Mon, 30 Jan 2023 15:17:53 +0100 Subject: [PATCH] Chore: Move search model from models package to search service (#62215) * Chore: Move search model from models package to search service * Remove unused imports * Cleanup after merge --- pkg/api/alerting.go | 6 +- pkg/api/common_test.go | 6 +- pkg/api/folder_test.go | 4 +- pkg/api/search.go | 12 ++-- pkg/api/search_test.go | 12 ++-- .../dashboards/database/database_test.go | 18 +++--- pkg/services/dashboards/models.go | 5 +- .../dashboards/service/dashboard_service.go | 16 ++--- pkg/services/ngalert/store/alert_rule.go | 4 +- pkg/services/search/model/model.go | 62 +++++++++++++++++++ pkg/services/search/service.go | 16 ++--- pkg/services/search/service_test.go | 14 ++--- pkg/services/search/sorting.go | 16 ++--- 13 files changed, 127 insertions(+), 64 deletions(-) create mode 100644 pkg/services/search/model/model.go diff --git a/pkg/api/alerting.go b/pkg/api/alerting.go index 6aec309aa74..bda411036c0 100644 --- a/pkg/api/alerting.go +++ b/pkg/api/alerting.go @@ -9,7 +9,6 @@ import ( "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/api/response" - "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting" alertmodels "github.com/grafana/grafana/pkg/services/alerting/models" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" @@ -19,6 +18,7 @@ import ( "github.com/grafana/grafana/pkg/services/ngalert/notifier/channels_config" "github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/search" + "github.com/grafana/grafana/pkg/services/search/model" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/util" "github.com/grafana/grafana/pkg/web" @@ -109,7 +109,7 @@ func (hs *HTTPServer) GetAlerts(c *contextmodel.ReqContext) response.Response { Limit: 1000, OrgId: c.OrgID, DashboardIds: dashboardIDs, - Type: string(models.DashHitDB), + Type: string(model.DashHitDB), FolderIds: folderIDs, Permission: dashboards.PERMISSION_VIEW, } @@ -120,7 +120,7 @@ func (hs *HTTPServer) GetAlerts(c *contextmodel.ReqContext) response.Response { } for _, d := range searchQuery.Result { - if d.Type == models.DashHitDB && d.ID > 0 { + if d.Type == model.DashHitDB && d.ID > 0 { dashboardIDs = append(dashboardIDs, d.ID) } } diff --git a/pkg/api/common_test.go b/pkg/api/common_test.go index 3e74a3e2ebc..9eaa2cefceb 100644 --- a/pkg/api/common_test.go +++ b/pkg/api/common_test.go @@ -23,7 +23,6 @@ import ( "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/remotecache" "github.com/grafana/grafana/pkg/infra/tracing" - "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/acimpl" accesscontrolmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock" @@ -53,6 +52,7 @@ import ( "github.com/grafana/grafana/pkg/services/quota/quotatest" "github.com/grafana/grafana/pkg/services/rendering" "github.com/grafana/grafana/pkg/services/search" + "github.com/grafana/grafana/pkg/services/search/model" "github.com/grafana/grafana/pkg/services/searchusers" "github.com/grafana/grafana/pkg/services/searchusers/filters" "github.com/grafana/grafana/pkg/services/sqlstore" @@ -524,13 +524,13 @@ type setUpConf struct { aclMockResp []*dashboards.DashboardACLInfoDTO } -type mockSearchService struct{ ExpectedResult models.HitList } +type mockSearchService struct{ ExpectedResult model.HitList } func (mss *mockSearchService) SearchHandler(_ context.Context, q *search.Query) error { q.Result = mss.ExpectedResult return nil } -func (mss *mockSearchService) SortOptions() []models.SortOption { return nil } +func (mss *mockSearchService) SortOptions() []model.SortOption { return nil } func setUp(confs ...setUpConf) *HTTPServer { store := dbtest.NewFakeDB() diff --git a/pkg/api/folder_test.go b/pkg/api/folder_test.go index 8e7034c0844..b441fa3ae22 100644 --- a/pkg/api/folder_test.go +++ b/pkg/api/folder_test.go @@ -14,7 +14,6 @@ import ( "github.com/grafana/grafana/pkg/api/response" "github.com/grafana/grafana/pkg/api/routing" "github.com/grafana/grafana/pkg/infra/db/dbtest" - "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/actest" acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock" @@ -25,6 +24,7 @@ import ( "github.com/grafana/grafana/pkg/services/folder/foldertest" "github.com/grafana/grafana/pkg/services/guardian" "github.com/grafana/grafana/pkg/services/quota/quotatest" + "github.com/grafana/grafana/pkg/services/search/model" "github.com/grafana/grafana/pkg/services/team/teamtest" "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/setting" @@ -151,7 +151,7 @@ func TestHTTPServer_FolderMetadata(t *testing.T) { hs.AccessControl = acmock.New() hs.QuotaService = quotatest.New(false, nil) hs.SearchService = &mockSearchService{ - ExpectedResult: models.HitList{}, + ExpectedResult: model.HitList{}, } }) diff --git a/pkg/api/search.go b/pkg/api/search.go index 91b8e2c06ac..0eb478fc05a 100644 --- a/pkg/api/search.go +++ b/pkg/api/search.go @@ -6,11 +6,11 @@ import ( "github.com/grafana/grafana/pkg/api/response" "github.com/grafana/grafana/pkg/infra/metrics" - "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/accesscontrol" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/search" + "github.com/grafana/grafana/pkg/services/search/model" "github.com/grafana/grafana/pkg/util" ) @@ -95,12 +95,12 @@ func (hs *HTTPServer) Search(c *contextmodel.ReqContext) response.Response { return hs.searchHitsWithMetadata(c, searchQuery.Result) } -func (hs *HTTPServer) searchHitsWithMetadata(c *contextmodel.ReqContext, hits models.HitList) response.Response { +func (hs *HTTPServer) searchHitsWithMetadata(c *contextmodel.ReqContext, hits model.HitList) response.Response { folderUIDs := make(map[string]bool) dashboardUIDs := make(map[string]bool) for _, hit := range hits { - if hit.Type == models.DashHitFolder { + if hit.Type == model.DashHitFolder { folderUIDs[hit.UID] = true } else { dashboardUIDs[hit.UID] = true @@ -113,13 +113,13 @@ func (hs *HTTPServer) searchHitsWithMetadata(c *contextmodel.ReqContext, hits mo // search hit with access control metadata attached type hitWithMeta struct { - *models.Hit + *model.Hit AccessControl accesscontrol.Metadata `json:"accessControl,omitempty"` } hitsWithMeta := make([]hitWithMeta, 0, len(hits)) for _, hit := range hits { var meta accesscontrol.Metadata - if hit.Type == models.DashHitFolder { + if hit.Type == model.DashHitFolder { meta = folderMeta[hit.UID] } else { meta = accesscontrol.MergeMeta("dashboards", dashboardMeta[hit.UID], folderMeta[hit.FolderUID]) @@ -216,7 +216,7 @@ type SearchParams struct { // swagger:response searchResponse type SearchResponse struct { // in: body - Body models.HitList `json:"body"` + Body model.HitList `json:"body"` } // swagger:response listSortOptionsResponse diff --git a/pkg/api/search_test.go b/pkg/api/search_test.go index 49ffef06275..c2d70b45dc3 100644 --- a/pkg/api/search_test.go +++ b/pkg/api/search_test.go @@ -9,9 +9,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/dashboards" + "github.com/grafana/grafana/pkg/services/search/model" "github.com/grafana/grafana/pkg/services/user" ) @@ -21,10 +21,10 @@ func TestHTTPServer_Search(t *testing.T) { sc.initCtx.SignedInUser = &user.SignedInUser{} sc.hs.SearchService = &mockSearchService{ - ExpectedResult: models.HitList{ - {ID: 1, UID: "folder1", Title: "folder1", Type: models.DashHitFolder}, - {ID: 2, UID: "folder2", Title: "folder2", Type: models.DashHitFolder}, - {ID: 3, UID: "dash3", Title: "dash3", FolderUID: "folder2", Type: models.DashHitDB}, + ExpectedResult: model.HitList{ + {ID: 1, UID: "folder1", Title: "folder1", Type: model.DashHitFolder}, + {ID: 2, UID: "folder2", Title: "folder2", Type: model.DashHitFolder}, + {ID: 3, UID: "dash3", Title: "dash3", FolderUID: "folder2", Type: model.DashHitDB}, }, } @@ -38,7 +38,7 @@ func TestHTTPServer_Search(t *testing.T) { } type withMeta struct { - models.Hit + model.Hit AccessControl accesscontrol.Metadata `json:"accessControl,omitempty"` } diff --git a/pkg/services/dashboards/database/database_test.go b/pkg/services/dashboards/database/database_test.go index 7f643a8fc78..eb5a591ea6f 100644 --- a/pkg/services/dashboards/database/database_test.go +++ b/pkg/services/dashboards/database/database_test.go @@ -13,12 +13,12 @@ import ( "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/db" - "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/publicdashboards/database" publicDashboardModels "github.com/grafana/grafana/pkg/services/publicdashboards/models" "github.com/grafana/grafana/pkg/services/quota/quotatest" + "github.com/grafana/grafana/pkg/services/search/model" "github.com/grafana/grafana/pkg/services/sqlstore" "github.com/grafana/grafana/pkg/services/sqlstore/searchstore" "github.com/grafana/grafana/pkg/services/star" @@ -407,7 +407,7 @@ func TestIntegrationDashboardDataAccess(t *testing.T) { require.Equal(t, len(query.Result), 1) hit := query.Result[0] - require.Equal(t, hit.Type, models.DashHitFolder) + require.Equal(t, hit.Type, model.DashHitFolder) require.Equal(t, hit.URL, fmt.Sprintf("/dashboards/f/%s/%s", savedFolder.UID, savedFolder.Slug)) require.Equal(t, hit.FolderTitle, "") }) @@ -648,8 +648,8 @@ func TestIntegrationDashboard_SortingOptions(t *testing.T) { 1: {dashboards.ActionDashboardsRead: []string{dashboards.ScopeDashboardsAll}}, }, }, - Sort: models.SortOption{ - Filter: []models.SortOptionFilter{ + Sort: model.SortOption{ + Filter: []model.SortOptionFilter{ searchstore.TitleSorter{Descending: true}, }, }, @@ -850,18 +850,18 @@ func testSearchDashboards(d *DashboardStore, query *dashboards.FindPersistedDash } func makeQueryResult(query *dashboards.FindPersistedDashboardsQuery, res []dashboards.DashboardSearchProjection) { - query.Result = make([]*models.Hit, 0) - hits := make(map[int64]*models.Hit) + query.Result = make([]*model.Hit, 0) + hits := make(map[int64]*model.Hit) for _, item := range res { hit, exists := hits[item.ID] if !exists { - hitType := models.DashHitDB + hitType := model.DashHitDB if item.IsFolder { - hitType = models.DashHitFolder + hitType = model.DashHitFolder } - hit = &models.Hit{ + hit = &model.Hit{ ID: item.ID, UID: item.UID, Title: item.Title, diff --git a/pkg/services/dashboards/models.go b/pkg/services/dashboards/models.go index b67cd20c33c..f9f3fcb2f2c 100644 --- a/pkg/services/dashboards/models.go +++ b/pkg/services/dashboards/models.go @@ -10,6 +10,7 @@ import ( "github.com/grafana/grafana/pkg/services/folder" "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/quota" + "github.com/grafana/grafana/pkg/services/search/model" "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/setting" ) @@ -412,9 +413,9 @@ type FindPersistedDashboardsQuery struct { Limit int64 Page int64 Permission PermissionType - Sort models.SortOption + Sort model.SortOption Filters []interface{} - Result models.HitList + Result model.HitList } diff --git a/pkg/services/dashboards/service/dashboard_service.go b/pkg/services/dashboards/service/dashboard_service.go index b4098316e02..ca46e7beb35 100644 --- a/pkg/services/dashboards/service/dashboard_service.go +++ b/pkg/services/dashboards/service/dashboard_service.go @@ -10,7 +10,6 @@ import ( "github.com/grafana/grafana/pkg/infra/appcontext" "github.com/grafana/grafana/pkg/infra/log" - "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/accesscontrol" "github.com/grafana/grafana/pkg/services/alerting" "github.com/grafana/grafana/pkg/services/dashboards" @@ -18,6 +17,7 @@ import ( "github.com/grafana/grafana/pkg/services/folder" "github.com/grafana/grafana/pkg/services/guardian" "github.com/grafana/grafana/pkg/services/org" + "github.com/grafana/grafana/pkg/services/search/model" "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/util" @@ -553,25 +553,25 @@ func (dr *DashboardServiceImpl) SearchDashboards(ctx context.Context, query *das return nil } -func getHitType(item dashboards.DashboardSearchProjection) models.HitType { - var hitType models.HitType +func getHitType(item dashboards.DashboardSearchProjection) model.HitType { + var hitType model.HitType if item.IsFolder { - hitType = models.DashHitFolder + hitType = model.DashHitFolder } else { - hitType = models.DashHitDB + hitType = model.DashHitDB } return hitType } func makeQueryResult(query *dashboards.FindPersistedDashboardsQuery, res []dashboards.DashboardSearchProjection) { - query.Result = make([]*models.Hit, 0) - hits := make(map[int64]*models.Hit) + query.Result = make([]*model.Hit, 0) + hits := make(map[int64]*model.Hit) for _, item := range res { hit, exists := hits[item.ID] if !exists { - hit = &models.Hit{ + hit = &model.Hit{ ID: item.ID, UID: item.UID, Title: item.Title, diff --git a/pkg/services/ngalert/store/alert_rule.go b/pkg/services/ngalert/store/alert_rule.go index 74e7b2f8387..adfdf0337e3 100644 --- a/pkg/services/ngalert/store/alert_rule.go +++ b/pkg/services/ngalert/store/alert_rule.go @@ -7,11 +7,11 @@ import ( "strings" "github.com/grafana/grafana/pkg/infra/db" - "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/folder" "github.com/grafana/grafana/pkg/services/guardian" ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models" + "github.com/grafana/grafana/pkg/services/search/model" "github.com/grafana/grafana/pkg/services/sqlstore" "github.com/grafana/grafana/pkg/services/sqlstore/searchstore" "github.com/grafana/grafana/pkg/services/user" @@ -333,7 +333,7 @@ func (st DBstore) GetUserVisibleNamespaces(ctx context.Context, orgID int64, use Type: searchstore.TypeAlertFolder, Limit: -1, Permission: dashboards.PERMISSION_VIEW, - Sort: models.SortOption{}, + Sort: model.SortOption{}, Filters: []interface{}{ searchstore.FolderWithAlertsFilter{}, }, diff --git a/pkg/services/search/model/model.go b/pkg/services/search/model/model.go new file mode 100644 index 00000000000..ac6828fe415 --- /dev/null +++ b/pkg/services/search/model/model.go @@ -0,0 +1,62 @@ +package model + +import ( + "strings" + + "github.com/grafana/grafana/pkg/services/sqlstore/searchstore" +) + +type SortOption struct { + Name string + DisplayName string + Description string + Index int + MetaName string + Filter []SortOptionFilter +} + +type SortOptionFilter interface { + searchstore.FilterOrderBy +} + +type HitType string + +const ( + DashHitDB HitType = "dash-db" + DashHitHome HitType = "dash-home" + DashHitFolder HitType = "dash-folder" +) + +type Hit struct { + ID int64 `json:"id"` + UID string `json:"uid"` + Title string `json:"title"` + URI string `json:"uri"` + URL string `json:"url"` + Slug string `json:"slug"` + Type HitType `json:"type"` + Tags []string `json:"tags"` + IsStarred bool `json:"isStarred"` + FolderID int64 `json:"folderId,omitempty"` + FolderUID string `json:"folderUid,omitempty"` + FolderTitle string `json:"folderTitle,omitempty"` + FolderURL string `json:"folderUrl,omitempty"` + SortMeta int64 `json:"sortMeta"` + SortMetaName string `json:"sortMetaName,omitempty"` +} + +type HitList []*Hit + +func (s HitList) Len() int { return len(s) } +func (s HitList) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +func (s HitList) Less(i, j int) bool { + if s[i].Type == "dash-folder" && s[j].Type == "dash-db" { + return true + } + + if s[i].Type == "dash-db" && s[j].Type == "dash-folder" { + return false + } + + return strings.ToLower(s[i].Title) < strings.ToLower(s[j].Title) +} diff --git a/pkg/services/search/service.go b/pkg/services/search/service.go index 365516c33fe..64d130023e2 100644 --- a/pkg/services/search/service.go +++ b/pkg/services/search/service.go @@ -5,8 +5,8 @@ import ( "sort" "github.com/grafana/grafana/pkg/infra/db" - "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/dashboards" + "github.com/grafana/grafana/pkg/services/search/model" "github.com/grafana/grafana/pkg/services/star" "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/setting" @@ -15,7 +15,7 @@ import ( func ProvideService(cfg *setting.Cfg, sqlstore db.DB, starService star.Service, dashboardService dashboards.DashboardService) *SearchService { s := &SearchService{ Cfg: cfg, - sortOptions: map[string]models.SortOption{ + sortOptions: map[string]model.SortOption{ SortAlphaAsc.Name: SortAlphaAsc, SortAlphaDesc.Name: SortAlphaDesc, }, @@ -41,17 +41,17 @@ type Query struct { Permission dashboards.PermissionType Sort string - Result models.HitList + Result model.HitList } type Service interface { SearchHandler(context.Context, *Query) error - SortOptions() []models.SortOption + SortOptions() []model.SortOption } type SearchService struct { Cfg *setting.Cfg - sortOptions map[string]models.SortOption + sortOptions map[string]model.SortOption sqlstore db.DB starService star.Service dashboardService dashboards.DashboardService @@ -94,8 +94,8 @@ func (s *SearchService) SearchHandler(ctx context.Context, query *Query) error { return nil } -func sortedHits(unsorted models.HitList) models.HitList { - hits := make(models.HitList, 0) +func sortedHits(unsorted model.HitList) model.HitList { + hits := make(model.HitList, 0) hits = append(hits, unsorted...) sort.Sort(hits) @@ -107,7 +107,7 @@ func sortedHits(unsorted models.HitList) models.HitList { return hits } -func (s *SearchService) setStarredDashboards(ctx context.Context, userID int64, hits []*models.Hit) error { +func (s *SearchService) setStarredDashboards(ctx context.Context, userID int64, hits []*model.Hit) error { query := star.GetUserStarsQuery{ UserID: userID, } diff --git a/pkg/services/search/service_test.go b/pkg/services/search/service_test.go index 19b94758b68..c0c9245b01d 100644 --- a/pkg/services/search/service_test.go +++ b/pkg/services/search/service_test.go @@ -9,8 +9,8 @@ import ( "github.com/stretchr/testify/require" "github.com/grafana/grafana/pkg/infra/db/dbtest" - "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/dashboards" + "github.com/grafana/grafana/pkg/services/search/model" "github.com/grafana/grafana/pkg/services/star" "github.com/grafana/grafana/pkg/services/star/startest" "github.com/grafana/grafana/pkg/services/user" @@ -24,12 +24,12 @@ func TestSearch_SortedResults(t *testing.T) { ds := dashboards.NewFakeDashboardService(t) ds.On("SearchDashboards", mock.Anything, mock.AnythingOfType("*dashboards.FindPersistedDashboardsQuery")).Run(func(args mock.Arguments) { q := args.Get(1).(*dashboards.FindPersistedDashboardsQuery) - q.Result = models.HitList{ - &models.Hit{ID: 16, Title: "CCAA", Type: "dash-db", Tags: []string{"BB", "AA"}}, - &models.Hit{ID: 10, Title: "AABB", Type: "dash-db", Tags: []string{"CC", "AA"}}, - &models.Hit{ID: 15, Title: "BBAA", Type: "dash-db", Tags: []string{"EE", "AA", "BB"}}, - &models.Hit{ID: 25, Title: "bbAAa", Type: "dash-db", Tags: []string{"EE", "AA", "BB"}}, - &models.Hit{ID: 17, Title: "FOLDER", Type: "dash-folder"}, + q.Result = model.HitList{ + &model.Hit{ID: 16, Title: "CCAA", Type: "dash-db", Tags: []string{"BB", "AA"}}, + &model.Hit{ID: 10, Title: "AABB", Type: "dash-db", Tags: []string{"CC", "AA"}}, + &model.Hit{ID: 15, Title: "BBAA", Type: "dash-db", Tags: []string{"EE", "AA", "BB"}}, + &model.Hit{ID: 25, Title: "bbAAa", Type: "dash-db", Tags: []string{"EE", "AA", "BB"}}, + &model.Hit{ID: 17, Title: "FOLDER", Type: "dash-folder"}, } }).Return(nil) us.ExpectedSignedInUser = &user.SignedInUser{IsGrafanaAdmin: true} diff --git a/pkg/services/search/sorting.go b/pkg/services/search/sorting.go index 25658d0b2f9..1749e23fa14 100644 --- a/pkg/services/search/sorting.go +++ b/pkg/services/search/sorting.go @@ -3,26 +3,26 @@ package search import ( "sort" - "github.com/grafana/grafana/pkg/models" + "github.com/grafana/grafana/pkg/services/search/model" "github.com/grafana/grafana/pkg/services/sqlstore/searchstore" ) var ( - SortAlphaAsc = models.SortOption{ + SortAlphaAsc = model.SortOption{ Name: "alpha-asc", DisplayName: "Alphabetically (A–Z)", Description: "Sort results in an alphabetically ascending order", Index: 0, - Filter: []models.SortOptionFilter{ + Filter: []model.SortOptionFilter{ searchstore.TitleSorter{}, }, } - SortAlphaDesc = models.SortOption{ + SortAlphaDesc = model.SortOption{ Name: "alpha-desc", DisplayName: "Alphabetically (Z–A)", Description: "Sort results in an alphabetically descending order", Index: 0, - Filter: []models.SortOptionFilter{ + Filter: []model.SortOptionFilter{ searchstore.TitleSorter{Descending: true}, }, } @@ -30,12 +30,12 @@ var ( // RegisterSortOption allows for hooking in more search options from // other services. -func (s *SearchService) RegisterSortOption(option models.SortOption) { +func (s *SearchService) RegisterSortOption(option model.SortOption) { s.sortOptions[option.Name] = option } -func (s *SearchService) SortOptions() []models.SortOption { - opts := make([]models.SortOption, 0, len(s.sortOptions)) +func (s *SearchService) SortOptions() []model.SortOption { + opts := make([]model.SortOption, 0, len(s.sortOptions)) for _, o := range s.sortOptions { opts = append(opts, o) }