searchkick 2.2.1 → 2.3.0

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: e592f63efa26867238f106cdede925736897c39e
4
- data.tar.gz: b873c66a18f69cffcd9227fe92a1cf314e602090
3
+ metadata.gz: 92b9786d3ffe96d4accab83ae00accbaa5b2ffb3
4
+ data.tar.gz: 9b60f5ab8f709d9138cbe4823b14d29a06e4aa77
5
5
  SHA512:
6
- metadata.gz: 74566048b5471575f1c7f2e269a6fa23fa62dbbd717696a077a26875f43883be128cbbb731578634ec948c51a5e9d336ed3595ea631717ac3056f784c813f19c
7
- data.tar.gz: 5c1a40b9633f70201a13e003a1852d5a3cfcf0d16d23024cea19ddce523b2f32e5675119e5899b1b4c3e7f057466cd09a80a788a655933923a78172b5b95ebb0
6
+ metadata.gz: f8e3324376e90052bbf854fe3d04200857d06ac6cde06bea08ee2fe573462de243d558ed1d0592d92b7794d5c1fd761f396812c4ea09ff5fce1e30cdac2119a8
7
+ data.tar.gz: c5bc1d098f59c17945af081727ef92cd7d297cfebe3f0acd1c5401dd95bca71a208c10208b07f7d473e9e387fc37f4643c8dc9b373dec2006c4507f30c598808
data/.travis.yml CHANGED
@@ -6,7 +6,7 @@ services:
6
6
  - redis-server
7
7
  before_install:
8
8
  - ./test/ci/before_install.sh
9
- script: RUBYOPT=W0 bundle exec rake test
9
+ script: bundle exec rake test
10
10
  before_script:
11
11
  - psql -c 'create database searchkick_test;' -U postgres
12
12
  notifications:
@@ -15,11 +15,12 @@ notifications:
15
15
  on_failure: change
16
16
  gemfile:
17
17
  - Gemfile
18
+ - test/gemfiles/activerecord50.gemfile
18
19
  - test/gemfiles/activerecord42.gemfile
19
20
  - test/gemfiles/mongoid5.gemfile
20
21
  - test/gemfiles/mongoid6.gemfile
21
22
  env:
22
- - ELASTICSEARCH_VERSION=5.3.0
23
+ - ELASTICSEARCH_VERSION=5.4.0
23
24
  jdk: oraclejdk8
24
25
  matrix:
25
26
  include:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 2.3.0
2
+
3
+ - Fixed analyzer on dynamically mapped fields
4
+ - Fixed error with `similar` method and `_all` field
5
+ - Throw error when fields are needed
6
+ - Added `queue_name` option
7
+ - No longer require synonyms to be lowercase
8
+
1
9
  ## 2.2.1
2
10
 
3
11
  - Added `avg`, `cardinality`, `max`, `min`, and `sum` aggregations
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  gem "sqlite3"
7
- gem "activerecord", "~> 5.0.0"
7
+ gem "activerecord", "~> 5.1.0"
8
8
  gem "gemoji-parser"
9
9
  gem "typhoeus"
10
10
  gem "activejob"
data/README.md CHANGED
@@ -27,8 +27,6 @@ Plus:
27
27
 
