searchkick 1.3.6 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -7
- data/CHANGELOG.md +6 -0
- data/README.md +8 -2
- data/lib/searchkick/index.rb +4 -0
- data/lib/searchkick/model.rb +29 -0
- data/lib/searchkick/query.rb +21 -1
- data/lib/searchkick/version.rb +1 -1
- data/test/autocomplete_test.rb +10 -0
- data/test/ci/before_install.sh +10 -13
- data/test/where_test.rb +15 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7ebf358ab6ac1ae3d08be867a20c9617a4ef0e9
|
4
|
+
data.tar.gz: 4935de64421b02b6a27505888f588c9e161f13f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfd3083681354eb0b1aab35d6b1f2d383326d8b6a2106af167b3f9cc9420ac974fec80c4dec30881e7e6903fb785a6492c643a14e36429bdb93fac21f0dc2193
|
7
|
+
data.tar.gz: 136e074de01969cb08fc54c35ee3468477b9d4612583510d327559fceee0218950e459b1228c32b3b5a54c60e81f3653ad7e22c0ab626a5193a9a355253bcc88
|
data/.travis.yml
CHANGED
@@ -24,7 +24,7 @@ gemfile:
|
|
24
24
|
- test/gemfiles/mongoid4.gemfile
|
25
25
|
- test/gemfiles/mongoid5.gemfile
|
26
26
|
env:
|
27
|
-
- ELASTICSEARCH_VERSION=2.4.
|
27
|
+
- ELASTICSEARCH_VERSION=2.4.1
|
28
28
|
matrix:
|
29
29
|
include:
|
30
30
|
- gemfile: Gemfile
|
@@ -34,11 +34,7 @@ matrix:
|
|
34
34
|
- gemfile: Gemfile
|
35
35
|
env: ELASTICSEARCH_VERSION=2.0.0
|
36
36
|
- gemfile: Gemfile
|
37
|
-
env: ELASTICSEARCH_VERSION=5.0.0
|
38
|
-
# - gemfile: test/gemfiles/nobrainer.gemfile
|
39
|
-
# env: NOBRAINER=true
|
37
|
+
env: ELASTICSEARCH_VERSION=5.0.0
|
40
38
|
allow_failures:
|
41
39
|
- gemfile: Gemfile
|
42
|
-
env: ELASTICSEARCH_VERSION=5.0.0
|
43
|
-
# - gemfile: test/gemfiles/nobrainer.gemfile
|
44
|
-
# env: NOBRAINER=true
|
40
|
+
env: ELASTICSEARCH_VERSION=5.0.0
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -44,7 +44,7 @@ Add this line to your application’s Gemfile:
|
|
44
44
|
gem 'searchkick'
|
45
45
|
```
|
46
46
|
|
47
|
-
For Elasticsearch
|
47
|
+
For Elasticsearch 5.0, use the version `1.4` and above. For Elasticsearch 2.0, use the version `1.0` and above.
|
48
48
|
|
49
49
|
Add searchkick to models you want to search.
|
50
50
|
|
@@ -852,6 +852,12 @@ Bounded by a box
|
|
852
852
|
City.search "san", where: {location: {top_left: {lat: 38, lon: -123}, bottom_right: {lat: 37, lon: -122}}}
|
853
853
|
```
|
854
854
|
|
855
|
+
Bounded by a polygon [master]
|
856
|
+
|
857
|
+
```ruby
|
858
|
+
City.search "san", where: {location: {geo_polygon: {points: [{lat: 38, lon: -123}, {lat: 39, lon: -123}, {lat: 37, lon: 122}]}}}
|
859
|
+
```
|
860
|
+
|
855
861
|
### Boost By Distance
|
856
862
|
|
857
863
|
Boost results by distance - closer results are boosted more
|
@@ -1046,7 +1052,7 @@ And create an initializer with:
|
|
1046
1052
|
|
1047
1053
|
```ruby
|
1048
1054
|
require "typhoeus/adapters/faraday"
|
1049
|
-
Ethon.logger = Logger
|
1055
|
+
Ethon.logger.level = Logger::WARN
|
1050
1056
|
```
|
1051
1057
|
|
1052
1058
|
**Note:** Typhoeus is not available for Windows.
|
data/lib/searchkick/index.rb
CHANGED
data/lib/searchkick/model.rb
CHANGED
@@ -69,6 +69,35 @@ module Searchkick
|
|
69
69
|
def searchkick_index_options
|
70
70
|
searchkick_index.index_options
|
71
71
|
end
|
72
|
+
|
73
|
+
def searchkick_debug
|
74
|
+
require "pp"
|
75
|
+
|
76
|
+
puts "Model Searchkick Options"
|
77
|
+
pp searchkick_options
|
78
|
+
puts
|
79
|
+
|
80
|
+
puts "Model Sample Search Data"
|
81
|
+
begin
|
82
|
+
pp first(3).map { |r| {index: searchkick_index.record_data(r).merge(data: searchkick_index.send(:search_data, r))}}
|
83
|
+
rescue => e
|
84
|
+
puts "#{e.class.name}: #{e.message}"
|
85
|
+
end
|
86
|
+
puts
|
87
|
+
|
88
|
+
puts "Elasticsearch Mapping"
|
89
|
+
puts JSON.pretty_generate(searchkick_index.mapping)
|
90
|
+
puts
|
91
|
+
|
92
|
+
puts "Elasticsearch Settings"
|
93
|
+
puts JSON.pretty_generate(searchkick_index.settings)
|
94
|
+
puts
|
95
|
+
|
96
|
+
puts "Elasticsearch Sample Results"
|
97
|
+
puts JSON.pretty_generate(search("*", load: false, limit: 3).response)
|
98
|
+
|
99
|
+
nil # do not return anything, as this is strictly used for manual debugging
|
100
|
+
end
|
72
101
|
end
|
73
102
|
extend Searchkick::Reindex # legacy for Searchjoy
|
74
103
|
|
data/lib/searchkick/query.rb
CHANGED
@@ -271,7 +271,21 @@ module Searchkick
|
|
271
271
|
qs.concat qs.map { |q| q.except(:cutoff_frequency).merge(fuzziness: edit_distance, prefix_length: prefix_length, max_expansions: max_expansions, boost: factor).merge(transpositions) }
|
272
272
|
end
|
273
273
|
|
274
|
-
|
274
|
+
# boost exact matches more
|
275
|
+
if field =~ /\.word_(start|middle|end)\z/ && searchkick_options[:word] != false
|
276
|
+
queries << {
|
277
|
+
bool: {
|
278
|
+
must: {
|
279
|
+
bool: {
|
280
|
+
should: qs.map { |q| {match_type => {field => q}} }
|
281
|
+
}
|
282
|
+
},
|
283
|
+
should: {match_type => {field.sub(/\.word_(start|middle|end)\z/, ".analyzed") => qs.first}}
|
284
|
+
}
|
285
|
+
}
|
286
|
+
else
|
287
|
+
queries.concat(qs.map { |q| {match_type => {field => q}} })
|
288
|
+
end
|
275
289
|
end
|
276
290
|
|
277
291
|
payload = {
|
@@ -748,6 +762,12 @@ module Searchkick
|
|
748
762
|
distance: value[:within] || "50mi"
|
749
763
|
}
|
750
764
|
}
|
765
|
+
when :geo_polygon
|
766
|
+
filters << {
|
767
|
+
geo_polygon: {
|
768
|
+
field => op_value
|
769
|
+
}
|
770
|
+
}
|
751
771
|
when :top_left
|
752
772
|
filters << {
|
753
773
|
geo_bounding_box: {
|
data/lib/searchkick/version.rb
CHANGED
data/test/autocomplete_test.rb
CHANGED
@@ -56,6 +56,16 @@ class AutocompleteTest < Minitest::Test
|
|
56
56
|
assert_search "dark grey", ["Dark Grey"], fields: [{name: :word_start}]
|
57
57
|
end
|
58
58
|
|
59
|
+
def test_word_start_exact
|
60
|
+
store_names ["Back Scratcher", "Backpack"]
|
61
|
+
assert_order "back", ["Back Scratcher", "Backpack"], fields: [{name: :word_start}]
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_word_start_exact_martin
|
65
|
+
store_names ["Martina", "Martin"]
|
66
|
+
assert_order "martin", ["Martin", "Martina"], fields: [{name: :word_start}]
|
67
|
+
end
|
68
|
+
|
59
69
|
# TODO find a better place
|
60
70
|
|
61
71
|
def test_exact
|
data/test/ci/before_install.sh
CHANGED
@@ -1,21 +1,18 @@
|
|
1
1
|
#!/usr/bin/env bash
|
2
2
|
|
3
|
+
set -e
|
4
|
+
|
3
5
|
gem install bundler
|
4
6
|
|
7
|
+
# https://docs.travis-ci.com/user/database-setup/#ElasticSearch
|
5
8
|
sudo apt-get purge elasticsearch
|
6
9
|
if [[ $ELASTICSEARCH_VERSION == 1* ]]; then
|
7
|
-
|
10
|
+
curl -O https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-$ELASTICSEARCH_VERSION.deb
|
11
|
+
elif [[ $ELASTICSEARCH_VERSION == 2* ]]; then
|
12
|
+
curl -O https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/$ELASTICSEARCH_VERSION/elasticsearch-$ELASTICSEARCH_VERSION.deb
|
8
13
|
else
|
9
|
-
|
10
|
-
fi
|
11
|
-
sudo dpkg -i elasticsearch-$ELASTICSEARCH_VERSION.deb
|
12
|
-
sudo service elasticsearch start
|
13
|
-
|
14
|
-
if [ -n "$NOBRAINER" ]; then
|
15
|
-
source /etc/lsb-release && echo "deb http://download.rethinkdb.com/apt $DISTRIB_CODENAME main" | sudo tee /etc/apt/sources.list.d/rethinkdb.list
|
16
|
-
wget -qO- http://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add -
|
17
|
-
sudo apt-get update -q
|
18
|
-
sudo apt-get install rethinkdb
|
19
|
-
sudo cp /etc/rethinkdb/default.conf.sample /etc/rethinkdb/instances.d/instance1.conf
|
20
|
-
sudo service rethinkdb restart
|
14
|
+
curl -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-$ELASTICSEARCH_VERSION.deb
|
21
15
|
fi
|
16
|
+
sudo dpkg -i --force-confnew elasticsearch-$ELASTICSEARCH_VERSION.deb
|
17
|
+
sudo service elasticsearch restart
|
18
|
+
sleep 10
|
data/test/where_test.rb
CHANGED
@@ -137,6 +137,21 @@ class WhereTest < Minitest::Test
|
|
137
137
|
assert_search "san", ["San Francisco", "San Antonio"], where: {location: {near: {lat: 37, lon: -122}, within: "2000mi"}}
|
138
138
|
end
|
139
139
|
|
140
|
+
def test_geo_polygon
|
141
|
+
store [
|
142
|
+
{name: "San Francisco", latitude: 37.7833, longitude: -122.4167},
|
143
|
+
{name: "San Antonio", latitude: 29.4167, longitude: -98.5000},
|
144
|
+
{name: "San Marino", latitude: 43.9333, longitude: 12.4667}
|
145
|
+
]
|
146
|
+
polygon = [
|
147
|
+
{lat: 42.185695, lon: -125.496146},
|
148
|
+
{lat: 42.185695, lon: -94.125535},
|
149
|
+
{lat: 27.122789, lon: -94.125535},
|
150
|
+
{lat: 27.12278, lon: -125.496146}
|
151
|
+
]
|
152
|
+
assert_search "san", ["San Francisco", "San Antonio"], where: {location: {geo_polygon: {points: polygon}}}
|
153
|
+
end
|
154
|
+
|
140
155
|
def test_top_left_bottom_right
|
141
156
|
store [
|
142
157
|
{name: "San Francisco", latitude: 37.7833, longitude: -122.4167},
|
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: 1.
|
4
|
+
version: 1.4.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: 2016-10-
|
11
|
+
date: 2016-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|