pg_search 2.3.2 → 2.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +11 -0
  3. data/.rubocop.yml +86 -4
  4. data/.travis.yml +4 -12
  5. data/CHANGELOG.md +25 -20
  6. data/LICENSE +1 -1
  7. data/README.md +5 -5
  8. data/lib/pg_search.rb +4 -4
  9. data/lib/pg_search/document.rb +1 -1
  10. data/lib/pg_search/features/dmetaphone.rb +4 -6
  11. data/lib/pg_search/features/tsearch.rb +13 -12
  12. data/lib/pg_search/migration/templates/add_pg_search_dmetaphone_support_functions.rb.erb +6 -6
  13. data/lib/pg_search/migration/templates/create_pg_search_documents.rb.erb +2 -2
  14. data/lib/pg_search/model.rb +2 -0
  15. data/lib/pg_search/multisearch.rb +10 -1
  16. data/lib/pg_search/multisearch/rebuilder.rb +2 -2
  17. data/lib/pg_search/scope_options.rb +2 -2
  18. data/lib/pg_search/tasks.rb +1 -1
  19. data/lib/pg_search/version.rb +1 -1
  20. data/pg_search.gemspec +8 -3
  21. data/spec/integration/.rubocop.yml +11 -0
  22. data/spec/integration/associations_spec.rb +17 -56
  23. data/spec/integration/deprecation_spec.rb +1 -1
  24. data/spec/integration/pg_search_spec.rb +62 -51
  25. data/spec/lib/pg_search/configuration/association_spec.rb +8 -6
  26. data/spec/lib/pg_search/features/dmetaphone_spec.rb +2 -2
  27. data/spec/lib/pg_search/features/trigram_spec.rb +15 -11
  28. data/spec/lib/pg_search/features/tsearch_spec.rb +16 -10
  29. data/spec/lib/pg_search/multisearch/rebuilder_spec.rb +89 -55
  30. data/spec/lib/pg_search/multisearch_spec.rb +47 -28
  31. data/spec/lib/pg_search/multisearchable_spec.rb +148 -94
  32. data/spec/lib/pg_search/normalizer_spec.rb +12 -10
  33. data/spec/lib/pg_search_spec.rb +57 -41
  34. data/spec/spec_helper.rb +10 -4
  35. data/spec/support/database.rb +1 -1
  36. metadata +81 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c16f0c4421b4d6d6f4c247f556c4eb2fdb01242617a1e960fdd15785be84dbf
4
- data.tar.gz: f580e760db34c55abf2401176681f8053500e3d249dd51edf8dce0dfb251f641
3
+ metadata.gz: 1c754738322b4dea0ecf3f70b8ddb03c5ff26bbe0f44578f6870c9f0e9fe6604
4
+ data.tar.gz: 4d8dc4be9b36a8a35cbaf6c759f9e973242e60c6b2eaf03b92d177297a7ad2b1
5
5
  SHA512:
6
- metadata.gz: f649091265d7b174c6b826a38e1f80f5eb57851184d2af4720926982d42c41ee1a4bc9399ca0cb1031c31f9a40313215cced168cb99d0a1cf65000fd7c4c6be9
7
- data.tar.gz: 42c651d0689300bd1328089814562fe575a43d3cf522365b51f2de828eb33cc55d7eab69d242d525228e62d46bc99f74391e0569c4ef4cd39f27bbaec5deb073
6
+ metadata.gz: '09b9d4b415a215bf24e38f1f3c80b309aaf7c4c52774e463f07db9f70496bf6bfde3bbd3fd0c69a4872ab531dc7a7fff098b6c11b1b7f5f0134b41e8feb73e4b'
7
+ data.tar.gz: a41a81af41368584b5cc4bbb6174c800e9d5dca906630db567cb908aa4280f921f2a1d579805d008dc77011b16d3b7ca5e025357cb0d51f777bd54cf848b8bc3
@@ -0,0 +1,11 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
+
6
+ version: 2
7
+ updates:
8
+ - package-ecosystem: "bundler" # See documentation for possible values
9
+ directory: "/" # Location of package manifests
10
+ schedule:
11
+ interval: "daily"
@@ -1,7 +1,13 @@
1
- require: rubocop-performance
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rails
4
+ - rubocop-rake
5
+ - rubocop-rspec
6
+ - rubocop-thread_safety
2
7
 
