searchkick 1.3.6 → 1.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2665e44b0bd2b8e4bcceb5d9963acb49505914bb
4
- data.tar.gz: f44ddcee8dd2b1ff0607aac73243a36a458179c5
3
+ metadata.gz: f7ebf358ab6ac1ae3d08be867a20c9617a4ef0e9
4
+ data.tar.gz: 4935de64421b02b6a27505888f588c9e161f13f0
5
5
  SHA512:
6
- metadata.gz: ea59d44e55010236af8b16a1c3b1d7e7f160081f137cbdd44e298d291c6ae84a966be25a405f21f970885f07c73bf6e76c6e56edf29cba234c2ba308b6ba5241
7
- data.tar.gz: 28c80bb3061751507605bebf0a4dacb541a4f8cfd6b98156c3cbfad2aa9de03c916aa12715bc47769a3a79b154d82f4c2bc901d34a7d314e57f2ac0d96fe5ee4
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.0
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-beta1
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-beta1
43
- # - gemfile: test/gemfiles/nobrainer.gemfile
44
- # env: NOBRAINER=true
40
+ env: ELASTICSEARCH_VERSION=5.0.0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 1.4.0
2
+
3
+ - Boost exact matches for partial matching
4
+ - Added `searchkick_debug` method
5
+ - Added `geo_polygon` filter
6
+
1
7
  ## 1.3.6
2
8
 
3
9
  - Fixed `Job adapter not found` error
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 2.0, use the version `1.0` and above. For Elasticsearch 0.90, use version `0.6.3` and [this readme](https://github.com/ankane/searchkick/blob/v0.6.3/README.md).
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.new("/dev/null")
1055
+ Ethon.logger.level = Logger::WARN
1050
1056
  ```
1051
1057
 
1052
1058
  **Note:** Typhoeus is not available for Windows.
@@ -33,6 +33,10 @@ module Searchkick
33
33
  client.indices.get_mapping index: name
34
34
  end
35
35
 
36
+ def settings
37
+ client.indices.get_settings index: name
38
+ end
39
+
36
40
  def swap(new_name)
37
41
  old_indices =
38
42
  begin
@@ -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
 
@@ -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
- queries.concat(qs.map { |q| {match_type => {field => q}} })
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: {
@@ -1,3 +1,3 @@
1
1
  module Searchkick
2
- VERSION = "1.3.6"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -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
@@ -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
- wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-$ELASTICSEARCH_VERSION.deb
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
- wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/$ELASTICSEARCH_VERSION/elasticsearch-$ELASTICSEARCH_VERSION.deb
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.3.6
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-08 00:00:00.000000000 Z
11
+ date: 2016-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel