github.com/weaviate/weaviate@v1.24.6/usecases/traverser/traverser_schema_search_params.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 traverser 13 14 import ( 15 "fmt" 16 ) 17 18 // TODO: is this still used? 19 20 // SearchType to search for either class names or property names 21 type SearchType string 22 23 const ( 24 // SearchTypeClass to search the contextionary for class names 25 SearchTypeClass SearchType = "class" 26 // SearchTypeProperty to search the contextionary for property names 27 SearchTypeProperty SearchType = "property" 28 ) 29 30 // SearchParams to be used for a SchemaSearch. See individual properties for 31 // additional documentation on what they do 32 type SearchParams struct { 33 // SearchType can be SearchTypeClass or SearchTypeProperty 34 SearchType SearchType 35 36 // Name is the string-representation of the class or property name 37 Name string 38 39 // Certainty must be a value between 0 and 1. The higher it is the narrower 40 // is the search, the lower it is, the wider the search is 41 Certainty float32 42 } 43 44 // Validate the feasibility of the specified arguments 45 func (p SearchParams) Validate() error { 46 if p.Name == "" { 47 return fmt.Errorf("Name cannot be empty") 48 } 49 50 if err := p.validateCertaintyOrWeight(p.Certainty); err != nil { 51 return fmt.Errorf("invalid Certainty: %s", err) 52 } 53 54 if p.SearchType != SearchTypeClass && p.SearchType != SearchTypeProperty { 55 return fmt.Errorf( 56 "SearchType must be SearchTypeClass or SearchTypeProperty, but got '%s'", p.SearchType) 57 } 58 59 return nil 60 } 61 62 func (p SearchParams) validateCertaintyOrWeight(c float32) error { 63 if c >= 0 && c <= 1 { 64 return nil 65 } 66 67 return fmt.Errorf("must be between 0 and 1, but got '%f'", c) 68 }