pg_search 2.3.6 → 2.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +21 -16
  3. data/.standard.yml +6 -0
  4. data/CHANGELOG.md +11 -0
  5. data/Gemfile +19 -6
  6. data/LICENSE +1 -1
  7. data/README.md +49 -32
  8. data/Rakefile +4 -7
  9. data/lib/pg_search/configuration/column.rb +6 -4
  10. data/lib/pg_search/configuration/foreign_column.rb +1 -1
  11. data/lib/pg_search/configuration.rb +1 -1
  12. data/lib/pg_search/document.rb +8 -8
  13. data/lib/pg_search/features/dmetaphone.rb +1 -1
  14. data/lib/pg_search/features/trigram.rb +4 -4
  15. data/lib/pg_search/features/tsearch.rb +14 -13
  16. data/lib/pg_search/migration/dmetaphone_generator.rb +2 -2
  17. data/lib/pg_search/migration/generator.rb +5 -5
  18. data/lib/pg_search/migration/multisearch_generator.rb +2 -2
  19. data/lib/pg_search/model.rb +6 -6
  20. data/lib/pg_search/multisearch.rb +4 -2
  21. data/lib/pg_search/multisearchable.rb +7 -7
  22. data/lib/pg_search/normalizer.rb +5 -5
  23. data/lib/pg_search/scope_options.rb +26 -5
  24. data/lib/pg_search/tasks.rb +2 -2
  25. data/lib/pg_search/version.rb +1 -1
  26. data/lib/pg_search.rb +3 -3
  27. data/pg_search.gemspec +16 -31
  28. data/spec/.rubocop.yml +20 -7
  29. data/spec/integration/.rubocop.yml +2 -2
  30. data/spec/integration/associations_spec.rb +106 -106
  31. data/spec/integration/deprecation_spec.rb +7 -8
  32. data/spec/integration/pg_search_spec.rb +314 -298
  33. data/spec/integration/single_table_inheritance_spec.rb +5 -5
  34. data/spec/lib/pg_search/configuration/association_spec.rb +15 -15
  35. data/spec/lib/pg_search/configuration/column_spec.rb +13 -1
  36. data/spec/lib/pg_search/configuration/foreign_column_spec.rb +4 -4
  37. data/spec/lib/pg_search/features/dmetaphone_spec.rb +4 -4
  38. data/spec/lib/pg_search/features/trigram_spec.rb +29 -29
  39. data/spec/lib/pg_search/features/tsearch_spec.rb +57 -39
  40. data/spec/lib/pg_search/multisearch/rebuilder_spec.rb +17 -17
  41. data/spec/lib/pg_search/multisearch_spec.rb +6 -6
  42. data/spec/lib/pg_search/multisearchable_spec.rb +26 -26
  43. data/spec/lib/pg_search/normalizer_spec.rb +7 -7
  44. data/spec/lib/pg_search_spec.rb +18 -18
  45. data/spec/spec_helper.rb +7 -9
  46. data/spec/support/database.rb +6 -6
  47. metadata +10 -214
  48. data/.codeclimate.yml +0 -17
  49. data/.rubocop.yml +0 -137
  50. data/.travis.yml +0 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43a62057153fd9e33ed21bc6ce1a420b5fbeaad46e9b047bd1e039c9c7ab6ad2
4
- data.tar.gz: 15759abc9542c0b7ddc6060e156e7eff74d78cceef5bb06c4bdfa562e029722b
3
+ metadata.gz: 103352d5afaf431080a49411b6e7bce5c2d1edec6aa88da55913fb179ef02367
4
+ data.tar.gz: fea6642ba781bb1916f32d46fe25f829c34d27564c23674dde4c80f97a5a43db
5
5
  SHA512:
