elasticsearch_autocomplete 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -75,37 +75,41 @@ module ElasticsearchAutocomplete
75
75
  ElasticsearchAutocomplete::MODES[ac_opts[:mode]]
76
76
  end
77
77
 
78
- private
79
-
80
78
  def define_ac_index(mode=:word)
81
- mode_config = ac_mode_config
79
+ model = self
82
80
  settings ElasticsearchAutocomplete::Analyzers::AC_BASE do
83
81
  mapping do
84
82
  ac_search_attrs.each do |attr|
85
- case mode
86
- when :word
87
- indexes attr, :type => 'multi_field', :fields => {
88
- attr => {:type => 'string'},
89
- "#{mode_config[:base]}_#{attr}" => {:type => 'string', :index_analyzer => 'ac_edge_ngram', :search_analyzer => 'ac_search', :include_in_all => false},
90
- "#{mode_config[:word]}_#{attr}" => {:type => 'string', :index_analyzer => 'ac_edge_ngram_word', :search_analyzer => 'ac_search', :include_in_all => false}
91
- }
92
- when :phrase
93
- indexes attr, :type => 'multi_field', :fields => {
94
- attr => {:type => 'string'},
95
- "#{mode_config[:base]}_#{attr}" => {:type => 'string', :index_analyzer => 'ac_edge_ngram', :search_analyzer => 'ac_search', :include_in_all => false},
96
- }
97
- when :full
98
- indexes attr, :type => 'multi_field', :fields => {
99
- attr => {:type => 'string'},
100
- "#{mode_config[:base]}_#{attr}" => {:type => 'string', :index_analyzer => 'ac_edge_ngram', :search_analyzer => 'ac_search', :include_in_all => false, :boost => 3},
101
- "#{mode_config[:full]}_#{attr}" => {:type => 'string', :index_analyzer => 'ac_edge_ngram_full', :search_analyzer => 'ac_search', :include_in_all => false}
102
- }
103
- end
83
+ indexes attr, model.ac_index_config(attr, mode)
104
84
  end
105
85
  end
106
86
  end
107
87
  end
108
88
 
89
+ def ac_index_config(attr, mode=:word)
90
+ defaults = {:type => 'string', :search_analyzer => 'ac_search', :include_in_all => false}
91
+ fields = case mode
92
+ when :word
93
+ {
94
+ attr => {:type => 'string'},
95
+ "#{ac_mode_config[:base]}_#{attr}" => defaults.merge(:index_analyzer => 'ac_edge_ngram'),
96
+ "#{ac_mode_config[:word]}_#{attr}" => defaults.merge(:index_analyzer => 'ac_edge_ngram_word')
97
+ }
98
+ when :phrase
99
+ {
100
+ attr => {:type => 'string'},
101
+ "#{ac_mode_config[:base]}_#{attr}" => defaults.merge(:index_analyzer => 'ac_edge_ngram')
102
+ }
103
+ when :full
104
+ {
105
+ attr => {:type => 'string'},
106
+ "#{ac_mode_config[:base]}_#{attr}" => defaults.merge(:index_analyzer => 'ac_edge_ngram', :boost => 3),
107
+ "#{ac_mode_config[:full]}_#{attr}" => defaults.merge(:index_analyzer => 'ac_edge_ngram_full')
108
+ }
109
+ end
110
+ {:type => 'multi_field', :fields => fields}
111
+ end
112
+
109
113
  def ac_search_fields
110
114
  @ac_search_fields ||= ac_search_attrs.map { |attr| ac_mode_config.values.map { |prefix| "#{prefix}_#{attr}" } }.flatten
111
115
  end
@@ -1,3 +1,3 @@
1
1
  module ElasticsearchAutocomplete
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: elasticsearch_autocomplete
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 0.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Alex Leschenko
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-28 00:00:00.000000000 Z
12
+ date: 2013-02-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  version_requirements: !ruby/object:Gem::Requirement
@@ -114,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
114
  version: '0'
115
115
  segments:
116
116
  - 0
117
- hash: -638938333914231974
117
+ hash: 1402164139427117718
118
118
  none: false
119
119
  required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  requirements:
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  segments:
125
125
  - 0
126
- hash: -638938333914231974
126
+ hash: 1402164139427117718
127
127
  none: false
128
128
  requirements: []
129
129
  rubyforge_project: