github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/util/tsearch/config.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 "strings"
    14  
    15  // ValidConfig returns an error if the input string is not a supported and valid
    16  // text search config.
    17  func ValidConfig(input string) error {
    18  	input = GetConfigKey(input)
    19  	_, err := getStemmer(input)
    20  	return err
    21  }
    22  
    23  // GetConfigKey returns a config that can be used as a key to look up stemmers
    24  // and stopwords from an input config value. This is simulating the more
    25  // advanced customizable dictionaries and configs that Postgres has, which
    26  // allows user-defined text search configurations: because of this, configs can
    27  // have schema prefixes. Because we don't (yet?) allow this, we just have to
    28  // trim off any `pg_catalog.` prefix if it exists.
    29  func GetConfigKey(config string) string {
    30  	return strings.TrimPrefix(config, "pg_catalog.")
    31  }