6
- metadata.gz: 6c1fc5c20a82e45a4fd6381fc56fd940dcd85cce2039e2e7f5159e0c939146d0176f1970481c29205bd7d7737022007d3d78cddc3fa93603a67221fa272d1a4e
7
- data.tar.gz: 06a4f487a2cef2fd7b55bf5f650f6e13cec3528b6514f72e6dce69943c67d879f42c795d46c7aa442b2abfe789e4459f10437df94e955f9bfbe54968e9297e39
6
+ metadata.gz: d550e544579fddb2ef4b2667a93624f9b293102db705e304b048bd0eaa328d908c3415028324a35e038353e7a47ac334e53e2a6f381abe2456de835c4d04c359
7
+ data.tar.gz: b896f972762290dda0d9e744680c707223188e6a5ceb05329cdc3479f302c1a18dd11b20bcd5ebffe66cc36143c182318b51e9e88e63463cfb55d7d0d8890d6b
@@ -8,6 +8,9 @@ on:
8
8
  pull_request:
9
9
  branches:
10
10
  - master
11
+ schedule:
12
+ - cron: "0 18 * * 6" # Saturdays at 12pm CST
13
+ workflow_dispatch:
11
14
 
12
15
  jobs:
13
16
  test:
@@ -33,33 +36,35 @@ jobs:
33
36
  strategy:
34
37
  fail-fast: false
35
38
  matrix:
36
- ruby-version: ['2.6', '2.7', '3.0', '3.1']
39
+ ruby-version: ['3.0', '3.1', '3.2', '3.3']
37
40
  active-record-version-env:
38
- - ACTIVE_RECORD_VERSION="~> 5.2.0"
39
- - ACTIVE_RECORD_VERSION="~> 6.0.0"
40
41
  - ACTIVE_RECORD_VERSION="~> 6.1.0"
41
42
  - ACTIVE_RECORD_VERSION="~> 7.0.0"
43
+ - ACTIVE_RECORD_VERSION="~> 7.1.0"
44
+ - ACTIVE_RECORD_VERSION="~> 7.2.0"
42
45
  allow-failure: [false]
46
+ exclude:
47
+ - ruby-version: '3.0'
48
+ active-record-version-env: ACTIVE_RECORD_VERSION="~> 7.2.0"
43
49
  include:
44
- - ruby-version: '3.1'
50
+ - ruby-version: '3.3'
51
+ active-record-version-env: ACTIVE_RECORD_BRANCH="main"
52
+ allow-failure: true
53
+ - ruby-version: '3.3'
54
+ active-record-version-env: ACTIVE_RECORD_BRANCH="7-2-stable"
55
+ allow-failure: true
56
+ - ruby-version: '3.3'
57
+ active-record-version-env: ACTIVE_RECORD_BRANCH="7-1-stable"
58
+ allow-failure: true
59
+ - ruby-version: '3.3'
45
60
  active-record-version-env: ACTIVE_RECORD_BRANCH="7-0-stable"
46
61
  allow-failure: true
47
- - ruby-version: '3.1'
62
+ - ruby-version: '3.3'
48
63
  active-record-version-env: ACTIVE_RECORD_BRANCH="6-1-stable"
49
64
  allow-failure: true
50
- exclude:
51
- - ruby-version: '3.0'
52
- active-record-version-env: ACTIVE_RECORD_VERSION="~> 5.2.0"
53
- allow-failure: false
54
- - ruby-version: '3.1'
55
- active-record-version-env: ACTIVE_RECORD_VERSION="~> 5.2.0"
56
- allow-failure: false
57
- - ruby-version: '2.6'
58
- active-record-version-env: ACTIVE_RECORD_VERSION="~> 7.0.0"
59
- allow-failure: false
60
65
  continue-on-error: ${{ matrix.allow-failure }}
61
66
  steps:
62
- - uses: actions/checkout@v2
67
+ - uses: actions/checkout@v4
63
68
  - name: Set up Ruby
64
69
  uses: ruby/setup-ruby@v1
65
70
  with:
data/.standard.yml ADDED
@@ -0,0 +1,6 @@
1
+ ruby_version: 3.0
2
+
3
+ plugins:
4
+ - standard-performance
5
+ - standard-rails:
6
+ target_rails_version: 6.1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # pg_search changelog
2
2
 
