コード例 #1
0
ファイル: view.go プロジェクト: steveyen/tuqqedin
func (this *ViewLocation) Compare(that *ViewLocation) int {
	result := ast.CollateJSON(this.Key, that.Key)
	if result != 0 {
		// if keys are the same, compare docis
		if *this.Docid < *that.Docid {
			result = -1
		} else if *this.Docid > *that.Docid {
			result = 1
		} else {
			result = 0
		}
	}

	return result
}
コード例 #2
0
ファイル: order.go プロジェクト: steveyen/tuqqedin
func (this *Order) Less(i, j int) bool {
	left := this.output[i]
	right := this.output[j]

	var leftContext, rightContext ast.Context
	switch left := left.(type) {
	case datasource.Document:
		leftContext = ast.NewContext(left)
		switch right := right.(type) {
		case datasource.Document:
			rightContext = ast.NewContext(right)
		default:
			panic(fmt.Sprintf("Non-map rows not currently supported (saw %T)", right))
		}
	default:
		panic(fmt.Sprintf("Non-map rows not currently supported (saw %T)", left))
	}

	for _, oe := range this.orderBy {
		leftVal, err := oe.Expression().Evaluate(leftContext)
		if err != nil {
			log.Printf("Error evaluating expression: %v", err)
			return false
		}
		rightVal, err := oe.Expression().Evaluate(rightContext)
		if err != nil {
			log.Printf("Error evaluating expression: %v", err)
			return false
		}

		result := ast.CollateJSON(leftVal, rightVal)
		if result != 0 {
			if oe.Order() && result < 0 {
				return true
			} else if !oe.Order() && result > 0 {
				return true
			} else {
				return false
			}
		}
		// at this level they are the same, keep going
	}

	// if we go to this point the order expressions could not differentiate between the elements
	return false
}