3
8
  AllCops:
4
- TargetRubyVersion: 2.4
9
+ TargetRubyVersion: 2.5
10
+ NewCops: enable
5
11
  Exclude:
6
12
  - bin/**/*
7
13
  - vendor/**/*
@@ -13,7 +19,7 @@ Layout/LineLength:
13
19
  Max: 120
14
20
 
15
21
  Metrics/MethodLength:
16
- Max: 21
22
+ Max: 15
17
23
 
18
24
  Metrics/BlockLength:
19
25
  Exclude:
@@ -44,7 +50,7 @@ Bundler/DuplicatedGem:
44
50
 
45
51
  Style/EmptyMethod:
46
52
  EnforcedStyle: expanded
47
-
53
+
48
54
  Layout/FirstArrayElementIndentation:
49
55
  EnforcedStyle: consistent
50
56
 
@@ -54,3 +60,79 @@ Style/Documentation:
54
60
  Style/WordArray:
55
61
  EnforcedStyle: percent
56
62
  MinSize: 3
63
+
64
+ Style/HashEachMethods:
65
+ Enabled: true
66
+
67
+ Style/HashTransformKeys:
68
+ Enabled: true
69
+
70
+ Style/HashTransformValues:
71
+ Enabled: true
72
+
73
+ Rails/ApplicationRecord:
74
+ Enabled: false
75
+
76
+ Rails/TimeZone:
77
+ Enabled: false
78
+
79
+ RSpec/ContextWording:
80
+ Prefixes:
81
+ - using
82
+ - via
83
+ - when
84
+ - with
85
+ - without
86
+
87
+ Lint/RaiseException:
88
+ Enabled: true
89
+
90
+ Lint/StructNewOverride:
91
+ Enabled: true
92
+
93
+ Layout/SpaceAroundMethodCallOperator:
94
+ Enabled: true
95
+
96
+ Style/ExponentialNotation:
97
+ Enabled: true
98
+
99
+ RSpec/DescribedClass:
100
+ Enabled: true
101
+
102
+ RSpec/ExpectInHook:
103
+ Enabled: false
104
+
105
+ RSpec/FilePath:
106
+ CustomTransform:
107
+ TSearch: "tsearch"
108
+ DMetaphone: "dmetaphone"
109
+
110
+ Layout/EmptyLinesAroundAttributeAccessor:
111
+ Enabled: true
112
+
113
+ Lint/DeprecatedOpenSSLConstant:
114
+ Enabled: true
115
+
116
+ Style/SlicingWithRange:
117
+ Enabled: true
118
+
119
+ Lint/MixedRegexpCaptureTypes:
120
+ Enabled: true
121
+
122
+ Style/RedundantFetchBlock:
123
+ Enabled: true
124
+
125
+ Style/RedundantRegexpCharacterClass:
126
+ Enabled: true
127
+
128
+ Style/RedundantRegexpEscape:
129
+ Enabled: true
130
+
131
+ RSpec/MultipleExpectations:
132
+ Max: 5
133
+
134
+ RSpec/MultipleMemoizedHelpers:
135
+ AllowSubject: true
136
+
137
+ RSpec/ExampleLength:
138
+ Max: 15
@@ -3,11 +3,10 @@ bundler_args: --binstubs
3
3
  cache: bundler
4
4
 
5
5
  rvm:
6
- - 2.7.0
7
- - 2.6.5
8
- - 2.5.7
9
- - 2.4.9
10
- - jruby-9.2.8.0
6
+ - 2.7.1
7
+ - 2.6.6
8
+ - 2.5.8
9
+ - jruby-9.2.11.1
11
10
 
12
11
  env:
13
12
  global:
@@ -23,13 +22,6 @@ matrix:
23
22
  allow_failures:
24
23
  - env: ACTIVE_RECORD_BRANCH="master"
25
24
  - env: ACTIVE_RECORD_BRANCH="6-0-stable"
26
- exclude:
27
- - rvm: 2.4.9
28
- env: ACTIVE_RECORD_BRANCH="master"
29
- - rvm: 2.4.9
30
- env: ACTIVE_RECORD_VERSION="~> 6.0.0"
31
- - rvm: 2.4.9
32
- - env: ACTIVE_RECORD_BRANCH="6-0-stable"
33
25
 