3
+ ## 2.3.7
4
+
5
+ * Drop support for Ruby 2.6 and 2.7
6
+ * Drop support for Active Record 6.0 and earlier
7
+ * Support Ruby 3.2 and 3.3
8
+ * Support Active Record 7.1
9
+ * Support Active Record 7.2 (fatkodima)
10
+ * Add U+02BB/U+02BC to disallowed tsquery characters (Vital Ryabchinskiy)
11
+ * add support for Arel::Nodes::SqlLiteral columns (Kyle Fazzari)
12
+ * Improve documentation (Prima Aulia Gusta, Ross Baird, Andy Atkinson)
13
+
3
14
  ## 2.3.6
4
15
 
5
16
  * Drop support for Ruby 2.5
data/Gemfile CHANGED
@@ -1,15 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
5
  gemspec
6
6
 
7
- gem 'pg', '>= 0.21.0', platform: :ruby
7
+ gem "pg", ">= 0.21.0", platform: :ruby
8
8
  gem "activerecord-jdbcpostgresql-adapter", ">= 1.3.1", platform: :jruby
9
9
 
10
- if ENV['ACTIVE_RECORD_BRANCH']
11
- gem 'activerecord', git: 'https://github.com/rails/rails.git', branch: ENV['ACTIVE_RECORD_BRANCH']
12
- gem 'arel', git: 'https://github.com/rails/arel.git' if ENV['ACTIVE_RECORD_BRANCH'] == 'master'
10
+ if ENV["ACTIVE_RECORD_BRANCH"]
11
+ gem "activerecord", git: "https://github.com/rails/rails.git", branch: ENV.fetch("ACTIVE_RECORD_BRANCH", nil)
12
+ gem "arel", git: "https://github.com/rails/arel.git" if ENV.fetch("ACTIVE_RECORD_BRANCH", nil) == "master"
13
13
  end
14
14
 
15
- gem 'activerecord', ENV['ACTIVE_RECORD_VERSION'] if ENV['ACTIVE_RECORD_VERSION']
15
+ gem "activerecord", ENV.fetch("ACTIVE_RECORD_VERSION", nil) if ENV["ACTIVE_RECORD_VERSION"] # standard:disable Bundler/DuplicatedGem
16
+
17
+ gem "debug"
18
+ gem "irb"
19
+ gem "rake"
20
+ gem "rspec"
21
+ gem "simplecov"
22
+ gem "simplecov-lcov"
23
+ gem "standard", require: false
24
+ gem "standard-rails", require: false
25
+ gem "standard-rspec", require: false
26
+ gem "undercover"
27
+ gem "warning"
28
+ gem "with_model"
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2021 Casebook, PBC <http://www.casebook.net>
1
+ Copyright (c) 2010–2022 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
@@ -13,8 +13,8 @@ Read the blog post introducing PgSearch at https://tanzu.vmware.com/content/blog
13
13
 
14
14
  ## REQUIREMENTS
15
15
 
16
- * Ruby 2.6+
17
- * ActiveRecord 5.2+
16
+ * Ruby 3.0+
17
+ * Active Record 6.1+
18
18
  * PostgreSQL 9.2+
