elasticsearch_autocomplete 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/elasticsearch_autocomplete.gemspec +1 -0
- data/lib/elasticsearch_autocomplete.rb +3 -1
- data/lib/elasticsearch_autocomplete/model_addition.rb +2 -2
- data/lib/elasticsearch_autocomplete/version.rb +1 -1
- data/spec/elasticsearch_autocomplete/base_spec.rb +34 -0
- data/spec/spec_helper.rb +2 -5
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a87e3e5a235180354eabcb8fb4ed51c88e79152a
|
4
|
+
data.tar.gz: 597ba4146d2e445899a3aafd2e3a91137e64e350
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 675ae4a73d7bed41485d2db1dcf189ef7f531b5d64cb9efa1c8ed7f01b7de2bf21b9a3880440ea2c5a0c2a6cfbc78198e291a8579767e78d6cd2115a2930ca89
|
7
|
+
data.tar.gz: f120c92b1e5b9c091bf9b3ac3bac6bc9ae0cfc2c9416032f1ecbaae15e122691a0bdcda30c8fdd4410ebfaf8cee5591f410cec21ae2ff04a039950a76ccc5cd8
|
data/README.md
CHANGED
@@ -63,7 +63,7 @@ class Product < ActiveRecord::Base
|
|
63
63
|
end
|
64
64
|
```
|
65
65
|
|
66
|
-
If you
|
66
|
+
If you want to define settings and mapping for elasticsearch index yourselves:
|
67
67
|
|
68
68
|
```ruby
|
69
69
|
class Product < ActiveRecord::Base
|
@@ -19,9 +19,11 @@ module ElasticsearchAutocomplete
|
|
19
19
|
:full => {:base => 'ac', :full => 'ac_full'}
|
20
20
|
}
|
21
21
|
|
22
|
-
def self.
|
22
|
+
def self.val_to_terms(val, zero=false)
|
23
23
|
return [] unless val
|
24
24
|
return val if val.is_a?(Array)
|
25
|
+
return [true] if val == 'true'
|
26
|
+
return [false] if val == 'false'
|
25
27
|
a = val.to_s.split(',').map(&:to_i)
|
26
28
|
zero ? a : a.reject(&:zero?)
|
27
29
|
end
|
@@ -58,10 +58,10 @@ module ElasticsearchAutocomplete
|
|
58
58
|
by(options[:order], options[:sort_mode] || 'asc') if options[:order].present?
|
59
59
|
end
|
60
60
|
|
61
|
-
filter(:and, :filters => options[:with].map { |k, v| {:terms => {k => ElasticsearchAutocomplete.
|
61
|
+
filter(:and, :filters => options[:with].map { |k, v| {:terms => {k => ElasticsearchAutocomplete.val_to_terms(v)}} }) if options[:with].present?
|
62
62
|
if options[:without].present?
|
63
63
|
options[:without].each do |k, v|
|
64
|
-
filter(:not, {:terms => {k => ElasticsearchAutocomplete.
|
64
|
+
filter(:not, {:terms => {k => ElasticsearchAutocomplete.val_to_terms(v, true)}})
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
@@ -66,6 +66,40 @@ describe ElasticsearchAutocomplete do
|
|
66
66
|
results.map{|x| x.is_a?(ActiveModelUser).should == true }
|
67
67
|
end
|
68
68
|
end
|
69
|
+
|
70
|
+
describe '#val_to_terms' do
|
71
|
+
it 'empty array if argument is blank' do
|
72
|
+
ElasticsearchAutocomplete.val_to_terms(nil).should == []
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'array if argument is array' do
|
76
|
+
ElasticsearchAutocomplete.val_to_terms([1, 2]).should == [1, 2]
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'comma separated values' do
|
80
|
+
ElasticsearchAutocomplete.val_to_terms('1,2').should == [1, 2]
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'skip zero' do
|
84
|
+
it 'skip zero by default' do
|
85
|
+
ElasticsearchAutocomplete.val_to_terms('0,1,2').should == [1, 2]
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'include zero' do
|
89
|
+
ElasticsearchAutocomplete.val_to_terms('0,1,2', true).should == [0, 1, 2]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'boolean' do
|
94
|
+
it 'true value' do
|
95
|
+
ElasticsearchAutocomplete.val_to_terms('true').should == [true]
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'false value' do
|
99
|
+
ElasticsearchAutocomplete.val_to_terms('false').should == [false]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
69
103
|
end
|
70
104
|
|
71
105
|
shared_examples 'basic autocomplete' do |model|
|
data/spec/spec_helper.rb
CHANGED
@@ -38,14 +38,11 @@ class ActiveModelBase
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def save
|
41
|
-
|
42
|
-
end
|
41
|
+
run_callbacks(:save) {}
|
43
42
|
end
|
44
43
|
|
45
44
|
def destroy
|
46
|
-
|
47
|
-
@destroyed = true
|
48
|
-
end
|
45
|
+
run_callbacks(:destroy) { @destroyed = true }
|
49
46
|
end
|
50
47
|
|
51
48
|
def destroyed?
|
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.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Leschenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tire
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activerecord
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.2'
|
69
83
|
description: Simple autocomplete for your models using awesome elasticsearch and tire
|
70
84
|
gem
|
71
85
|
email:
|