34
26
  before_script:
35
27
  - psql --version
@@ -1,62 +1,67 @@
1
1
  # pg_search changelog
2
2
 
3
+ ## 2.3.3
4
+
5
+ * Drop support for Ruby < 2.5.
6
+ * Use keyword argument for `clean_up` setting in `PgSearch::Multisearch.rebuild`.
7
+
3
8
  ## 2.3.2
4
9
 
5
- * Autoload PgSearch::Document to prevent it from being loaded in projects that are not using multi-search.
6
- * Rebuilder should use update_pg_search_document if additional_attributes is set (David Ramalho)
10
+ * Autoload `PgSearch::Document` to prevent it from being loaded in projects that are not using multi-search.
11
+ * Rebuilder should use `update_pg_search_document` if `additional_attributes` is set. (David Ramalho)
7
12
 
8
13
  ## 2.3.1
9
14
 
10
- * Drop support for Active Record < 5.2
11
- * Do not load railtie unless Rails::Railtie is defined, to avoid problem when loading alongside Action Mailer (Adam Schwartz)
15
+ * Drop support for Active Record < 5.2.
16
+ * Do not load railtie unless Rails::Railtie is defined, to avoid problem when loading alongside Action Mailer. (Adam Schwartz)
12
17
 
13
18
  ## 2.3.0
14
19
 
15
- * Extract `PgSearch::Model` module
20
+ * Extract `PgSearch::Model` module.
16
21
  * Deprecate `include PgSearch`. Use `include PgSearch::Model` instead.
17
22
 
18
23
  ## 2.2.0
19
24
 
20
- * Add word_similarity option to trigram search (Severin Räz)
25
+ * Add `word_similarity` option to trigram search. (Severin Räz)
21
26
 
22
27
  ## 2.1.7
23
28
 
24
- * Restore link to GitHub repository to original location
29
+ * Restore link to GitHub repository to original location.
25
30
 
26
31
  ## 2.1.6
27
32
 
28
- * Update link to GitHub repository to new location
33
+ * Update link to GitHub repository to new location.
29
34
 
30
35
  ## 2.1.5
31
36
 
32
- * Drop support for Ruby < 2.4
37
+ * Drop support for Ruby < 2.4.
33
38
 
34
39
  ## 2.1.4
35
40
 
36
- * Drop support for Ruby < 2.3
37
- * Use update instead of deprecated update_attributes
38
- * Remove explicit arel dependency to better support Active Record 6 beta
41
+ * Drop support for Ruby < 2.3.
42
+ * Use `update` instead of deprecated `update_attributes`.
43
+ * Remove explicit Arel dependency to better support Active Record 6 beta.
39
44
 
40
45
  ## 2.1.3
41
46
 
42
47
  * Drop support for Ruby < 2.2