19
19
  * [PostgreSQL extensions](https://github.com/Casecommons/pg_search/wiki/Installing-PostgreSQL-Extensions) for certain features
20
20
 
@@ -48,7 +48,7 @@ To add PgSearch to an Active Record model, simply include the PgSearch module.
48
48
  class Shape < ActiveRecord::Base
49
49
  include PgSearch::Model
50
50
  end
51
- ```
51
+ ```
52
52
 
53
53
  ### Contents
54
54
  * [Multi-search vs. search scopes](#multi-search-vs-search-scopes)
@@ -198,17 +198,22 @@ problematic_record.published? # => true
198
198
  PgSearch.multisearch("timestamp") # => Includes problematic_record
199
199
  ```
200
200
 
201
- #### More Options
201
+ #### More Options
202
202
 
203
203
  **Conditionally update pg_search_documents**
204
204
 
205
- You can specify an `:update_if` parameter to conditionally update pg_search documents. For example:
205
+ You can also use the `:update_if` option to pass a Proc or method name to call
206
+ to determine whether or not a particular record should be updated.
207
+
208
+ Note that the Proc or method name is called in an `after_save` hook, so if you
209
+ are relying on ActiveRecord dirty flags use `*_previously_changed?`.
206
210
 
207
211
  ```ruby
208
- multisearchable(
209
- against: [:body],
210
- update_if: :body_changed?
211
- )
212
+ class Message < ActiveRecord::Base
213
+ include PgSearch::Model
214
+ multisearchable against: [:body],
215
+ update_if: :body_previously_changed?
216
+ end
212
217
  ```
213
218
 
214
219
  **Specify additional attributes to be saved on the pg_search_documents table**
@@ -241,7 +246,8 @@ This allows much faster searches without joins later on by doing something like:
241
246
  PgSearch.multisearch(params['search']).where(author_id: 2)
242
247
  ```
243
248
 
244
- *NOTE: You must currently manually call `record.update_pg_search_document` for the additional attribute to be included in the pg_search_documents table*
249
+ *NOTE: You must currently manually call `record.update_pg_search_document` for
250
+ the additional attribute to be included in the pg_search_documents table*
245
251
 
246
252
  #### Multi-search associations
247
253
 
@@ -353,15 +359,11 @@ pg_search_documents tables. The following will set the schema search path to
353
359
 
354
360
  $ rake pg_search:multisearch:rebuild[BlogPost,my_schema]
355
361
 
356
- For models that are multisearchable :against methods that directly map to
362
+ For models that are multisearchable `:against` methods that directly map to
357
363
  Active Record attributes, an efficient single SQL statement is run to update
358
- the pg_search_documents table all at once. However, if you call any dynamic
359
- methods in :against, the following strategy will be used:
360
-
361
- ```ruby
362
- PgSearch::Document.delete_all(searchable_type: "Ingredient")
363
- Ingredient.find_each { |record| record.update_pg_search_document }
364
- ```
364
+ the `pg_search_documents` table all at once. However, if you call any dynamic
365
+ methods in `:against` then `update_pg_search_document` will be called on the
366
+ individual records being indexed in batches.
365
367
 
366
368
  You can also provide a custom implementation for rebuilding the documents by
367
369
  adding a class method called `rebuild_pg_search_documents` to your model.
@@ -550,6 +552,21 @@ class Beer < ActiveRecord::Base
550
552
  end
551
553
  ```
552
554
 
555
+ Here's an example if you pass multiple :using options with additional configurations.
556
+
557
+ ```ruby
558
+ class Beer < ActiveRecord::Base
559
+ include PgSearch::Model
560
+ pg_search_scope :search_name,
561
+ against: :name,
562
+ using: {
563
+ :trigram => {},
564
+ :dmetaphone => {},
565
+ :tsearch => { :prefix => true }
566
+ }
567
+ end
568
+ ```
569
+
553
570
  The currently implemented features are
554
571
 
555
572
  * :tsearch - [Full text search](http://www.postgresql.org/docs/current/static/textsearch-intro.html), which is built-in to PostgreSQL
@@ -662,7 +679,7 @@ Animal.with_name_matching("fish !red !blue") # => [one_fish, two_fish]
662
679
 
663
680
  PostgreSQL full text search also support multiple dictionaries for stemming.
664
681
  You can learn more about how dictionaries work by reading the [PostgreSQL
665
- documention](http://www.postgresql.org/docs/current/static/textsearch-dictionaries.html).
682
+ documention](http://www.postgresql.org/docs/current/static/textsearch-dictionaries.html).
666
683
  If you use one of the language dictionaries, such as "english",
667
684
  then variants of words (e.g. "jumping" and "jumped") will match each other. If
668
685
  you don't want stemming, you should pick the "simple" dictionary which does
@@ -684,12 +701,12 @@ class BoringTweet < ActiveRecord::Base
684
701
  }
685
702
  end
686
703
 
687
- sleepy = BoringTweet.create! text: "I snoozed my alarm for fourteen hours today. I bet I can beat that tomorrow! #sleepy"
704
+ sleep = BoringTweet.create! text: "I snoozed my alarm for fourteen hours today. I bet I can beat that tomorrow! #sleep"
688
705
  sleeping = BoringTweet.create! text: "You know what I like? Sleeping. That's what. #enjoyment"
689
- sleeper = BoringTweet.create! text: "Have you seen Woody Allen's movie entitled Sleeper? Me neither. #boycott"
706
+ sleeps = BoringTweet.create! text: "In the jungle, the mighty jungle, the lion sleeps #tonight"
690
707
 
691
- BoringTweet.kinda_matching("sleeping") # => [sleepy, sleeping, sleeper]
692
- BoringTweet.literally_matching("sleeping") # => [sleeping]
708
+ BoringTweet.kinda_matching("sleeping") # => [sleep, sleeping, sleeps]
709
+ BoringTweet.literally_matching("sleeps") # => [sleeps]
693
710
  ```
694
711
 
695
712
  ##### :normalization
@@ -834,7 +851,7 @@ used for searching.
834
851
  Double Metaphone support is currently available as part of the [fuzzystrmatch
835
852
  extension](http://www.postgresql.org/docs/current/static/fuzzystrmatch.html)
836
853
  that must be installed before this feature can be used. In addition to the
837
- extension, you must install a utility function into your database. To generate
854
+ extension, you must install a utility function into your database. To generate
838
855
  and run a migration for this, run:
839
856
 
840
857
  $ rails g pg_search:migration:dmetaphone
@@ -869,7 +886,7 @@ Trigram search works by counting how many three-letter substrings (or
869
886
  Trigram search has some ability to work even with typos and misspellings in
870
887
  the query or text.
871
888
 
872
- Trigram support is currently available as part of the
889
+ Trigram support is currently available as part of the
873
890
  [pg_trgm extension](http://www.postgresql.org/docs/current/static/pgtrgm.html) that must be installed before this
874
891
  feature can be used.
875
892
 
@@ -933,7 +950,7 @@ Vegetable.strictly_spelled_like("collyflower") # => []
933
950
  Allows you to match words in longer strings.
934
951
  By default, trigram searches use `%` or `similarity()` as a similarity value.
935
952
  Set `word_similarity` to `true` to opt for `<%` and `word_similarity` instead.
936
- This causes the trigram search to use the similarity of the query term
953
+ This causes the trigram search to use the similarity of the query term
937
954
  and the word with greatest similarity.
938
955
 
939
956
  ```ruby
@@ -959,12 +976,12 @@ Sentence.similarity_like("word") # => []
959
976
  Sentence.word_similarity_like("word") # => [sentence]
960
977
  ```
961
978
 
962
- ### Limiting Fields When Combining Features
979
+ ### Limiting Fields When Combining Features
963
980
 
964
- Sometimes when doing queries combining different features you
965
- might want to searching against only some of the fields with certain features.
981
+ Sometimes when doing queries combining different features you
982
+ might want to search against only some of the fields with certain features.
966
983
  For example perhaps you want to only do a trigram search against the shorter fields
967
- so that you don't need to reduce the threshold excessively. You can specify
984
+ so that you don't need to reduce the threshold excessively. You can specify
968
985
  which fields using the 'only' option:
969
986
 
970
987
  ```ruby
@@ -983,7 +1000,7 @@ class Image < ActiveRecord::Base
983
1000
  end
984
1001
  ```
985
1002
 
986
- Now you can succesfully retrieve an Image with a file_name: 'image_foo.jpg'
1003
+ Now you can succesfully retrieve an Image with a file_name: 'image_foo.jpg'
987
1004
  and long_description: 'This description is so long that it would make a trigram search
988
1005
  fail any reasonable threshold limit' with:
989
1006
 
@@ -1201,5 +1218,5 @@ for discussing pg_search and other Casebook PBC open source projects.
1201
1218
 
1202
1219
  ## LICENSE
1203
1220
 
1204
- Copyright © 2010–2021 [Casebook PBC](http://www.casebook.net).
1221
+ Copyright © 2010–2022 [Casebook PBC](http://www.casebook.net).
1205
1222
  Licensed under the MIT license, see [LICENSE](/LICENSE) file.
data/Rakefile CHANGED
@@ -1,15 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler'
3
+ require "bundler"
4
4
  Bundler::GemHelper.install_tasks
5
5
 
6
- require 'rspec/core/rake_task'
6
+ require "rspec/core/rake_task"
7
7
  RSpec::Core::RakeTask.new(:spec)
8
8
 
9
- require "rubocop/rake_task"
10
- RuboCop::RakeTask.new do |t|
11
- t.options = %w[--display-cop-names]
12
- end
9
+ require "standard/rake"
13
10
 
14
11
  desc "Check test coverage"
15
12
  task :undercover do
@@ -17,4 +14,4 @@ task :undercover do
17
14
  exit(1) unless system("bin/undercover --compare origin/master")
18
15
  end
19
16
 
20
- task default: %w[spec rubocop undercover]
17
+ task default: %w[spec standard undercover]
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'digest'
3
+ require "digest"
4
4
 
5
5
  module PgSearch
6
6
  class Configuration
@@ -9,18 +9,20 @@ module PgSearch
9
9
 
10
10
  def initialize(column_name, weight, model)
11
11
  @name = column_name.to_s
12
- @column_name = column_name.to_s
12
+ @column_name = column_name
13
13
  @weight = weight
14
14
  @model = model
15
15
  @connection = model.connection
16
16
  end
17
17
 
18
18
  def full_name
19
+ return @column_name if @column_name.is_a?(Arel::Nodes::SqlLiteral)
20
+
19
21
  "#{table_name}.#{column_name}"
20
22
  end
21
23
 
22
24
  def to_sql
23
- "coalesce(#{expression}::text, '')"
25
+ "coalesce((#{expression})::text, '')"
24
26
  end
25
27
 
26
28
  private
@@ -30,7 +32,7 @@ module PgSearch
30
32
  end
31
33
 
32
34
  def column_name
33
- @connection.quote_column_name(@column_name)
35
+ @connection.quote_column_name(@name)
34
36
  end
35
37
 
36
38
  def expression
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'digest'
3
+ require "digest"
4
4
 
5
5
  module PgSearch
6
6
  class Configuration
@@ -80,7 +80,7 @@ module PgSearch
80
80
  attr_reader :options
81
81
 
82
82
  def default_options
83
- { using: :tsearch }
83
+ {using: :tsearch}
84
84
  end
85
85
 
86
86
  VALID_KEYS = %w[
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'logger'
3
+ require "logger"
4
4
 
5
5
  module PgSearch
6
- class Document < ActiveRecord::Base
6
+ class Document < ActiveRecord::Base # standard:disable Rails/ApplicationRecord
7
7
  include PgSearch::Model
8
8
 
9
- self.table_name = 'pg_search_documents'
9
+ self.table_name = "pg_search_documents"
10
10
  belongs_to :searchable, polymorphic: true
11
11
 
12
12
  # The logger might not have loaded yet.
@@ -17,12 +17,12 @@ module PgSearch
17
17
 
18
18
  pg_search_scope :search, lambda { |*args|
19
19
  options = if PgSearch.multisearch_options.respond_to?(:call)
20
- PgSearch.multisearch_options.call(*args)
21
- else
22
- { query: args.first }.merge(PgSearch.multisearch_options)
23
- end
20
+ PgSearch.multisearch_options.call(*args)
21
+ else
22
+ {query: args.first}.merge(PgSearch.multisearch_options)
23
+ end
24
24
 
25
- { against: :content }.merge(options)
25
+ {against: :content}.merge(options)
26
26
  }
27
27
  end
28
28
  end
@@ -7,7 +7,7 @@ module PgSearch
7
7
  class DMetaphone
8
8
  def initialize(query, options, columns, model, normalizer)
9
9
  dmetaphone_normalizer = Normalizer.new(normalizer)
10
- options = (options || {}).merge(dictionary: 'simple')
10
+ options = (options || {}).merge(dictionary: "simple")
11
11
  @tsearch = TSearch.new(query, options, columns, model, dmetaphone_normalizer)
12
12
  end
13
13
 
@@ -35,17 +35,17 @@ module PgSearch
35
35
 
36
36
  def similarity_function
37
37
  if word_similarity?
38
- 'word_similarity'
38
+ "word_similarity"
39
39
  else
40
- 'similarity'
40
+ "similarity"
41
41
  end
42
42
  end
43
43
 
44
44
  def infix_operator
45
45
  if word_similarity?
46
- '<%'
46
+ "<%"
47
47
  else
48
- '%'
48
+ "%"
49
49
  end
50
50
  end
51
51
 
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_support/core_ext/module/delegation"
4
- require 'active_support/deprecation'
4
+ require "active_support/deprecation"
5
5
 
6
6
  module PgSearch
7
7
  module Features
8
- class TSearch < Feature # rubocop:disable Metrics/ClassLength
8
+ class TSearch < Feature
9
9
  def self.valid_options
10
10
  super + %i[dictionary prefix negation any_word normalization tsvector_column highlight]
11
11
  end
@@ -36,12 +36,11 @@ module PgSearch
36
36
  end
37
37
 
38
38
  def ts_headline_options
39
- return '' unless options[:highlight].is_a?(Hash)
39
+ return "" unless options[:highlight].is_a?(Hash)
40
40
 
41
41
  headline_options
42
42
  .merge(deprecated_headline_options)
43
- .map { |key, value| "#{key} = #{value}" unless value.nil? }
44
- .compact
43
+ .filter_map { |key, value| "#{key} = #{value}" unless value.nil? }
45
44
  .join(", ")
46
45
  end
47
46
 
@@ -59,7 +58,7 @@ module PgSearch
59
58
  end
60
59
  end
61
60
 
62
- def deprecated_headline_options # rubocop:disable Metrics/MethodLength
61
+ def deprecated_headline_options
63
62
  indifferent_options = options.with_indifferent_access
64
63
 
65
64
  %w[
@@ -71,9 +70,11 @@ module PgSearch
71
70
  unless value.nil?
72
71
  key = deprecated_key.camelize
73
72
 
74
- ActiveSupport::Deprecation.warn(
73
+ warn(
75
74
  "pg_search 3.0 will no longer accept :#{deprecated_key} as an argument to :ts_headline, " \
76
- "use :#{key} instead."
75
+ "use :#{key} instead.",
76
+ category: :deprecated,
77
+ uplevel: 1
77
78
  )
78
79
 
79
80
  hash[key] = ts_headline_option_value(value)
@@ -95,11 +96,11 @@ module PgSearch
95
96
  end
96
97
  end
97
98
 
98
- DISALLOWED_TSQUERY_CHARACTERS = /['?\\:‘’]/.freeze
99
+ DISALLOWED_TSQUERY_CHARACTERS = /['?\\:‘’ʻʼ]/
99
100
 
100
101
  def tsquery_for_term(unsanitized_term)
101
102
  if options[:negation] && unsanitized_term.start_with?("!")
102
- unsanitized_term[0] = ''
103
+ unsanitized_term[0] = ""
103
104
  negated = true
104
105
  end
105
106
 
@@ -117,7 +118,7 @@ module PgSearch
117
118
  # If :negated is true, then the term will have ! prepended to the front.
118
119
  def tsquery_expression(term_sql, negated:, prefix:)
119
120
  terms = [
120
- (Arel::Nodes.build_quoted('!') if negated),
121
+ (Arel::Nodes.build_quoted("!") if negated),
121
122
  Arel::Nodes.build_quoted("' "),
122
123
  term_sql,
123
124
  Arel::Nodes.build_quoted(" '"),
@@ -134,7 +135,7 @@ module PgSearch
134
135
 
135
136
  query_terms = query.split.compact
136
137
  tsquery_terms = query_terms.map { |term| tsquery_for_term(term) }
137
- tsquery_terms.join(options[:any_word] ? ' || ' : ' && ')
138
+ tsquery_terms.join(options[:any_word] ? " || " : " && ")
138
139
  end
139
140
 
140
141
  def tsdocument
@@ -152,7 +153,7 @@ module PgSearch
152
153
  end
153
154
  end
154
155
 
155
- tsdocument_terms.join(' || ')
156
+ tsdocument_terms.join(" || ")
156
157
  end
157
158
 
158
159
  # From http://www.postgresql.org/docs/8.3/static/textsearch-controls.html
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'pg_search/migration/generator'
3
+ require "pg_search/migration/generator"
4
4
 
5
5
  module PgSearch
6
6
  module Migration
7
7
  class DmetaphoneGenerator < Generator
8
8
  def migration_name
9
- 'add_pg_search_dmetaphone_support_functions'
9
+ "add_pg_search_dmetaphone_support_functions"
10
10
  end
11
11
  end
12
12
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_record'
4
- require 'rails/generators/base'
3
+ require "active_record"
4
+ require "rails/generators/base"
5
5
 
6
6
  module PgSearch
7
7
  module Migration
@@ -10,19 +10,19 @@ module PgSearch
10
10
 
11
11
  def self.inherited(subclass)
12
12
  super
13
- subclass.source_root File.expand_path('templates', __dir__)
13
+ subclass.source_root File.expand_path("templates", __dir__)
14
14
  end
15
15
 
16
16
  def create_migration
17
17
  now = Time.now.utc
18
- filename = "#{now.strftime('%Y%m%d%H%M%S')}_#{migration_name}.rb"
18
+ filename = "#{now.strftime("%Y%m%d%H%M%S")}_#{migration_name}.rb"
19
19
  template "#{migration_name}.rb.erb", "db/migrate/#{filename}", migration_version
20
20
  end
21
21
 
22
22
  private
23
23
 
24
24
  def read_sql_file(filename)
25
- sql_directory = File.expand_path('../../../sql', __dir__)
25
+ sql_directory = File.expand_path("../../../sql", __dir__)
26
26
  source_path = File.join(sql_directory, "#{filename}.sql")
27
27
  File.read(source_path).strip
28
28
  end
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'pg_search/migration/generator'
3
+ require "pg_search/migration/generator"
4
4
 
5
5
  module PgSearch
6
6
  module Migration
7
7
  class MultisearchGenerator < Generator
8
8
  def migration_name
9
- 'create_pg_search_documents'
9
+ "create_pg_search_documents"
10
10
  end
11
11
  end
12
12
  end
@@ -7,12 +7,12 @@ module PgSearch
7
7
  module ClassMethods
8
8
  def pg_search_scope(name, options)
9
9
  options_proc = if options.respond_to?(:call)
10
- options
11
- elsif options.respond_to?(:merge)
12
- ->(query) { { query: query }.merge(options) }
13
- else
14
- raise ArgumentError, 'pg_search_scope expects a Hash or Proc'
15
- end
10
+ options
11
+ elsif options.respond_to?(:merge)
12
+ ->(query) { {query: query}.merge(options) }
13
+ else
14
+ raise ArgumentError, "pg_search_scope expects a Hash or Proc"
15
+ end
16
16
 
17
17
  define_singleton_method(name) do |*args|
18
18
  config = Configuration.new(options_proc.call(*args), self)