pg_search 2.2.0 → 2.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +1 -0
- data/.editorconfig +10 -0
- data/.github/dependabot.yml +11 -0
- data/.rubocop.yml +88 -7
- data/.travis.yml +11 -19
- data/CHANGELOG.md +40 -15
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/README.md +46 -45
- data/lib/pg_search.rb +13 -56
- data/lib/pg_search/document.rb +2 -2
- data/lib/pg_search/features/dmetaphone.rb +4 -6
- data/lib/pg_search/features/tsearch.rb +13 -12
- data/lib/pg_search/migration/templates/add_pg_search_dmetaphone_support_functions.rb.erb +6 -6
- data/lib/pg_search/migration/templates/create_pg_search_documents.rb.erb +2 -2
- data/lib/pg_search/model.rb +57 -0
- data/lib/pg_search/multisearch.rb +10 -1
- data/lib/pg_search/multisearch/rebuilder.rb +7 -3
- data/lib/pg_search/scope_options.rb +2 -2
- data/lib/pg_search/tasks.rb +2 -1
- data/lib/pg_search/version.rb +1 -1
- data/pg_search.gemspec +9 -5
- data/spec/.rubocop.yml +2 -2
- data/spec/integration/.rubocop.yml +11 -0
- data/spec/integration/associations_spec.rb +27 -66
- data/spec/integration/deprecation_spec.rb +33 -0
- data/spec/integration/pagination_spec.rb +1 -1
- data/spec/integration/pg_search_spec.rb +70 -59
- data/spec/integration/single_table_inheritance_spec.rb +2 -2
- data/spec/lib/pg_search/configuration/association_spec.rb +10 -8
- data/spec/lib/pg_search/configuration/foreign_column_spec.rb +1 -1
- data/spec/lib/pg_search/features/dmetaphone_spec.rb +2 -2
- data/spec/lib/pg_search/features/trigram_spec.rb +15 -11
- data/spec/lib/pg_search/features/tsearch_spec.rb +16 -10
- data/spec/lib/pg_search/multisearch/rebuilder_spec.rb +124 -76
- data/spec/lib/pg_search/multisearch_spec.rb +49 -30
- data/spec/lib/pg_search/multisearchable_spec.rb +155 -101
- data/spec/lib/pg_search/normalizer_spec.rb +12 -10
- data/spec/lib/pg_search_spec.rb +59 -46
- data/spec/spec_helper.rb +13 -4
- data/spec/support/database.rb +1 -1
- metadata +76 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a217bfd36241c2a3b7e9d496fbcafcda084f0ab87c50baaee487ed3ad1349774
|
4
|
+
data.tar.gz: 2adb9c974d6b1d00fbf89be865c1901e759de8956daa8b5795407a51468abc6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16e3c8d3a801a3e2cee0a38b42de4ce5d74142c08be3908fbc733b591312047df33e4ec0101d7e2029646d4476d9875146d64bed90cb3492bd921967462eee01
|
7
|
+
data.tar.gz: 0d5507703452f0b8607d2bb3ea355375ab88dcbf99fdc8239fe0a255820ad782e3d7ecd9101f28bde9f2df2c092aa323cb1c7d23c6460bd967b070efde4a33a8
|
data/.codeclimate.yml
CHANGED
data/.editorconfig
ADDED
@@ -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"
|
data/.rubocop.yml
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
-
require:
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rails
|
4
|
+
- rubocop-rake
|
5
|
+
- rubocop-rspec
|
2
6
|
|
3
7
|
AllCops:
|
4
|
-
TargetRubyVersion: 2.
|
8
|
+
TargetRubyVersion: 2.5
|
9
|
+
NewCops: enable
|
5
10
|
Exclude:
|
6
11
|
- bin/**/*
|
7
12
|
- vendor/**/*
|
@@ -9,17 +14,17 @@ AllCops:
|
|
9
14
|
Style/StringLiterals:
|
10
15
|
Enabled: false
|
11
16
|
|
12
|
-
|
17
|
+
Layout/LineLength:
|
13
18
|
Max: 120
|
14
19
|
|
15
20
|
Metrics/MethodLength:
|
16
|
-
Max:
|
21
|
+
Max: 15
|
17
22
|
|
18
23
|
Metrics/BlockLength:
|
19
24
|
Exclude:
|
20
25
|
- spec/**/*
|
21
26
|
|
22
|
-
Layout/
|
27
|
+
Layout/ParameterAlignment:
|
23
28
|
EnforcedStyle: with_fixed_indentation
|
24
29
|
|
25
30
|
Style/NumericPredicate:
|
@@ -44,8 +49,8 @@ Bundler/DuplicatedGem:
|
|
44
49
|
|
45
50
|
Style/EmptyMethod:
|
46
51
|
EnforcedStyle: expanded
|
47
|
-
|
48
|
-
Layout/
|
52
|
+
|
53
|
+
Layout/FirstArrayElementIndentation:
|
49
54
|
EnforcedStyle: consistent
|
50
55
|
|
51
56
|
Style/Documentation:
|
@@ -54,3 +59,79 @@ Style/Documentation:
|
|
54
59
|
Style/WordArray:
|
55
60
|
EnforcedStyle: percent
|
56
61
|
MinSize: 3
|
62
|
+
|
63
|
+
Style/HashEachMethods:
|
64
|
+
Enabled: true
|
65
|
+
|
66
|
+
Style/HashTransformKeys:
|
67
|
+
Enabled: true
|
68
|
+
|
69
|
+
Style/HashTransformValues:
|
70
|
+
Enabled: true
|
71
|
+
|
72
|
+
Rails/ApplicationRecord:
|
73
|
+
Enabled: false
|
74
|
+
|
75
|
+
Rails/TimeZone:
|
76
|
+
Enabled: false
|
77
|
+
|
78
|
+
RSpec/ContextWording:
|
79
|
+
Prefixes:
|
80
|
+
- using
|
81
|
+
- via
|
82
|
+
- when
|
83
|
+
- with
|
84
|
+
- without
|
85
|
+
|
86
|
+
Lint/RaiseException:
|
87
|
+
Enabled: true
|
88
|
+
|
89
|
+
Lint/StructNewOverride:
|
90
|
+
Enabled: true
|
91
|
+
|
92
|
+
Layout/SpaceAroundMethodCallOperator:
|
93
|
+
Enabled: true
|
94
|
+
|
95
|
+
Style/ExponentialNotation:
|
96
|
+
Enabled: true
|
97
|
+
|
98
|
+
RSpec/DescribedClass:
|
99
|
+
Enabled: true
|
100
|
+
|
101
|
+
RSpec/ExpectInHook:
|
102
|
+
Enabled: false
|
103
|
+
|
104
|
+
RSpec/FilePath:
|
105
|
+
CustomTransform:
|
106
|
+
TSearch: "tsearch"
|
107
|
+
DMetaphone: "dmetaphone"
|
108
|
+
|
109
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
110
|
+
Enabled: true
|
111
|
+
|
112
|
+
Lint/DeprecatedOpenSSLConstant:
|
113
|
+
Enabled: true
|
114
|
+
|
115
|
+
Style/SlicingWithRange:
|
116
|
+
Enabled: true
|
117
|
+
|
118
|
+
Lint/MixedRegexpCaptureTypes:
|
119
|
+
Enabled: true
|
120
|
+
|
121
|
+
Style/RedundantFetchBlock:
|
122
|
+
Enabled: true
|
123
|
+
|
124
|
+
Style/RedundantRegexpCharacterClass:
|
125
|
+
Enabled: true
|
126
|
+
|
127
|
+
Style/RedundantRegexpEscape:
|
128
|
+
Enabled: true
|
129
|
+
|
130
|
+
RSpec/MultipleExpectations:
|
131
|
+
Max: 5
|
132
|
+
|
133
|
+
RSpec/MultipleMemoizedHelpers:
|
134
|
+
AllowSubject: true
|
135
|
+
|
136
|
+
RSpec/ExampleLength:
|
137
|
+
Max: 15
|
data/.travis.yml
CHANGED
@@ -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.
|
8
|
-
- 2.
|
9
|
-
- 2.
|
10
|
-
- jruby-9.2.
|
6
|
+
- 2.7.2
|
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="
|
18
|
-
- ACTIVE_RECORD_VERSION="~> 6.0.0
|
16
|
+
- ACTIVE_RECORD_BRANCH="6-0-stable"
|
17
|
+
- ACTIVE_RECORD_VERSION="~> 6.0.0"
|
19
18
|
- ACTIVE_RECORD_VERSION="~> 5.2.0"
|
20
|
-
|
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="
|
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"
|
data/CHANGELOG.md
CHANGED
@@ -1,47 +1,72 @@
|
|
1
1
|
# pg_search changelog
|
2
2
|
|
3
|
+
## 2.3.4
|
4
|
+
|
5
|
+
* Fix issue when setting various options directly on the `PgSearch` module while
|
6
|
+
running with a threaded web server, such as Puma. (Anton Rieder)
|
7
|
+
|
8
|
+
## 2.3.3
|
9
|
+
|
10
|
+
* Drop support for Ruby < 2.5.
|
11
|
+
* Use keyword argument for `clean_up` setting in `PgSearch::Multisearch.rebuild`.
|
12
|
+
|
13
|
+
## 2.3.2
|
14
|
+
|
15
|
+
* Autoload `PgSearch::Document` to prevent it from being loaded in projects that are not using multi-search.
|
16
|
+
* Rebuilder should use `update_pg_search_document` if `additional_attributes` is set. (David Ramalho)
|
17
|
+
|
18
|
+
## 2.3.1
|
19
|
+
|
20
|
+
* Drop support for Active Record < 5.2.
|
21
|
+
* Do not load railtie unless Rails::Railtie is defined, to avoid problem when loading alongside Action Mailer. (Adam Schwartz)
|
22
|
+
|
23
|
+
## 2.3.0
|
24
|
+
|
25
|
+
* Extract `PgSearch::Model` module.
|
26
|
+
* Deprecate `include PgSearch`. Use `include PgSearch::Model` instead.
|
27
|
+
|
3
28
|
## 2.2.0
|
4
29
|
|
5
|
-
* Add word_similarity option to trigram search (Severin Räz)
|
30
|
+
* Add `word_similarity` option to trigram search. (Severin Räz)
|
6
31
|
|
7
32
|
## 2.1.7
|
8
33
|
|
9
|
-
* Restore link to GitHub repository to original location
|
34
|
+
* Restore link to GitHub repository to original location.
|
10
35
|
|
11
36
|
## 2.1.6
|
12
37
|
|
13
|
-
* Update link to GitHub repository to new location
|
38
|
+
* Update link to GitHub repository to new location.
|
14
39
|
|
15
40
|
## 2.1.5
|
16
41
|
|
17
|
-
* Drop support for Ruby < 2.4
|
42
|
+
* Drop support for Ruby < 2.4.
|
18
43
|
|
19
44
|
## 2.1.4
|
20
45
|
|
21
|
-
* Drop support for Ruby < 2.3
|
22
|
-
* Use update instead of deprecated update_attributes
|
23
|
-
* Remove explicit
|
46
|
+
* Drop support for Ruby < 2.3.
|
47
|
+
* Use `update` instead of deprecated `update_attributes`.
|
48
|
+
* Remove explicit Arel dependency to better support Active Record 6 beta.
|
24
49
|
|
25
50
|
## 2.1.3
|
26
51
|
|
27
52
|
* Drop support for Ruby < 2.2
|
28
|
-
* Disallow left/right single quotation marks in tsquery (Fabian Schwahn) (#382)
|
29
|
-
* Do not attempt to save an already-
|
30
|
-
* Quote column name when rebuilding (Jed Levin) (#379)
|
53
|
+
* Disallow left/right single quotation marks in tsquery. (Fabian Schwahn) (#382)
|
54
|
+
* Do not attempt to save an already-destroyed `PgSearch::Document`. (Oleg Dashevskii, Vokhmin Aleksei V) (#353)
|
55
|
+
* Quote column name when rebuilding. (Jed Levin) (#379)
|
31
56
|
|
32
57
|
## 2.1.2
|
33
58
|
|
34
|
-
* Silence warnings in Rails 5.2.0.beta2 (Kevin Deisz)
|
59
|
+
* Silence warnings in Rails 5.2.0.beta2. (Kevin Deisz)
|
35
60
|
|
36
61
|
## 2.1.1
|
37
62
|
|
38
|
-
* Support snake_case ts_headline options again (with deprecation warning)
|
63
|
+
* Support snake_case `ts_headline` options again. (with deprecation warning)
|
39
64
|
|
40
65
|
## 2.1.0
|
41
66
|
|
42
|
-
* Allow ts_headline options to be passed to
|
43
|
-
* Wait to load PgSearch::Document until after Active Record has loaded (Logan Leger)
|
44
|
-
* Add Rails version to generated migrations (Erik Eide)
|
67
|
+
* Allow `ts_headline` options to be passed to `:highlight`. (Ian Heisters)
|
68
|
+
* Wait to load `PgSearch::Document` until after Active Record has loaded. (Logan Leger)
|
69
|
+
* Add Rails version to generated migrations. (Erik Eide)
|
45
70
|
|
46
71
|
## 2.0.1
|
47
72
|
|
data/Gemfile
CHANGED
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2010-
|
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.
|
20
|
-
* ActiveRecord
|
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
|
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
|
-
|
185
|
-
|
186
|
-
|
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
|
-
|
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
|
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,
|
@@ -887,10 +892,10 @@ and the word with greatest similarity.
|
|
887
892
|
|
888
893
|
```ruby
|
889
894
|
class Sentence < ActiveRecord::Base
|
890
|
-
include PgSearch
|
895
|
+
include PgSearch::Model
|
891
896
|
|
892
897
|
pg_search_scope :similarity_like,
|
893
|
-
against: :
|
898
|
+
against: :name,
|
894
899
|
using: {
|
895
900
|
trigram: {
|
896
901
|
word_similarity: true
|
@@ -898,7 +903,7 @@ class Sentence < ActiveRecord::Base
|
|
898
903
|
}
|
899
904
|
|
900
905
|
pg_search_scope :word_similarity_like,
|
901
|
-
against: :
|
906
|
+
against: :name,
|
902
907
|
using: [:trigram]
|
903
908
|
end
|
904
909
|
|
@@ -918,7 +923,7 @@ which fields using the 'only' option:
|
|
918
923
|
|
919
924
|
```ruby
|
920
925
|
class Image < ActiveRecord::Base
|
921
|
-
include PgSearch
|
926
|
+
include PgSearch::Model
|
922
927
|
|
923
928
|
pg_search_scope :combined_search,
|
924
929
|
against: [:file_name, :short_description, :long_description]
|
@@ -953,7 +958,7 @@ must be installed before this feature can be used.
|
|
953
958
|
|
954
959
|
```ruby
|
955
960
|
class SpanishQuestion < ActiveRecord::Base
|
956
|
-
include PgSearch
|
961
|
+
include PgSearch::Model
|
957
962
|
pg_search_scope :gringo_search,
|
958
963
|
against: :word,
|
959
964
|
ignoring: :accents
|
@@ -1143,15 +1148,11 @@ Patterson](http://tenderlovemaking.com/) for the original version and to Caseboo
|
|
1143
1148
|
|
1144
1149
|
## CONTRIBUTIONS AND FEEDBACK
|
1145
1150
|
|
1146
|
-
|
1147
|
-
project](https://www.pivotaltracker.com/projects/228645) where we manage new
|
1148
|
-
feature ideas and bugs.
|
1151
|
+
Please read our [CONTRIBUTING guide](https://github.com/Casecommons/pg_search/blob/master/CONTRIBUTING.md).
|
1149
1152
|
|
1150
1153
|
We also have a [Google Group](http://groups.google.com/group/casecommons-dev)
|
1151
1154
|
for discussing pg_search and other Casebook PBC open source projects.
|
1152
1155
|
|
1153
|
-
Please read our [CONTRIBUTING guide](https://github.com/Casecommons/pg_search/blob/master/CONTRIBUTING.md).
|
1154
|
-
|
1155
1156
|
## LICENSE
|
1156
1157
|
|
1157
1158
|
Copyright © 2010–2019 [Casebook PBC](http://www.casebook.net).
|