pg_search 2.1.7 → 2.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +1 -0
  3. data/.editorconfig +10 -0
  4. data/.github/dependabot.yml +11 -0
  5. data/.rubocop.yml +89 -7
  6. data/.travis.yml +11 -19
  7. data/CHANGELOG.md +38 -14
  8. data/Gemfile +1 -1
  9. data/LICENSE +1 -1
  10. data/README.md +74 -42
  11. data/lib/pg_search.rb +15 -58
  12. data/lib/pg_search/document.rb +2 -2
  13. data/lib/pg_search/features/dmetaphone.rb +4 -6
  14. data/lib/pg_search/features/trigram.rb +29 -5
  15. data/lib/pg_search/features/tsearch.rb +13 -12
  16. data/lib/pg_search/migration/templates/add_pg_search_dmetaphone_support_functions.rb.erb +6 -6
  17. data/lib/pg_search/migration/templates/create_pg_search_documents.rb.erb +2 -2
  18. data/lib/pg_search/model.rb +59 -0
  19. data/lib/pg_search/multisearch.rb +10 -1
  20. data/lib/pg_search/multisearch/rebuilder.rb +7 -3
  21. data/lib/pg_search/multisearchable.rb +4 -4
  22. data/lib/pg_search/scope_options.rb +2 -10
  23. data/lib/pg_search/tasks.rb +2 -1
  24. data/lib/pg_search/version.rb +1 -1
  25. data/pg_search.gemspec +10 -5
  26. data/spec/.rubocop.yml +2 -2
  27. data/spec/integration/.rubocop.yml +11 -0
  28. data/spec/integration/associations_spec.rb +36 -75
  29. data/spec/integration/deprecation_spec.rb +33 -0
  30. data/spec/integration/pagination_spec.rb +1 -1
  31. data/spec/integration/pg_search_spec.rb +199 -188
  32. data/spec/integration/single_table_inheritance_spec.rb +2 -2
  33. data/spec/lib/pg_search/configuration/association_spec.rb +10 -8
  34. data/spec/lib/pg_search/configuration/foreign_column_spec.rb +3 -3
  35. data/spec/lib/pg_search/features/dmetaphone_spec.rb +2 -2
  36. data/spec/lib/pg_search/features/trigram_spec.rb +48 -19
  37. data/spec/lib/pg_search/features/tsearch_spec.rb +16 -10
  38. data/spec/lib/pg_search/multisearch/rebuilder_spec.rb +124 -76
  39. data/spec/lib/pg_search/multisearch_spec.rb +49 -30
  40. data/spec/lib/pg_search/multisearchable_spec.rb +155 -101
  41. data/spec/lib/pg_search/normalizer_spec.rb +12 -10
  42. data/spec/lib/pg_search_spec.rb +62 -46
  43. data/spec/spec_helper.rb +13 -4
  44. data/spec/support/database.rb +1 -1
  45. metadata +90 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 154a4037a4ee2795a1cfa074afb2e762969db793cbbdecfbee26325ceaac6d7e
4
- data.tar.gz: ae17fccdcae3305c410acf036c28fd2bd5bbede25f5e13afe722cfcfb7a8c188
3
+ metadata.gz: 1c754738322b4dea0ecf3f70b8ddb03c5ff26bbe0f44578f6870c9f0e9fe6604
4
+ data.tar.gz: 4d8dc4be9b36a8a35cbaf6c759f9e973242e60c6b2eaf03b92d177297a7ad2b1
5
5
  SHA512:
6
- metadata.gz: aa942ecd16fbc913a084f17e06493f05ab95b7520bc212aa002fe1fc6386678e80638505fb2b5640ecaecd69212b956a1e7d03ed6475a30811db96d3de33a16e
7
- data.tar.gz: 6f648d0b981a95d4eb35ab1ab81c3fb199e25aefd3378032c3f7407fe8722c780c3542264f4dc99c5e7b9780dff02619ba6cd0fd34b36cd0ca4ae1565c7e083d
6
+ metadata.gz: '09b9d4b415a215bf24e38f1f3c80b309aaf7c4c52774e463f07db9f70496bf6bfde3bbd3fd0c69a4872ab531dc7a7fff098b6c11b1b7f5f0134b41e8feb73e4b'
7
+ data.tar.gz: a41a81af41368584b5cc4bbb6174c800e9d5dca906630db567cb908aa4280f921f2a1d579805d008dc77011b16d3b7ca5e025357cb0d51f777bd54cf848b8bc3
@@ -9,6 +9,7 @@ engines:
9
9
  enabled: true