28
28
  [![Build Status](https://travis-ci.org/ankane/searchkick.svg?branch=master)](https://travis-ci.org/ankane/searchkick)
29
29
 
30
- **Searchkick 2.0 was just released!** See [notable changes](#200).
31
-
32
30
  ## Contents
33
31
 
34
32
  - [Getting Started](#getting-started)
@@ -1606,12 +1604,18 @@ Set a lower timeout for searches
1606
1604
  Searchkick.search_timeout = 3
1607
1605
  ```
1608
1606
 
1609
- Change the search method name in `config/initializers/searchkick.rb`
1607
+ Change the search method name
1610
1608
 
1611
1609
  ```ruby
1612
1610
  Searchkick.search_method_name = :lookup
1613
1611
  ```
1614
1612
 
1613
+ Change search queue name
1614
+
1615
+ ```ruby
1616
+ Searchkick.queue_name = :search_reindex
1617
+ ```
1618
+
1615
1619
  Eager load associations
1616
1620
 
1617
1621
  ```ruby
@@ -1763,11 +1767,25 @@ end
1763
1767
 
1764
1768
  ### Factory Girl
1765
1769
 
1766
- Manually reindex after an instance is created.
1770
+ Use a trait and an after `create` hook for each indexed model:
1767
1771
 
1768
1772
  ```ruby
1769
- product = FactoryGirl.create(:product)
1770
- product.reindex(refresh: true)
1773
+ FactoryGirl.define do
1774
+ factory :product do
1775
+ # ...
1776
+
1777
+ # Note: This should be the last trait in the list so `reindex` is called
1778
+ # after all the other callbacks complete.
1779
+ trait :reindex do
1780
+ after(:create) do |product, _evaluator|
1781
+ product.reindex(refresh: true)
1782
+ end
1783
+ end
1784
+ end
1785
+ end
1786
+
1787
+ # use it
1788
+ FactoryGirl.create(:product, :some_trait, :reindex, some_attribute: "foo")
1771
1789
  ```
1772
1790
 
1773
1791
  ### Parallel Tests
@@ -167,7 +167,7 @@ module Searchkick
167
167
  if synonyms.any?
168
168
  settings[:analysis][:filter][:searchkick_synonym] = {
169
169
  type: "synonym",
170
- synonyms: synonyms.select { |s| s.size > 1 }.map { |s| s.is_a?(Array) ? s.join(",") : s }
170
+ synonyms: synonyms.select { |s| s.size > 1 }.map { |s| s.is_a?(Array) ? s.join(",") : s }.map(&:downcase)
171
171
  }
172
172
  # choosing a place for the synonym filter when stemming is not easy
173
173
  # https://groups.google.com/forum/#!topic/elasticsearch/p7qcQlgHdB8
@@ -229,6 +229,8 @@ module Searchkick
229
229
 
230
230
  mapping_options[:searchable].delete("_all")
231
231
 
232
+ analyzed_field_options = {type: default_type, index: "analyzed", analyzer: default_analyzer}
233
+
232
234
  mapping_options.values.flatten.uniq.each do |field|
233
235
  fields = {}
234
236
 
@@ -240,7 +242,7 @@ module Searchkick
240
242
 
241
243
  if !options[:searchable] || mapping_options[:searchable].include?(field)
242
244
  if word
243
- fields["analyzed"] = {type: default_type, index: "analyzed", analyzer: default_analyzer}
245
+ fields["analyzed"] = analyzed_field_options
244
246
 
245
247
  if mapping_options[:highlight].include?(field)
246
248
  fields["analyzed"][:term_vector] = "with_positions_offsets"
@@ -294,7 +296,7 @@ module Searchkick
294
296
  end
295
297
 
296
298
  if word
297
- dynamic_fields["analyzed"] = {type: default_type, index: "analyzed"}
299
+ dynamic_fields["analyzed"] = analyzed_field_options
298
300
  end
299
301
  end
300
302
 
@@ -305,7 +307,7 @@ module Searchkick
305
307
 
306
308
  mappings = {
307
309
  _default_: {
308
- _all: all_enabled ? {type: default_type, index: "analyzed", analyzer: default_analyzer} : {enabled: false},
310
+ _all: all_enabled ? analyzed_field_options : {enabled: false},
309
311
  properties: mapping,
310
312
  _routing: routing,
311
313
  # https://gist.github.com/kimchy/2898285
@@ -223,13 +223,15 @@ module Searchkick
223
223
  if options[:similar]
224
224
  payload = {
225
225
  more_like_this: {
226
- fields: fields,
227
226
  like_text: term,
228
227
  min_doc_freq: 1,
229
228
  min_term_freq: 1,
230
229
  analyzer: "searchkick_search2"
231
230
  }
232
231
  }
232
+ if fields != ["_all"]
233
+ payload[:more_like_this][:fields] = fields
234
+ end
233
235
  elsif all
234
236
  payload = {
235
237
  match_all: {}
@@ -277,7 +279,13 @@ module Searchkick
277
279
 
278
280
  match_type =
279
281
  if field.end_with?(".phrase")
280
- field = field.sub(/\.phrase\z/, ".analyzed")
282
+ field =
283
+ if field == "_all.phrase"
284
+ "_all"
285
+ else
286
+ field.sub(/\.phrase\z/, ".analyzed")
287
+ end
288
+
281
289
  :match_phrase
282
290
  else
283
291
  :match
@@ -482,17 +490,22 @@ module Searchkick
482
490
  def set_fields
483
491
  boost_fields = {}
484
492
  fields = options[:fields] || searchkick_options[:searchable]
493
+ default_match = options[:match] || searchkick_options[:match] || :word
485
494
  fields =
486
495
  if fields
487
496
  fields.map do |value|
488
- k, v = value.is_a?(Hash) ? value.to_a.first : [value, options[:match] || searchkick_options[:match] || :word]
497
+ k, v = value.is_a?(Hash) ? value.to_a.first : [value, default_match]
489
498
  k2, boost = k.to_s.split("^", 2)
490
499
  field = "#{k2}.#{v == :word ? 'analyzed' : v}"
491
500
  boost_fields[field] = boost.to_f if boost
492
501
  field
493
502
  end
494
- else
503
+ elsif default_match == :word
495
504
  ["_all"]
505
+ elsif default_match == :phrase
506
+ ["_all.phrase"]
507
+ else
508
+ raise ArgumentError, "Must specify fields"
496
509
  end
497
510
  [boost_fields, fields]
498
511
  end
@@ -7,7 +7,7 @@ module Searchkick
7
7
  "Cequel::Record::RecordNotFound"
8
8
  ]
9
9
 
10
- queue_as :searchkick
10
+ queue_as { Searchkick.queue_name }
11
11
 
12
12
  def perform(klass, id)
13
13
  model = klass.constantize
@@ -1,3 +1,3 @@
1
1
  module Searchkick
2
- VERSION = "2.2.1"
2
+ VERSION = "2.3.0"
3
3
  end
data/lib/searchkick.rb CHANGED
@@ -36,7 +36,7 @@ module Searchkick
36
36
  class ImportError < Error; end
37
37
 
38
38
  class << self
39
- attr_accessor :search_method_name, :wordnet_path, :timeout, :models, :client_options, :redis, :index_suffix
39
+ attr_accessor :search_method_name, :wordnet_path, :timeout, :models, :client_options, :redis, :index_suffix, :queue_name
40
40
  attr_writer :client, :env, :search_timeout
41
41
  attr_reader :aws_credentials
42
42
  end
@@ -45,6 +45,7 @@ module Searchkick
45
45
  self.timeout = 10
46
46
  self.models = []
47
47
  self.client_options = {}
48
+ self.queue_name = :searchkick
48
49
 
49
50
  def self.client
50
51
  @client ||= begin
@@ -206,4 +207,7 @@ end
206
207
 
207
208
  # TODO find better ActiveModel hook
208
209
  ActiveModel::Callbacks.send(:include, Searchkick::Model)
209
- ActiveRecord::Base.send(:extend, Searchkick::Model) if defined?(ActiveRecord)
210
+
211
+ ActiveSupport.on_load(:active_record) do
212
+ extend Searchkick::Model
213
+ end
data/test/errors_test.rb CHANGED
@@ -2,8 +2,8 @@ require_relative "test_helper"
2
2
 
3
3
  class ErrorsTest < Minitest::Test
4
4
  def test_bulk_import_raises_error
5
- valid_dog = Product.new(name: "2016-01-02")
6
- invalid_dog = Product.new(name: "Ol' One-Leg")
5
+ valid_dog = Product.create(name: "2016-01-02")
6
+ invalid_dog = Product.create(name: "Ol' One-Leg")
7
7
  index = Searchkick::Index.new "dogs", mappings: {
8
8
  dog: {
9
9
  properties: {
@@ -4,4 +4,4 @@ source 'https://rubygems.org'
4
4
  gemspec path: "../../"
5
5
 
6
6
  gem "sqlite3"
7
- gem "activerecord", "~> 5.1.0.beta1"
7
+ gem "activerecord", "~> 5.0.0"
data/test/match_test.rb CHANGED
@@ -243,6 +243,11 @@ class MatchTest < Minitest::Test
243
243
  assert_order "wheat bread", ["Wheat Bread", "Whole Wheat Bread"], match: :phrase
244
244
  end
245
245
 
246
+ def test_dynamic_fields
247
+ store_names ["Red Bull"], Speaker
248
+ assert_search "redbull", ["Red Bull"], {fields: [:name]}, Speaker
249
+ end
250
+
246
251
  def test_unsearchable
247
252
  store [
248
253
  {name: "Unsearchable", description: "Almond"}
@@ -59,4 +59,9 @@ class SynonymsTest < Minitest::Test
59
59
  assert_search "Halogen Lamp", ["Lightbulb"]
60
60
  assert_search "onions", ["Green Onions"]
61
61
  end
62
+
63
+ def test_case
64
+ store_names ["Uppercase"]
65
+ assert_search "lowercase", ["Uppercase"]
66
+ end
62
67
  end
data/test/test_helper.rb CHANGED
@@ -372,6 +372,7 @@ class Product
372
372
  ["qtip", "cottonswab"],
373
373
  ["burger", "hamburger"],
374
374
  ["bandaid", "bandag"],
375
+ ["UPPERCASE", "lowercase"],
375
376
  "lightbulb => led,lightbulb",
376
377
  "lightbulb => halogenlamp"
377
378
  ],
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: 2.2.1
4
+ version: 2.3.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: 2017-04-16 00:00:00.000000000 Z
11
+ date: 2017-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -138,7 +138,7 @@ files:
138
138
  - test/gemfiles/activerecord40.gemfile
139
139
  - test/gemfiles/activerecord41.gemfile
140
140
  - test/gemfiles/activerecord42.gemfile
141
- - test/gemfiles/activerecord51.gemfile
141
+ - test/gemfiles/activerecord50.gemfile
142
142
  - test/gemfiles/apartment.gemfile
143
143
  - test/gemfiles/cequel.gemfile
144
144
  - test/gemfiles/mongoid2.gemfile
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
193
  version: '0'
194
194
  requirements: []
195
195
  rubyforge_project:
196
- rubygems_version: 2.6.8
196
+ rubygems_version: 2.6.11
197
197
  signing_key:
198
198
  specification_version: 4
199
199
  summary: Searchkick learns what your users are looking for. As more people search,
@@ -213,7 +213,7 @@ test_files:
213
213
  - test/gemfiles/activerecord40.gemfile
214
214
  - test/gemfiles/activerecord41.gemfile
215
215
  - test/gemfiles/activerecord42.gemfile
216
- - test/gemfiles/activerecord51.gemfile
216
+ - test/gemfiles/activerecord50.gemfile
217
217
  - test/gemfiles/apartment.gemfile
218
218
  - test/gemfiles/cequel.gemfile
219
219
  - test/gemfiles/mongoid2.gemfile