standard_analyzer.go 1.6 KB

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