10
10
  rubocop:
11
11
  enabled: true
12
+ channel: rubocop-0-78
12
13
  ratings:
13
14
  paths:
14
15
  - "**.rb"
@@ -0,0 +1,10 @@
1
+ # EditorConfig is awesome: https://EditorConfig.org
2
+
3
+ root = true
4
+
5
+ [*]
6
+ end_of_line = lf
7
+ insert_final_newline = true
8
+ charset = utf-8
9
+ indent_style = space
10
+ indent_size = 2
@@ -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/**/*
@@ -9,17 +15,17 @@ AllCops:
9
15
  Style/StringLiterals:
10
16
  Enabled: false
11
17
 
12
- Metrics/LineLength:
18
+ 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:
20
26
  - spec/**/*
21
27
 
22
- Layout/AlignParameters:
28
+ Layout/ParameterAlignment:
23
29
  EnforcedStyle: with_fixed_indentation
24
30
 
25
31
  Style/NumericPredicate:
@@ -44,8 +50,8 @@ Bundler/DuplicatedGem:
44
50
 
45
51
  Style/EmptyMethod:
46
52
  EnforcedStyle: expanded
47
-
48
- Layout/IndentArray:
53
+
54
+ Layout/FirstArrayElementIndentation:
49
55
  EnforcedStyle: consistent
50
56
 
51
57
  Style/Documentation:
@@ -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
@@ -1,38 +1,27 @@
1
1
  language: ruby
2
- sudo: false
3
2
  bundler_args: --binstubs
4
3
  cache: bundler
5
4
 
6
5
  rvm:
7
- - 2.6.3
8
- - 2.5.5
9
- - 2.4.6
10
- - jruby-9.2.6.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:
14
13
  - CC_TEST_REPORTER_ID=0a0e3e45118bc447e677d52c21d056a5471c4921d54f96ed7b2550d9fc5043ea
15
14
  matrix:
16
15
  - ACTIVE_RECORD_BRANCH="master"
17
- - ACTIVE_RECORD_BRANCH="5-2-stable"
18
- - ACTIVE_RECORD_VERSION="~> 6.0.0.beta1"
16
+ - ACTIVE_RECORD_BRANCH="6-0-stable"
17
+ - ACTIVE_RECORD_VERSION="~> 6.0.0"
19
18
  - ACTIVE_RECORD_VERSION="~> 5.2.0"
20
- - ACTIVE_RECORD_VERSION="~> 5.1.0"
21
- - ACTIVE_RECORD_VERSION="~> 5.0.0"
22
- - ACTIVE_RECORD_VERSION="~> 4.2.9"
19
+
23
20
 
24
21
  matrix:
25
22
  allow_failures:
26
23
  - env: ACTIVE_RECORD_BRANCH="master"
27
- - env: ACTIVE_RECORD_BRANCH="5-2-stable"
28
- - env: ACTIVE_RECORD_VERSION="~> 6.0.0.beta1"
29
- exclude:
30
- - rvm: 2.4.6
31
- env: ACTIVE_RECORD_BRANCH="master"
32
- - rvm: jruby-9.2.6.0
33
- env: ACTIVE_RECORD_VERSION="~> 4.2.9"
34
- - rvm: 2.4.5
35
- env: ACTIVE_RECORD_VERSION="~> 6.0.0.beta1"
24
+ - env: ACTIVE_RECORD_BRANCH="6-0-stable"
36
25
 
37
26
  before_script:
38
27
  - psql --version
@@ -46,5 +35,8 @@ script: bin/rake
46
35
  after_script:
47
36
  - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
48
37
 
38
+ jdk:
39
+ - openjdk8
40
+
49
41
  addons:
50
42
  postgresql: "9.6"
