detect_lang_analyzer.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright (c) 2014 Couchbase, Inc.
  2. // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
  3. // except in compliance with the License. You may obtain a copy of the License at
  4. // http://www.apache.org/licenses/LICENSE-2.0
  5. // Unless required by applicable law or agreed to in writing, software distributed under the
  6. // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  7. // either express or implied. See the License for the specific language governing permissions
  8. // and limitations under the License.
  9. package detect_lang_analyzer
  10. import (
  11. "github.com/couchbaselabs/bleve/analysis"
  12. "github.com/couchbaselabs/bleve/analysis/token_filters/lower_case_filter"
  13. "github.com/couchbaselabs/bleve/registry"
  14. )
  15. const Name = "detect_lang"
  16. func AnalyzerConstructor(config map[string]interface{}, cache *registry.Cache) (*analysis.Analyzer, error) {
  17. keywordTokenizer, err := cache.TokenizerNamed("single")
  18. if err != nil {
  19. return nil, err
  20. }
  21. toLowerFilter, err := cache.TokenFilterNamed(lower_case_filter.Name)
  22. if err != nil {
  23. return nil, err
  24. }
  25. detectLangFilter, err := cache.TokenFilterNamed("detect_lang")
  26. if err != nil {
  27. return nil, err
  28. }
  29. rv := analysis.Analyzer{
  30. Tokenizer: keywordTokenizer,
  31. TokenFilters: []analysis.TokenFilter{
  32. toLowerFilter,
  33. detectLangFilter,
  34. },
  35. }
  36. return &rv, nil
  37. }
  38. func init() {
  39. registry.RegisterAnalyzer(Name, AnalyzerConstructor)
  40. }