analyzer_da.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 da
  10. import (
  11. "github.com/couchbaselabs/bleve/analysis"
  12. "github.com/couchbaselabs/bleve/analysis/token_filters/lower_case_filter"
  13. "github.com/couchbaselabs/bleve/analysis/tokenizers/unicode_word_boundary"
  14. "github.com/couchbaselabs/bleve/registry"
  15. )
  16. const AnalyzerName = "da"
  17. func AnalyzerConstructor(config map[string]interface{}, cache *registry.Cache) (*analysis.Analyzer, error) {
  18. unicodeTokenizer, err := cache.TokenizerNamed(unicode_word_boundary.Name)
  19. if err != nil {
  20. return nil, err
  21. }
  22. toLowerFilter, err := cache.TokenFilterNamed(lower_case_filter.Name)
  23. if err != nil {
  24. return nil, err
  25. }
  26. stopDaFilter, err := cache.TokenFilterNamed(StopName)
  27. if err != nil {
  28. return nil, err
  29. }
  30. stemmerDaFilter, err := cache.TokenFilterNamed(StemmerName)
  31. if err != nil {
  32. return nil, err
  33. }
  34. rv := analysis.Analyzer{
  35. Tokenizer: unicodeTokenizer,
  36. TokenFilters: []analysis.TokenFilter{
  37. toLowerFilter,
  38. stopDaFilter,
  39. stemmerDaFilter,
  40. },
  41. }
  42. return &rv, nil
  43. }
  44. func init() {
  45. registry.RegisterAnalyzer(AnalyzerName, AnalyzerConstructor)
  46. }