@@ -1,43 +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
+
8
+ ## 2.3.2
9
+
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)
12
+
13
+ ## 2.3.1
14
+
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)
17
+
18
+ ## 2.3.0
19
+
20
+ * Extract `PgSearch::Model` module.
21
+ * Deprecate `include PgSearch`. Use `include PgSearch::Model` instead.
22
+
23
+ ## 2.2.0
24
+
25
+ * Add `word_similarity` option to trigram search. (Severin Räz)
26
+
3
27
  ## 2.1.7
4
28
 
5
- * Restore link to GitHub repository to original location
29
+ * Restore link to GitHub repository to original location.
6
30
 
7
31
  ## 2.1.6
8
32
 
9
- * Update link to GitHub repository to new location
33
+ * Update link to GitHub repository to new location.
10
34
 
11
35
  ## 2.1.5
12
36
 
13
- * Drop support for Ruby < 2.4
37
+ * Drop support for Ruby < 2.4.
14
38
 
15
39
  ## 2.1.4
16
40
 
17
- * Drop support for Ruby < 2.3
18
- * Use update instead of deprecated update_attributes
19
- * 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.
20
44
 
21
45
  ## 2.1.3
22
46
 
23
47
  * Drop support for Ruby < 2.2
24
- * Disallow left/right single quotation marks in tsquery (Fabian Schwahn) (#382)
25
- * Do not attempt to save an already-destroy PgSearch::Document (Oleg Dashevskii, Vokhmin Aleksei V) (#353)
26
- * 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)
27
51
 
28
52
  ## 2.1.2
29
53
 
30
- * Silence warnings in Rails 5.2.0.beta2 (Kevin Deisz)
54
+ * Silence warnings in Rails 5.2.0.beta2. (Kevin Deisz)
31
55
 
32
56
  ## 2.1.1
33
57
 
34
- * Support snake_case ts_headline options again (with deprecation warning)
58
+ * Support snake_case `ts_headline` options again. (with deprecation warning)
35
59
 
36
60
  ## 2.1.0
37
61
 
38
- * Allow ts_headline options to be passed to :highlight (Ian Heisters)
39
- * Wait to load PgSearch::Document until after Active Record has loaded (Logan Leger)
40
- * 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)
41
65
 
42
66
  ## 2.0.1
43
67
 
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
6
 
7
- gem 'pg', '>= 0.21.0', '< 1.0.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
10
  if ENV['ACTIVE_RECORD_BRANCH']
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,8 +16,8 @@ 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+
20
- * ActiveRecord 4.2+
19
+ * Ruby 2.5+
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
23
23
 
@@ -49,7 +49,7 @@ To add PgSearch to an Active Record model, simply include the PgSearch module.
49
49
 
50
50
  ```ruby
51
51
  class Shape < ActiveRecord::Base
52
- include PgSearch
52
+ include PgSearch::Model
53
53
  end
54
54
  ```
55
55
 
@@ -87,12 +87,12 @@ multisearchable in its class definition.
87
87
 
88
88
  ```ruby
89
89
  class EpicPoem < ActiveRecord::Base
90
- include PgSearch
90
+ include PgSearch::Model
91
91
  multisearchable against: [:title, :author]
92
92
  end
93
93
 
94
94
  class Flower < ActiveRecord::Base
95
- include PgSearch
95
+ include PgSearch::Model
96
96
  multisearchable against: :color
97
97
  end
98
98
  ```
@@ -112,13 +112,13 @@ particular record should be included.
112
112
 
113
113
  ```ruby
114
114
  class Convertible < ActiveRecord::Base
115
- include PgSearch
115
+ include PgSearch::Model
116
116
  multisearchable against: [:make, :model],
117
117
  if: :available_in_red?
118
118
  end
119
119
 
120
120
  class Jalopy < ActiveRecord::Base
121
- include PgSearch
121
+ include PgSearch::Model
122
122
  multisearchable against: [:make, :model],
123
123
  if: lambda { |record| record.model_year > 1970 }
124
124
  end
@@ -132,7 +132,7 @@ timestamp.
132
132
 
133
133
  ```ruby
134
134
  class AntipatternExample
