elasticsearch_autocomplete 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 033b837130dd4581eb9dbefe8b6424a5012f179c
4
- data.tar.gz: 517d306c4a96ba7da1693bf6591a662133028a06
3
+ metadata.gz: 4f9206e0ce061bd387b72955314aef688bf605d1
4
+ data.tar.gz: ee11adab330424718638a670f6b3ce13d0525750
5
5
  SHA512:
6
- metadata.gz: 141d423cb8d784bf259f4b4ef7026fce9804116bf7552525f9856638bb8cb44a8f78f870539322be926b55c1f6758d946ac0560c3783c822918faa167a9871cc
7
- data.tar.gz: be4c0e832e7a27c0f41243902c37d8531a3c42361af68e4eb50e732512cc51693086a0691ab9cadfa5442e84c86784bfb7bb3b3f33c25c424c035e9f1aa0e640
6
+ metadata.gz: a56d6e952ca07c36fc8d25f2ed7684061e7bb2345d694140937e8f3f5b728771973f153391e62145aec810020621766e0f1b2c5d860d00f3f823ebf0277d7e93
7
+ data.tar.gz: cf73bef59eabdd792c1c27d8b6dccc85ec1f3da6e38b5b0405e4ac285785b084947339e07cfa86a1e942a80949a0a350611c67921b1ec128c24a99eabea0c1a8
data/.gitignore CHANGED
@@ -21,4 +21,7 @@ tmp
21
21
  .rspec
22
22
  .ruby-version
23
23
  .ruby-gemset
24
- TODO
24
+ Vagrantfile
25
+ .vagrant
26
+ TODO
27
+ .byebug_history
@@ -1,12 +1,14 @@
1
- language: ruby
1
+ sudo: false
2
2
 
3
- services:
4
- - elasticsearch
3
+ language: ruby
5
4
 
6
- gemfile:
7
- - Gemfile
5
+ before_install:
6
+ - curl -s https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.0.0/elasticsearch-2.0.0.tar.gz > elasticsearch.tar.gz
7
+ - tar -xzf elasticsearch.tar.gz
8
+ - cd elasticsearch*/ && bin/elasticsearch &
9
+ - sleep 10 && curl http://localhost:9200
8
10
 
9
11
  rvm:
10
12
  - 1.9.3
11
- - 2.0.0
12
- - 2.1.5
13
+ - 2.3.0
14
+
@@ -9,6 +9,13 @@ module ElasticsearchAutocomplete
9
9
  mattr_accessor :enable_indexing
10
10
  self.enable_indexing = true
11
11
 
12
+ mattr_accessor :elasticsearch_version
13
+ self.elasticsearch_version = '2.x'
14
+
15
+ def self.es2?
16
+ elasticsearch_version && elasticsearch_version.start_with?('2')
17
+ end
18
+
12
19
  def self.default_index_prefix
13
20
  Object.const_defined?(:Rails) ? ::Rails.application.class.name.split('::').first.downcase : nil
14
21
  end
@@ -11,7 +11,7 @@ module ElasticsearchAutocomplete
11
11
 
12
12
  after_save :ac_update_index
13
13
  after_destroy :ac_update_index
14
-
14
+
15
15
  index_prefix ElasticsearchAutocomplete.defaults[:index_prefix] if ElasticsearchAutocomplete.defaults[:index_prefix]
16
16
  end
17
17
 
@@ -28,7 +28,7 @@ module ElasticsearchAutocomplete
28
28
  self.ac_mode_config = ElasticsearchAutocomplete::MODES[ac_opts[:mode]]
29
29
 
30
30
  self.ac_search_attrs = ac_opts[:search_fields] || (ac_opts[:localized] ? I18n.available_locales.map { |l| "#{ac_attr}_#{l}" } : [ac_attr])
31
- self.ac_search_fields = ac_search_attrs.map { |attr| ac_mode_config.values.map { |prefix| "#{prefix}_#{attr}" } }.flatten
31
+ self.ac_search_fields = ac_search_attrs.map { |attr| ac_mode_config.values.map { |prefix| "#{attr}.#{prefix}_#{attr}" } }.flatten
32
32
 
33
33
  define_ac_index(ac_opts[:mode]) unless options[:skip_settings]
34
34
  end
@@ -57,6 +57,14 @@ module ElasticsearchAutocomplete
57
57
  end
58
58
 
59
59
  filter(:and, filters: options[:with].map { |k, v| {terms: {k => ElasticsearchAutocomplete.val_to_terms(v)}} }) if options[:with].present?
60
+
61
+ if options[:or].present?
62
+ or_filters = Array(options[:or]).map do |filter|
63
+ {and: filter.map {|k, v| {terms: {k => ElasticsearchAutocomplete.val_to_terms(v)}}}}
64
+ end
65
+ filter(:or, or_filters)
66
+ end
67
+
60
68
  if options[:without].present?
61
69
  options[:without].each do |k, v|
