analyzer_fa.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 fa
  10. import (
  11. "github.com/couchbaselabs/bleve/analysis"
  12. "github.com/couchbaselabs/bleve/registry"
  13. "github.com/couchbaselabs/bleve/analysis/char_filters/zero_width_non_joiner"
  14. "github.com/couchbaselabs/bleve/analysis/language/ar"
  15. "github.com/couchbaselabs/bleve/analysis/token_filters/lower_case_filter"
  16. "github.com/couchbaselabs/bleve/analysis/tokenizers/unicode_word_boundary"
  17. )
  18. const AnalyzerName = "fa"
  19. func AnalyzerConstructor(config map[string]interface{}, cache *registry.Cache) (*analysis.Analyzer, error) {
  20. zFilter, err := cache.CharFilterNamed(zero_width_non_joiner.Name)
  21. if err != nil {
  22. return nil, err
  23. }
  24. unicodeTokenizer, err := cache.TokenizerNamed(unicode_word_boundary.Name)
  25. if err != nil {
  26. return nil, err
  27. }
  28. normArFilter, err := cache.TokenFilterNamed(ar.NormalizeName)
  29. if err != nil {
  30. return nil, err
  31. }
  32. normFaFilter, err := cache.TokenFilterNamed(NormalizeName)
  33. if err != nil {
  34. return nil, err
  35. }
  36. toLowerFilter, err := cache.TokenFilterNamed(lower_case_filter.Name)
  37. if err != nil {
  38. return nil, err
  39. }
  40. stopFaFilter, err := cache.TokenFilterNamed(StopName)
  41. if err != nil {
  42. return nil, err
  43. }
  44. rv := analysis.Analyzer{
  45. CharFilters: []analysis.CharFilter{
  46. zFilter,
  47. },
  48. Tokenizer: unicodeTokenizer,
  49. TokenFilters: []analysis.TokenFilter{
  50. toLowerFilter,
  51. normArFilter,
  52. normFaFilter,
  53. stopFaFilter,
  54. },
  55. }
  56. return &rv, nil
  57. }
  58. func init() {
  59. registry.RegisterAnalyzer(AnalyzerName, AnalyzerConstructor)
  60. }