43
- * Disallow left/right single quotation marks in tsquery (Fabian Schwahn) (#382)
44
- * Do not attempt to save an already-destroy PgSearch::Document (Oleg Dashevskii, Vokhmin Aleksei V) (#353)
45
- * Quote column name when rebuilding (Jed Levin) (#379)
48
+ * Disallow left/right single quotation marks in tsquery. (Fabian Schwahn) (#382)
49
+ * Do not attempt to save an already-destroyed `PgSearch::Document`. (Oleg Dashevskii, Vokhmin Aleksei V) (#353)
50
+ * Quote column name when rebuilding. (Jed Levin) (#379)
46
51
 
47
52
  ## 2.1.2
48
53
 
49
- * Silence warnings in Rails 5.2.0.beta2 (Kevin Deisz)
54
+ * Silence warnings in Rails 5.2.0.beta2. (Kevin Deisz)
50
55
 
51
56
  ## 2.1.1
52
57
 
53
- * Support snake_case ts_headline options again (with deprecation warning)
58
+ * Support snake_case `ts_headline` options again. (with deprecation warning)
54
59
 
55
60
  ## 2.1.0
56
61
 
57
- * Allow ts_headline options to be passed to :highlight (Ian Heisters)
58
- * Wait to load PgSearch::Document until after Active Record has loaded (Logan Leger)
59
- * Add Rails version to generated migrations (Erik Eide)
62
+ * Allow `ts_headline` options to be passed to `:highlight`. (Ian Heisters)
63
+ * Wait to load `PgSearch::Document` until after Active Record has loaded. (Logan Leger)
64
+ * Add Rails version to generated migrations. (Erik Eide)
60
65
 
61
66
  ## 2.0.1
62
67
 
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2019 Casebook, PBC <http://www.casebook.net>
1
+ Copyright (c) 2010-2020 Casebook, PBC <http://www.casebook.net>
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -16,7 +16,7 @@ Read the blog post introducing PgSearch at https://content.pivotal.io/blog/pg-se
16
16
 
17
17
  ## REQUIREMENTS
18
18
 
19
- * Ruby 2.4+
19
+ * Ruby 2.5+
20
20
  * ActiveRecord 5.2+
21
21
  * PostgreSQL 9.2+
22
22
  * [PostgreSQL extensions](https://github.com/Casecommons/pg_search/wiki/Installing-PostgreSQL-Extensions) for certain features
@@ -294,7 +294,7 @@ is your base class. You can prevent ```rebuild``` from deleting your records
294
294
  like so:
295
295
 
296
296
  ```ruby
297
- PgSearch::Multisearch.rebuild(Product, false)
297
+ PgSearch::Multisearch.rebuild(Product, clean_up: false)
298
298
  ```
299
299
 
300
300
  Rebuild is also available as a Rake task, for convenience.
@@ -338,7 +338,7 @@ class Movie < ActiveRecord::Base
338
338
 
339
339
  # More sophisticated approach
340
340
  def self.rebuild_pg_search_documents
341
- connection.execute <<-SQL
341
+ connection.execute <<~SQL.squish
342
342
  INSERT INTO pg_search_documents (searchable_type, searchable_id, content, created_at, updated_at)
343
343
  SELECT 'Movie' AS searchable_type,
344
344
  movies.id AS searchable_id,
@@ -895,7 +895,7 @@ class Sentence < ActiveRecord::Base
895
895
  include PgSearch::Model
896
896
 
897
897
  pg_search_scope :similarity_like,
898
- against: :words,
898
+ against: :name,
899
899
  using: {
900
900
  trigram: {
901
901
  word_similarity: true
@@ -903,7 +903,7 @@ class Sentence < ActiveRecord::Base
903
903
  }
904
904
 
905
905
  pg_search_scope :word_similarity_like,
906
- against: :words,
906
+ against: :name,
907
907
  using: [:trigram]
908
908
  end
909
909
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "active_record"
4
4
  require "active_support/concern"
5
- require "active_support/core_ext/module/attribute_accessors"
5
+ require "active_support/core_ext/module/attribute_accessors_per_thread"
6
6
  require "active_support/core_ext/string/strip"
7
7
 
8
8
  require "pg_search/configuration"
@@ -18,7 +18,7 @@ module PgSearch
18
18
  autoload :Document, "pg_search/document"
19
19
 
20
20
  def self.included(base)
21
- ActiveSupport::Deprecation.warn <<-MESSAGE.strip_heredoc
21
+ ActiveSupport::Deprecation.warn <<~MESSAGE
22
22
  Directly including `PgSearch` into an Active Record model is deprecated and will be removed in pg_search 3.0.
23
23
 
24
24
  Please replace `include PgSearch` with `include PgSearch::Model`.
@@ -27,10 +27,10 @@ module PgSearch
27
27
  base.include PgSearch::Model
28
28
  end
29
29
 
30
- mattr_accessor :multisearch_options
30
+ thread_mattr_accessor :multisearch_options
31
31
  self.multisearch_options = {}
32
32
 
33
- mattr_accessor :unaccent_function
33
+ thread_mattr_accessor :unaccent_function
34
34
  self.unaccent_function = "unaccent"
35
35
 
36
36
  class << self
@@ -12,7 +12,7 @@ module PgSearch
12
12
  # The logger might not have loaded yet.
13
13
  # https://github.com/Casecommons/pg_search/issues/26
14
14
  def self.logger
15
- super || Logger.new(STDERR)
15
+ super || Logger.new($stderr)
16
16
  end
17
17
 
18
18
  pg_search_scope :search, lambda { |*args|
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_support/core_ext/module/delegation"
4
+
3
5
  module PgSearch
4
6
  module Features
5
7
  class DMetaphone
@@ -9,13 +11,9 @@ module PgSearch
9
11
  @tsearch = TSearch.new(query, options, columns, model, dmetaphone_normalizer)
10
12
  end
11
13
 
12
- def conditions
13
- tsearch.conditions
14
- end
14
+ delegate :conditions, to: :tsearch
15
15
 
16
- def rank
17
- tsearch.rank
18
- end
16
+ delegate :rank, to: :tsearch
19
17
 
20
18
  private
21
19
 
@@ -59,7 +59,7 @@ module PgSearch
59
59
  end
60
60
  end
61
61
 
62
- def deprecated_headline_options
62
+ def deprecated_headline_options # rubocop:disable Metrics/MethodLength
63
63
  indifferent_options = options.with_indifferent_access
64
64
 
65
65
  %w[
@@ -97,7 +97,7 @@ module PgSearch
97
97
 
98
98
  DISALLOWED_TSQUERY_CHARACTERS = /['?\\:‘’]/.freeze
99
99
 
100
- def tsquery_for_term(unsanitized_term) # rubocop:disable Metrics/AbcSize
100
+ def tsquery_for_term(unsanitized_term)
101
101
  if options[:negation] && unsanitized_term.start_with?("!")
102
102
  unsanitized_term[0] = ''
103
103
  negated = true
@@ -107,25 +107,26 @@ module PgSearch
107
107
 
108
108
  term_sql = Arel.sql(normalize(connection.quote(sanitized_term)))
109
109
 
110
- # After this, the SQL expression evaluates to a string containing the term surrounded by single-quotes.
111
- # If :prefix is true, then the term will have :* appended to the end.
112
- # If :negated is true, then the term will have ! prepended to the front.
110
+ tsquery = tsquery_expression(term_sql, negated: negated, prefix: options[:prefix])
111
+
112
+ Arel::Nodes::NamedFunction.new("to_tsquery", [dictionary, tsquery]).to_sql
113
+ end
114
+
115
+ # After this, the SQL expression evaluates to a string containing the term surrounded by single-quotes.
116
+ # If :prefix is true, then the term will have :* appended to the end.
117
+ # If :negated is true, then the term will have ! prepended to the front.
118
+ def tsquery_expression(term_sql, negated:, prefix:)
113
119
  terms = [
114
120
  (Arel::Nodes.build_quoted('!') if negated),
115
121
  Arel::Nodes.build_quoted("' "),
116
122
  term_sql,
117
123
  Arel::Nodes.build_quoted(" '"),
118
- (Arel::Nodes.build_quoted(":*") if options[:prefix])
124
+ (Arel::Nodes.build_quoted(":*") if prefix)
119
125
  ].compact
120
126
 
121
- tsquery_sql = terms.inject do |memo, term|
127
+ terms.inject do |memo, term|
122
128
  Arel::Nodes::InfixOperation.new("||", memo, Arel::Nodes.build_quoted(term))
123
129
  end
124
-
125
- Arel::Nodes::NamedFunction.new(
126
- "to_tsquery",
127
- [dictionary, tsquery_sql]
128
- ).to_sql
129
130
  end
130
131
 
131
132
  def tsquery
@@ -1,16 +1,16 @@
1
1
  class AddPgSearchDmetaphoneSupportFunctions < ActiveRecord::Migration<%= migration_version %>
2
- def self.up
2
+ def up
3
3
  say_with_time("Adding support functions for pg_search :dmetaphone") do
4
- execute <<-'SQL'
5
- <%= read_sql_file "dmetaphone" %>
4
+ execute <<~'SQL'.squish
5
+ <%= indent(read_sql_file("dmetaphone"), 8) %>
6
6
  SQL
7
7
  end
8
8
  end
9
9
 
10
- def self.down
10
+ def down
11
11
  say_with_time("Dropping support functions for pg_search :dmetaphone") do
12
- execute <<-'SQL'
13
- <%= read_sql_file "uninstall_dmetaphone" %>
12
+ execute <<~'SQL'.squish
13
+ <%= indent(read_sql_file("uninstall_dmetaphone"), 8) %>
14
14
  SQL
15
15
  end
16
16
  end