Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions sort/custom_field_sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"sort"
"strings"
"time"

"github.com/alibaba/pairec/v2/log"
"github.com/alibaba/pairec/v2/module"
Expand All @@ -14,6 +15,7 @@ import (
type CustomFieldSort struct {
sortByField string
sortOrder string // "asc" 表示升序,"desc" 表示降序
name string
}

func NewCustomFieldSort(config recconf.SortConfig) *CustomFieldSort {
Expand All @@ -31,10 +33,12 @@ func NewCustomFieldSort(config recconf.SortConfig) *CustomFieldSort {
return &CustomFieldSort{
sortByField: config.SortByField,
sortOrder: sortOrder,
name: config.Name,
}
}

func (s *CustomFieldSort) Sort(sortData *SortData) error {
start := time.Now()
items, ok := sortData.Data.([]*module.Item)
if !ok {
return errors.New("sort data type error")
Expand All @@ -61,5 +65,6 @@ func (s *CustomFieldSort) Sort(sortData *SortData) error {
return iScore > jScore
})
sortData.Data = items
sortInfoLogWithName(sortData, "CustomFieldSort", s.name, len(items), start)
return nil
}