github.com/weaviate/weaviate@v1.24.6/entities/filters/pagination.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 filters
    13  
    14  const (
    15  	// LimitFlagSearchByDist indicates that the
    16  	// vector search should be conducted by
    17  	// distance, without limit
    18  	LimitFlagSearchByDist int = iota - 2
    19  
    20  	// LimitFlagNotSet indicates that no limit
    21  	// was provided by the client
    22  	LimitFlagNotSet
    23  )
    24  
    25  type Pagination struct {
    26  	Offset  int
    27  	Limit   int
    28  	Autocut int
    29  }
    30  
    31  // ExtractPaginationFromArgs gets the limit key out of a map. Not specific to
    32  // GQL, but can be used from GQL
    33  func ExtractPaginationFromArgs(args map[string]interface{}) (*Pagination, error) {
    34  	offset, offsetOk := args["offset"]
    35  	if !offsetOk {
    36  		offset = 0
    37  	}
    38  
    39  	limit, limitOk := args["limit"]
    40  	if !limitOk || limit.(int) < 0 {
    41  		limit = LimitFlagNotSet
    42  	}
    43  
    44  	autocut, autocutOk := args["autocut"]
    45  	if !autocutOk {
    46  		autocut = 0 // disabled
    47  	}
    48  
    49  	if !offsetOk && !limitOk && !autocutOk {
    50  		return nil, nil
    51  	}
    52  
    53  	return &Pagination{
    54  		Offset:  offset.(int),
    55  		Limit:   limit.(int),
    56  		Autocut: autocut.(int),
    57  	}, nil
    58  }