62
70
  filter(:not, {terms: {k => ElasticsearchAutocomplete.val_to_terms(v, true)}})
@@ -78,23 +86,24 @@ module ElasticsearchAutocomplete
78
86
 
79
87
  def ac_index_config(attr, mode=:word)
80
88
  defaults = {type: 'string', search_analyzer: 'ac_search', include_in_all: false}
89
+ index_analyzer_key = ElasticsearchAutocomplete.es2? ? :analyzer : :index_analyzer
81
90
  fields = case mode
82
91
  when :word
83
92
  {
84
93
  attr => {type: 'string'},
85
- "#{ac_mode_config[:base]}_#{attr}" => defaults.merge(index_analyzer: 'ac_edge_ngram'),
86
- "#{ac_mode_config[:word]}_#{attr}" => defaults.merge(index_analyzer: 'ac_edge_ngram_word')
94
+ "#{ac_mode_config[:base]}_#{attr}" => defaults.merge(index_analyzer_key => 'ac_edge_ngram'),
95
+ "#{ac_mode_config[:word]}_#{attr}" => defaults.merge(index_analyzer_key => 'ac_edge_ngram_word')
87
96
  }
88
97
  when :phrase
89
98
  {
90
99
  attr => {type: 'string'},
91
- "#{ac_mode_config[:base]}_#{attr}" => defaults.merge(index_analyzer: 'ac_edge_ngram')
100
+ "#{ac_mode_config[:base]}_#{attr}" => defaults.merge(index_analyzer_key => 'ac_edge_ngram')
92
101
  }
93
102
  when :full
94
103
  {
95
104
  attr => {type: 'string'},
96
- "#{ac_mode_config[:base]}_#{attr}" => defaults.merge(index_analyzer: 'ac_edge_ngram', boost: 3),
97
- "#{ac_mode_config[:full]}_#{attr}" => defaults.merge(index_analyzer: 'ac_edge_ngram_full')
105
+ "#{ac_mode_config[:base]}_#{attr}" => defaults.merge(index_analyzer_key => 'ac_edge_ngram', boost: 3),
106
+ "#{ac_mode_config[:full]}_#{attr}" => defaults.merge(index_analyzer_key => 'ac_edge_ngram_full')
98
107
  }
99
108
  end
100
109
  {type: 'multi_field', fields: fields}
@@ -1,3 +1,3 @@
1
1
  module ElasticsearchAutocomplete
2
- VERSION = '0.1.5'
2
+ VERSION = '0.1.6'
3
3
  end
@@ -35,6 +35,11 @@ describe 'search filters' do
35
35
  @model.setup_index
36
36
  end
37
37
 
38
+ it 'filter suggestions with or terms' do
39
+ expect(@model.ac_search('Laura', or: [{interest_ids: [1]}, {interest_ids: '4'}]).map(&:full_name)).to\
40
+ match_array ['Laura Nelson', 'Laura Larson']
41
+ end
42
+
38
43
  it 'filter suggestions with terms' do
39
44
  expect(@model.ac_search('Laura', with: {interest_ids: [2]}).map(&:full_name)).to match_array ['Laura Nelson', 'Laura Flores']
40
45
  end
@@ -62,8 +67,8 @@ describe 'search filters' do
62
67
  end
63
68
 
64
69
  it 'paginate suggestions' do
65
- res = @model.ac_search('Laura', per_page: 1, page: 2).to_a
70
+ res = @model.ac_search('Laura', order: :id, per_page: 1, page: 2).to_a
66
71
  expect(res.length).to eq 1
67
72
  expect(res.first.full_name).to eq 'Laura Flores'
68
73
  end
69
- end
74
+ end
@@ -4,13 +4,15 @@ require 'active_support/core_ext'
4
4
  require 'elasticsearch_autocomplete'
5
5
 
6
6
  Tire.configure do
7
- #logger 'tmp/elasticsearch.log' # Commented out logger line here so that it doesn't break specs when tmp directory doesn't exist.
8
- url 'http://localhost:9200'
7
+ # logger 'tmp/elasticsearch.log' # Commented out logger line here so that it doesn't break specs when tmp directory doesn't exist.
8
+ url "http://localhost:#{ENV['ES_PORT'] || 9200}"
9
9
  pretty 1
10
10
  end
11
11
 
12
12
  I18n.available_locales = [:en, :ru]
13
13
 
14
+ # ElasticsearchAutocomplete.elasticsearch_version = '1.x'
15
+
14
16
  class ActiveModelBase
15
17
  include ActiveModel::AttributeMethods
16
18
  include ActiveModel::Serialization
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch_autocomplete
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Leschenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-21 00:00:00.000000000 Z
11
+ date: 2016-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tire
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  version: '0'
127
127
  requirements: []
128
128
  rubyforge_project:
129
- rubygems_version: 2.4.3
129
+ rubygems_version: 2.5.1
130
130
  signing_key:
131
131
  specification_version: 4
132
132
  summary: Elasticsearch autocomplete for models