135
- include PgSearch
135
+ include PgSearch::Model
136
136
  multisearchable against: [:contents],
137
137
  if: :published?
138
138
 
@@ -175,15 +175,17 @@ multisearchable(
175
175
 
176
176
  **Specify additional attributes to be saved on the pg_search_documents table**
177
177
 
178
- You can specify `:additional_attributes` to be saved within the pg_search_documents table. For example, perhaps you are indexing a book model and an article model and wanted to include the author_id.
178
+ You can specify `:additional_attributes` to be saved within the `pg_search_documents` table. For example, perhaps you are indexing a book model and an article model and wanted to include the author_id.
179
179
 
180
- First, we need to add `author_id` to the migration creating our pg_search_documents table.
180
+ First, we need to add a reference to author to the migration creating our `pg_search_documents` table.
181
181
 
182
182
  ```ruby
183
183
  create_table :pg_search_documents do |t|
184
- t.text :content
185
- t.integer :author_id
186
- t.belongs_to :searchable, polymorphic: true, index: true
184
+ t.text :content
185
+ t.references :author, index: true
186
+ t.belongs_to :searchable, polymorphic: true, index: true
187
+ t.timestamps null: false
188
+ end
187
189
  ```
188
190
 
189
191
  Then, we can send in this additional attribute in a lambda
@@ -196,7 +198,10 @@ Then, we can send in this additional attribute in a lambda
196
198
  ```
197
199
 
198
200
  This allows much faster searches without joins later on by doing something like:
199
- `PgSearch.multisearch(params['search']).where(author_id: 2)`
201
+
202
+ ```ruby
203
+ PgSearch.multisearch(params['search']).where(author_id: 2)
204
+ ```
200
205
 
201
206
  *NOTE: You must currently manually call `record.update_pg_search_document` for the additional attribute to be included in the pg_search_documents table*
202
207
 
@@ -289,7 +294,7 @@ is your base class. You can prevent ```rebuild``` from deleting your records
289
294
  like so:
290
295
 
291
296
  ```ruby
292
- PgSearch::Multisearch.rebuild(Product, false)
297
+ PgSearch::Multisearch.rebuild(Product, clean_up: false)
293
298
  ```
294
299
 
295
300
  Rebuild is also available as a Rake task, for convenience.
@@ -333,7 +338,7 @@ class Movie < ActiveRecord::Base
333
338
 
334
339
  # More sophisticated approach
335
340
  def self.rebuild_pg_search_documents
336
- connection.execute <<-SQL
341
+ connection.execute <<~SQL.squish
337
342
  INSERT INTO pg_search_documents (searchable_type, searchable_id, content, created_at, updated_at)
338
343
  SELECT 'Movie' AS searchable_type,
339
344
  movies.id AS searchable_id,
@@ -374,7 +379,7 @@ To search against a column, pass a symbol as the :against option.
374
379
 
375
380
  ```ruby
376
381
  class BlogPost < ActiveRecord::Base
377
- include PgSearch
382
+ include PgSearch::Model
378
383
  pg_search_scope :search_by_title, against: :title
379
384
  end
380
385
  ```
@@ -394,7 +399,7 @@ Just pass an Array if you'd like to search more than one column.
394
399
 
395
400
  ```ruby
396
401
  class Person < ActiveRecord::Base
397
- include PgSearch
402
+ include PgSearch::Model
398
403
  pg_search_scope :search_by_full_name, against: [:first_name, :last_name]
399
404
  end
400
405
  ```
@@ -421,7 +426,7 @@ value if you wanted.
421
426
 
422
427
  ```ruby
423
428
  class Person < ActiveRecord::Base
424
- include PgSearch
429
+ include PgSearch::Model
425
430
  pg_search_scope :search_by_name, lambda { |name_part, query|
426
431
  raise ArgumentError unless [:first, :last].include?(name_part)
427
432
  {
@@ -459,7 +464,7 @@ class Cheese < ActiveRecord::Base
459
464
  end
460
465
 
461
466
  class Salami < ActiveRecord::Base
462
- include PgSearch
467
+ include PgSearch::Model
463
468
 
464
469
  belongs_to :cracker
465
470
  has_many :cheeses, through: :cracker
@@ -494,7 +499,7 @@ search techniques.
494
499
 
495
500
  ```ruby
496
501
  class Beer < ActiveRecord::Base
497
- include PgSearch
502
+ include PgSearch::Model
498
503
  pg_search_scope :search_name, against: :name, using: [:tsearch, :trigram, :dmetaphone]
499
504
  end
500
505
  ```
@@ -520,7 +525,7 @@ subtitle, and finally the content.
520
525
 
521
526
  ```ruby
522
527
  class NewsArticle < ActiveRecord::Base
523
- include PgSearch
528
+ include PgSearch::Model
524
529
  pg_search_scope :search_full_text, against: {
525
530
  title: 'A',
526
531
  subtitle: 'B',
@@ -535,7 +540,7 @@ weight. If you omit the weight, a default will be used.
535
540
 
536
541
  ```ruby
537
542
  class NewsArticle < ActiveRecord::Base
538
- include PgSearch
543
+ include PgSearch::Model
539
544
  pg_search_scope :search_full_text, against: [
540
545
  [:title, 'A'],
541
546
  [:subtitle, 'B'],
@@ -544,7 +549,7 @@ class NewsArticle < ActiveRecord::Base
544
549
  end
545
550
 
546
551
  class NewsArticle < ActiveRecord::Base
547
- include PgSearch
552
+ include PgSearch::Model
548
553
  pg_search_scope :search_full_text, against: [
549
554
  [:title, 'A'],
550
555
  {subtitle: 'B'},
@@ -562,7 +567,7 @@ shown in the following example.
562
567
 
563
568
  ```ruby
564
569
  class Superhero < ActiveRecord::Base
565
- include PgSearch
570
+ include PgSearch::Model
566
571
  pg_search_scope :whose_name_starts_with,
567
572
  against: :name,
568
573
  using: {
@@ -591,7 +596,7 @@ term that you were trying to exclude.
591
596
 
592
597
  ```ruby
593
598
  class Animal < ActiveRecord::Base
594
- include PgSearch
599
+ include PgSearch::Model
595
600
  pg_search_scope :with_name_matching,
596
601
  against: :name,
597
602
  using: {
@@ -620,7 +625,7 @@ dictionary will be used.
620
625
 
621
626
  ```ruby
622
627
  class BoringTweet < ActiveRecord::Base
623
- include PgSearch
628
+ include PgSearch::Model
624
629
  pg_search_scope :kinda_matching,
625
630
  against: :text,
626
631
  using: {
@@ -664,7 +669,7 @@ their numbers together.
664
669
 
665
670
  ```ruby
666
671
  class BigLongDocument < ActiveRecord::Base
667
- include PgSearch
672
+ include PgSearch::Model
668
673
  pg_search_scope :regular_search,
669
674
  against: :text
670
675
 
@@ -688,7 +693,7 @@ models containing any word in the search terms.
688
693
 
689
694
  ```ruby
690
695
  class Number < ActiveRecord::Base
691
- include PgSearch
696
+ include PgSearch::Model
692
697
  pg_search_scope :search_any_word,
693
698
  against: :text,
694
699
  using: {
@@ -714,11 +719,11 @@ but will not include it in the query's WHERE condition.
714
719
 
715
720
  ```ruby
716
721
  class Person < ActiveRecord::Base
717
- include PgSearch
722
+ include PgSearch::Model
718
723
  pg_search_scope :search,
719
724
  against: :name,
720
725
  using: {
721
- tsearch: {any_word: true}
726
+ tsearch: {any_word: true},
722
727
  dmetaphone: {any_word: true, sort_only: true}
723
728
  }
724
729
  end
@@ -739,7 +744,7 @@ Adding .with_pg_search_highlight after the pg_search_scope you can access to
739
744
 
740
745
  ```ruby
741
746
  class Person < ActiveRecord::Base
742
- include PgSearch
747
+ include PgSearch::Model
743
748
  pg_search_scope :search,
744
749
  against: :bio,
745
750
  using: {
@@ -793,7 +798,7 @@ The following example shows how to use :dmetaphone.
793
798
 
794
799
  ```ruby
795
800
  class Word < ActiveRecord::Base
796
- include PgSearch
801
+ include PgSearch::Model
797
802
  pg_search_scope :that_sounds_like,
798
803
  against: :spelling,
799
804
  using: :dmetaphone
@@ -824,7 +829,7 @@ feature can be used.
824
829
 
825
830
  ```ruby
826
831
  class Website < ActiveRecord::Base
827
- include PgSearch
832
+ include PgSearch::Model
828
833
  pg_search_scope :kinda_spelled_like,
829
834
  against: :name,
830
835
  using: :trigram
@@ -849,7 +854,7 @@ threshold will force a table scan as the derived query uses the
849
854
 
850
855
  ```ruby
851
856
  class Vegetable < ActiveRecord::Base
852
- include PgSearch
857
+ include PgSearch::Model
853
858
 
854
859
  pg_search_scope :strictly_spelled_like,
855
860
  against: :name,
@@ -877,6 +882,37 @@ Vegetable.roughly_spelled_like("collyflower") # => [cauliflower]
877
882
  Vegetable.strictly_spelled_like("collyflower") # => []
878
883
  ```
879
884
 
885
+ ##### :word_similarity
886
+
887
+ Allows you to match words in longer strings.
888
+ By default, trigram searches use `%` or `similarity()` as a similarity value.
889
+ Set `word_similarity` to `true` to opt for `<%` and `word_similarity` instead.
890
+ This causes the trigram search to use the similarity of the query term
891
+ and the word with greatest similarity.
892
+
893
+ ```ruby
894
+ class Sentence < ActiveRecord::Base
895
+ include PgSearch::Model
896
+
897
+ pg_search_scope :similarity_like,
898
+ against: :name,
899
+ using: {
900
+ trigram: {
901
+ word_similarity: true
902
+ }
903
+ }
904
+
905
+ pg_search_scope :word_similarity_like,
906
+ against: :name,
907
+ using: [:trigram]
908
+ end
909
+
910
+ sentence = Sentence.create! name: "Those are two words."
911
+
912
+ Sentence.similarity_like("word") # => []
913
+ Sentence.word_similarity_like("word") # => [sentence]
914
+ ```
915
+
880
916
  ### Limiting Fields When Combining Features
881
917
 
882
918
  Sometimes when doing queries combining different features you
@@ -887,7 +923,7 @@ which fields using the 'only' option:
887
923
 
888
924
  ```ruby
889
925
  class Image < ActiveRecord::Base
890
- include PgSearch
926
+ include PgSearch::Model
891
927
 
892
928
  pg_search_scope :combined_search,
893
929
  against: [:file_name, :short_description, :long_description]
@@ -922,7 +958,7 @@ must be installed before this feature can be used.
922
958
 
923
959
  ```ruby
924
960
  class SpanishQuestion < ActiveRecord::Base
925
- include PgSearch
961
+ include PgSearch::Model
926
962
  pg_search_scope :gringo_search,
927
963
  against: :word,
928
964
  ignoring: :accents
@@ -1112,15 +1148,11 @@ Patterson](http://tenderlovemaking.com/) for the original version and to Caseboo
1112
1148
 
1113
1149
  ## CONTRIBUTIONS AND FEEDBACK
1114
1150
 
1115
- Welcomed! Feel free to join and contribute to our [public Pivotal Tracker
1116
- project](https://www.pivotaltracker.com/projects/228645) where we manage new
1117
- feature ideas and bugs.
1151
+ Please read our [CONTRIBUTING guide](https://github.com/Casecommons/pg_search/blob/master/CONTRIBUTING.md).
1118
1152
 
1119
1153
  We also have a [Google Group](http://groups.google.com/group/casecommons-dev)
1120
1154
  for discussing pg_search and other Casebook PBC open source projects.
1121
1155
 
1122
- Please read our [CONTRIBUTING guide](https://github.com/Casecommons/pg_search/blob/master/CONTRIBUTING.md).
1123
-
1124
1156
  ## LICENSE
1125
1157
 
1126
1158
  Copyright © 2010–2019 [Casebook PBC](http://www.casebook.net).