// 抽取结果sort
package util

import (
	"fmt"
	"sort"
)

/*
type SortObject struct {
	Key      string
	Value    int
	ValueStr string
	Object   interface{}
}

type SortStruct []*SortObject

func (list SortStruct) Len() int {
	return len(list)
}

func (list SortStruct) Less(i, j int) bool {
	if list[i].Value > list[j].Value {
		return true
	} else if list[i].Value < list[j].Value {
		return false
	} else {
		return list[i].ValueStr > list[j].ValueStr
	}
}

func (list SortStruct) Swap(i, j int) {
	var temp *SortObject = list[i]
	list[i] = list[j]
	list[j] = temp
}

func ExtSort(list []*SortObject) []*SortObject {
	ls := SortStruct(list)
	sort.Sort(ls)
	return ls
}

*/

//ExtField排序
type results []*ExtField

func (list results) Len() int {
	return len(list)
}

func (list results) Less(i, j int) bool {
	if list[i].Score > list[j].Score {
		return true
	} else if list[i].Score < list[j].Score {
		return false
	} else {
		return fmt.Sprint(list[i].Value) > fmt.Sprint(list[j].Value)
	}
}

func (list results) Swap(i, j int) {
	var temp *ExtField = list[i]
	list[i] = list[j]
	list[j] = temp
}

func Sort(list []*ExtField) []*ExtField {
	ls := results(list)
	sort.Sort(ls)
	return ls
}
