github.com/weaviate/weaviate@v1.24.6/modules/text-spellcheck/additional/spellcheck/spellcheck.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 spellcheck 13 14 import ( 15 "context" 16 "errors" 17 18 "github.com/tailor-inc/graphql" 19 "github.com/tailor-inc/graphql/language/ast" 20 "github.com/weaviate/weaviate/entities/moduletools" 21 "github.com/weaviate/weaviate/entities/search" 22 "github.com/weaviate/weaviate/modules/text-spellcheck/ent" 23 ) 24 25 type Params struct{} 26 27 type spellCheckClient interface { 28 Check(ctx context.Context, text []string) (*ent.SpellCheckResult, error) 29 } 30 31 type SpellCheckProvider struct { 32 spellCheck spellCheckClient 33 paramHelper *paramHelper 34 } 35 36 func New(spellCheck spellCheckClient) *SpellCheckProvider { 37 return &SpellCheckProvider{spellCheck, newParamHelper()} 38 } 39 40 func (p *SpellCheckProvider) AdditionalPropertyDefaultValue() interface{} { 41 return &Params{} 42 } 43 44 func (p *SpellCheckProvider) ExtractAdditionalFn(param []*ast.Argument) interface{} { 45 return &Params{} 46 } 47 48 func (p *SpellCheckProvider) AdditionalFieldFn(classname string) *graphql.Field { 49 return p.additionalSpellCheckField(classname) 50 } 51 52 func (p *SpellCheckProvider) AdditionalPropertyFn(ctx context.Context, 53 in []search.Result, params interface{}, limit *int, 54 argumentModuleParams map[string]interface{}, cfg moduletools.ClassConfig, 55 ) ([]search.Result, error) { 56 if parameters, ok := params.(*Params); ok { 57 return p.findSpellCheck(ctx, in, parameters, limit, argumentModuleParams) 58 } 59 return nil, errors.New("wrong parameters") 60 }