github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/util/tsearch/snowball.go (about) 1 // Copyright 2022 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package tsearch 12 13 import ( 14 "github.com/blevesearch/snowballstem" 15 "github.com/blevesearch/snowballstem/danish" 16 "github.com/blevesearch/snowballstem/dutch" 17 "github.com/blevesearch/snowballstem/english" 18 "github.com/blevesearch/snowballstem/finnish" 19 "github.com/blevesearch/snowballstem/french" 20 "github.com/blevesearch/snowballstem/german" 21 "github.com/blevesearch/snowballstem/hungarian" 22 "github.com/blevesearch/snowballstem/italian" 23 "github.com/blevesearch/snowballstem/norwegian" 24 "github.com/blevesearch/snowballstem/portuguese" 25 "github.com/blevesearch/snowballstem/russian" 26 "github.com/blevesearch/snowballstem/spanish" 27 "github.com/blevesearch/snowballstem/swedish" 28 "github.com/blevesearch/snowballstem/turkish" 29 "github.com/cockroachdb/cockroachdb-parser/pkg/sql/pgwire/pgcode" 30 "github.com/cockroachdb/cockroachdb-parser/pkg/sql/pgwire/pgerror" 31 ) 32 33 func getStemmer(config string) (func(env *snowballstem.Env) bool, error) { 34 switch config { 35 case "simple": 36 return func(env *snowballstem.Env) bool { 37 return true 38 }, nil 39 case "english": 40 return english.Stem, nil 41 case "danish": 42 return danish.Stem, nil 43 case "dutch": 44 return dutch.Stem, nil 45 case "finnish": 46 return finnish.Stem, nil 47 case "french": 48 return french.Stem, nil 49 case "german": 50 return german.Stem, nil 51 case "hungarian": 52 return hungarian.Stem, nil 53 case "italian": 54 return italian.Stem, nil 55 case "norwegian": 56 return norwegian.Stem, nil 57 case "portuguese": 58 return portuguese.Stem, nil 59 case "russian": 60 return russian.Stem, nil 61 case "spanish": 62 return spanish.Stem, nil 63 case "swedish": 64 return swedish.Stem, nil 65 case "turkish": 66 return turkish.Stem, nil 67 } 68 return nil, pgerror.Newf(pgcode.UndefinedObject, "text search configuration %q does not exist", config) 69 }