github.com/weaviate/weaviate@v1.24.6/adapters/repos/db/sorter/utils.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package sorter
    13  
    14  import (
    15  	"github.com/pkg/errors"
    16  	"github.com/weaviate/weaviate/entities/filters"
    17  )
    18  
    19  func extractPropNamesAndOrders(sort []filters.Sort) ([]string, []string, error) {
    20  	propNames := make([]string, len(sort))
    21  	orders := make([]string, len(sort))
    22  
    23  	for i, srt := range sort {
    24  		if len(srt.Path) == 0 {
    25  			return nil, nil, errors.New("path parameter cannot be empty")
    26  		}
    27  		if len(srt.Path) > 1 {
    28  			return nil, nil, errors.New("sorting by reference not supported, path must have exactly one argument")
    29  		}
    30  		propNames[i] = srt.Path[0]
    31  		orders[i] = srt.Order
    32  	}
    33  	return propNames, orders, nil
    34  }
    35  
    36  func validateLimit(limit, elementsCount int) int {
    37  	if limit > elementsCount {
    38  		return elementsCount
    39  	}
    40  	if limit < 0 {
    41  		return 0
    42  	}
    43  	return limit
    44  }