searchkick 0.7.9 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +21 -8
- data/lib/searchkick.rb +4 -0
- data/lib/searchkick/query.rb +20 -10
- data/lib/searchkick/search.rb +1 -1
- data/lib/searchkick/version.rb +1 -1
- data/searchkick.gemspec +1 -1
- data/test/match_test.rb +9 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d97f04a7f7678a643933cfd0045ec2e6043ebf02
|
4
|
+
data.tar.gz: c817fb9f49a0b6526beb3a2a2d5266c451258cfe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c19441dd8e684d5c1d0b4613dce000535dbd527ff35fce233bcdaba960037c9ec2853c1539ce8b038f3880a30c0a2be7717363f87be93b0789440718509c8c8c
|
7
|
+
data.tar.gz: 247238fb70ade1d5ce6eeff5ddd3c0bf590bec9bb52e8e746fe12db58ffb7bf5bdde5f6385bc4167b8dd67bc151724b215253b15755e1cb75f30ec07fac1c025
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -45,12 +45,6 @@ Add this line to your application’s Gemfile:
|
|
45
45
|
gem 'searchkick'
|
46
46
|
```
|
47
47
|
|
48
|
-
For Elasticsearch 1.2, use:
|
49
|
-
|
50
|
-
```ruby
|
51
|
-
gem 'searchkick', github: 'ankane/searchkick', branch: 'elasticsearch-1.2'
|
52
|
-
```
|
53
|
-
|
54
48
|
For Elasticsearch 0.90, use version `0.6.3` and [this readme](https://github.com/ankane/searchkick/blob/v0.6.3/README.md).
|
55
49
|
|
56
50
|
Add searchkick to models you want to search.
|
@@ -161,11 +155,20 @@ Plays nicely with kaminari and will_paginate.
|
|
161
155
|
```ruby
|
162
156
|
# controller
|
163
157
|
@products = Product.search "milk", page: params[:page], per_page: 20
|
158
|
+
```
|
159
|
+
|
160
|
+
View with kaminari
|
164
161
|
|
165
|
-
|
162
|
+
```erb
|
166
163
|
<%= paginate @products %>
|
167
164
|
```
|
168
165
|
|
166
|
+
View with will_paginate
|
167
|
+
|
168
|
+
```erb
|
169
|
+
<%= will_paginate @products %>
|
170
|
+
```
|
171
|
+
|
169
172
|
### Partial Matches
|
170
173
|
|
171
174
|
By default, results must match all words in the query.
|
@@ -215,7 +218,7 @@ fields: [{"name^2" => :word_start}] # better interface on the way
|
|
215
218
|
### Exact Matches
|
216
219
|
|
217
220
|
```ruby
|
218
|
-
User.search "hi@searchkick.org", fields: [{email: :exact}]
|
221
|
+
User.search "hi@searchkick.org", fields: [{email: :exact}, :name]
|
219
222
|
```
|
220
223
|
|
221
224
|
### Language
|
@@ -640,6 +643,16 @@ Then deploy and reindex:
|
|
640
643
|
rake searchkick:reindex CLASS=Product
|
641
644
|
```
|
642
645
|
|
646
|
+
### Performance
|
647
|
+
|
648
|
+
For the best performance, add [Patron](https://github.com/toland/patron) to your Gemfile.
|
649
|
+
|
650
|
+
```ruby
|
651
|
+
gem 'patron'
|
652
|
+
```
|
653
|
+
|
654
|
+
**Note:** Patron is not available for Windows.
|
655
|
+
|
643
656
|
### Automatic Failover
|
644
657
|
|
645
658
|
Create an initializer `config/initializers/elasticsearch.rb` with multiple hosts:
|
data/lib/searchkick.rb
CHANGED
data/lib/searchkick/query.rb
CHANGED
@@ -6,7 +6,7 @@ module Searchkick
|
|
6
6
|
def initialize(klass, term, options = {})
|
7
7
|
if term.is_a?(Hash)
|
8
8
|
options = term
|
9
|
-
term =
|
9
|
+
term = "*"
|
10
10
|
else
|
11
11
|
term = term.to_s
|
12
12
|
end
|
@@ -15,6 +15,8 @@ module Searchkick
|
|
15
15
|
@term = term
|
16
16
|
@options = options
|
17
17
|
|
18
|
+
below12 = Gem::Version.new(Searchkick.server_version) < Gem::Version.new("1.2")
|
19
|
+
|
18
20
|
boost_fields = {}
|
19
21
|
fields =
|
20
22
|
if options[:fields]
|
@@ -127,6 +129,13 @@ module Searchkick
|
|
127
129
|
|
128
130
|
if conversions_field and options[:conversions] != false
|
129
131
|
# wrap payload in a bool query
|
132
|
+
script_score =
|
133
|
+
if below12
|
134
|
+
{script_score: {script: "doc['count'].value"}}
|
135
|
+
else
|
136
|
+
{field_value_factor: {field: "count"}}
|
137
|
+
end
|
138
|
+
|
130
139
|
payload = {
|
131
140
|
bool: {
|
132
141
|
must: payload,
|
@@ -141,11 +150,8 @@ module Searchkick
|
|
141
150
|
match: {
|
142
151
|
query: term
|
143
152
|
}
|
144
|
-
},
|
145
|
-
script_score: {
|
146
|
-
script: "doc['count'].value"
|
147
153
|
}
|
148
|
-
}
|
154
|
+
}.merge(script_score)
|
149
155
|
}
|
150
156
|
}
|
151
157
|
}
|
@@ -165,16 +171,20 @@ module Searchkick
|
|
165
171
|
end
|
166
172
|
|
167
173
|
boost_by.each do |field, value|
|
174
|
+
script_score =
|
175
|
+
if below12
|
176
|
+
{script_score: {script: "#{value[:factor].to_f} * log(doc['#{field}'].value + 2.718281828)"}}
|
177
|
+
else
|
178
|
+
{field_value_factor: {field: field, factor: value[:factor].to_f, modifier: "ln2p"}}
|
179
|
+
end
|
180
|
+
|
168
181
|
custom_filters << {
|
169
182
|
filter: {
|
170
183
|
exists: {
|
171
184
|
field: field
|
172
185
|
}
|
173
|
-
},
|
174
|
-
script_score: {
|
175
|
-
script: "#{value[:factor].to_f} * log(doc['#{field}'].value + 2.718281828)"
|
176
186
|
}
|
177
|
-
}
|
187
|
+
}.merge(script_score)
|
178
188
|
end
|
179
189
|
|
180
190
|
boost_where = options[:boost_where] || {}
|
@@ -370,7 +380,7 @@ module Searchkick
|
|
370
380
|
e.message.include?("No query registered for [function_score]]")
|
371
381
|
)
|
372
382
|
|
373
|
-
raise UnsupportedVersionError, "This version of Searchkick requires Elasticsearch 0
|
383
|
+
raise UnsupportedVersionError, "This version of Searchkick requires Elasticsearch 1.0 or greater"
|
374
384
|
elsif status_code == 400
|
375
385
|
if e.message.include?("[multi_match] analyzer [searchkick_search] not found")
|
376
386
|
raise InvalidQueryError, "Bad mapping - run #{searchkick_klass.name}.reindex"
|
data/lib/searchkick/search.rb
CHANGED
data/lib/searchkick/version.rb
CHANGED
data/searchkick.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency "activemodel"
|
22
|
-
spec.add_dependency "elasticsearch", "
|
22
|
+
spec.add_dependency "elasticsearch", ">= 1"
|
23
23
|
spec.add_dependency "hashie"
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.3"
|
data/test/match_test.rb
CHANGED
@@ -139,6 +139,15 @@ class TestMatch < Minitest::Unit::TestCase
|
|
139
139
|
assert_search "*", ["Product A", "Product B"]
|
140
140
|
end
|
141
141
|
|
142
|
+
def test_no_arguments
|
143
|
+
assert_equal [], Product.search.to_a
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_no_term
|
147
|
+
store_names ["Product A"]
|
148
|
+
assert_equal ["Product A"], Product.search(where: {name: "Product A"}).map(&:name)
|
149
|
+
end
|
150
|
+
|
142
151
|
def test_to_be_or_not_to_be
|
143
152
|
store_names ["to be or not to be"]
|
144
153
|
assert_search "to be", ["to be or not to be"]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: searchkick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: elasticsearch
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: hashie
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|