pg_search 2.3.5 → 2.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +80 -0
- data/.standard.yml +6 -0
- data/CHANGELOG.md +20 -0
- data/Gemfile +19 -6
- data/LICENSE +1 -1
- data/README.md +61 -39
- data/Rakefile +9 -6
- data/lib/pg_search/configuration/column.rb +6 -4
- data/lib/pg_search/configuration/foreign_column.rb +1 -1
- data/lib/pg_search/configuration.rb +13 -3
- data/lib/pg_search/document.rb +8 -8
- data/lib/pg_search/features/dmetaphone.rb +1 -1
- data/lib/pg_search/features/feature.rb +1 -1
- data/lib/pg_search/features/trigram.rb +4 -4
- data/lib/pg_search/features/tsearch.rb +15 -14
- data/lib/pg_search/migration/dmetaphone_generator.rb +2 -2
- data/lib/pg_search/migration/generator.rb +5 -5
- data/lib/pg_search/migration/multisearch_generator.rb +2 -2
- data/lib/pg_search/model.rb +6 -6
- data/lib/pg_search/multisearch.rb +16 -6
- data/lib/pg_search/multisearchable.rb +7 -7
- data/lib/pg_search/normalizer.rb +5 -5
- data/lib/pg_search/scope_options.rb +28 -10
- data/lib/pg_search/tasks.rb +2 -2
- data/lib/pg_search/version.rb +1 -1
- data/lib/pg_search.rb +5 -5
- data/pg_search.gemspec +17 -29
- data/spec/.rubocop.yml +20 -7
- data/spec/integration/.rubocop.yml +2 -2
- data/spec/integration/associations_spec.rb +106 -106
- data/spec/integration/deprecation_spec.rb +7 -8
- data/spec/integration/pg_search_spec.rb +339 -292
- data/spec/integration/single_table_inheritance_spec.rb +5 -5
- data/spec/lib/pg_search/configuration/association_spec.rb +15 -15
- data/spec/lib/pg_search/configuration/column_spec.rb +13 -1
- data/spec/lib/pg_search/configuration/foreign_column_spec.rb +4 -4
- data/spec/lib/pg_search/features/dmetaphone_spec.rb +4 -4
- data/spec/lib/pg_search/features/trigram_spec.rb +28 -28
- data/spec/lib/pg_search/features/tsearch_spec.rb +57 -39
- data/spec/lib/pg_search/multisearch/rebuilder_spec.rb +17 -17
- data/spec/lib/pg_search/multisearch_spec.rb +15 -6
- data/spec/lib/pg_search/multisearchable_spec.rb +26 -26
- data/spec/lib/pg_search/normalizer_spec.rb +7 -7
- data/spec/lib/pg_search_spec.rb +20 -20
- data/spec/spec_helper.rb +15 -9
- data/spec/support/database.rb +9 -7
- metadata +13 -188
- data/.autotest +0 -5
- data/.codeclimate.yml +0 -17
- data/.rubocop.yml +0 -134
- data/.travis.yml +0 -42
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 103352d5afaf431080a49411b6e7bce5c2d1edec6aa88da55913fb179ef02367
|
|
4
|
+
data.tar.gz: fea6642ba781bb1916f32d46fe25f829c34d27564c23674dde4c80f97a5a43db
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d550e544579fddb2ef4b2667a93624f9b293102db705e304b048bd0eaa328d908c3415028324a35e038353e7a47ac334e53e2a6f381abe2456de835c4d04c359
|
|
7
|
+
data.tar.gz: b896f972762290dda0d9e744680c707223188e6a5ceb05329cdc3479f302c1a18dd11b20bcd5ebffe66cc36143c182318b51e9e88e63463cfb55d7d0d8890d6b
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
name: build
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
- github-actions
|
|
8
|
+
pull_request:
|
|
9
|
+
branches:
|
|
10
|
+
- master
|
|
11
|
+
schedule:
|
|
12
|
+
- cron: "0 18 * * 6" # Saturdays at 12pm CST
|
|
13
|
+
workflow_dispatch:
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
test:
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
services:
|
|
19
|
+
postgres:
|
|
20
|
+
image: postgres:latest
|
|
21
|
+
env:
|
|
22
|
+
POSTGRES_USER: postgres
|
|
23
|
+
POSTGRES_PASSWORD: postgres
|
|
24
|
+
options: >-
|
|
25
|
+
--health-cmd pg_isready
|
|
26
|
+
--health-interval 10s
|
|
27
|
+
--health-timeout 5s
|
|
28
|
+
--health-retries 5
|
|
29
|
+
ports:
|
|
30
|
+
- 5432:5432
|
|
31
|
+
env:
|
|
32
|
+
CI: true
|
|
33
|
+
PGHOST: 127.0.0.1
|
|
34
|
+
PGUSER: postgres
|
|
35
|
+
PGPASS: postgres
|
|
36
|
+
strategy:
|
|
37
|
+
fail-fast: false
|
|
38
|
+
matrix:
|
|
39
|
+
ruby-version: ['3.0', '3.1', '3.2', '3.3']
|
|
40
|
+
active-record-version-env:
|
|
41
|
+
- ACTIVE_RECORD_VERSION="~> 6.1.0"
|
|
42
|
+
- ACTIVE_RECORD_VERSION="~> 7.0.0"
|
|
43
|
+
- ACTIVE_RECORD_VERSION="~> 7.1.0"
|
|
44
|
+
- ACTIVE_RECORD_VERSION="~> 7.2.0"
|
|
45
|
+
allow-failure: [false]
|
|
46
|
+
exclude:
|
|
47
|
+
- ruby-version: '3.0'
|
|
48
|
+
active-record-version-env: ACTIVE_RECORD_VERSION="~> 7.2.0"
|
|
49
|
+
include:
|
|
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'
|
|
60
|
+
active-record-version-env: ACTIVE_RECORD_BRANCH="7-0-stable"
|
|
61
|
+
allow-failure: true
|
|
62
|
+
- ruby-version: '3.3'
|
|
63
|
+
active-record-version-env: ACTIVE_RECORD_BRANCH="6-1-stable"
|
|
64
|
+
allow-failure: true
|
|
65
|
+
continue-on-error: ${{ matrix.allow-failure }}
|
|
66
|
+
steps:
|
|
67
|
+
- uses: actions/checkout@v4
|
|
68
|
+
- name: Set up Ruby
|
|
69
|
+
uses: ruby/setup-ruby@v1
|
|
70
|
+
with:
|
|
71
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
72
|
+
bundler-cache: true
|
|
73
|
+
- name: Set up test database
|
|
74
|
+
env:
|
|
75
|
+
PGPASSWORD: postgres
|
|
76
|
+
run: createdb pg_search_test
|
|
77
|
+
- name: Update bundle
|
|
78
|
+
run: ${{ matrix.active-record-version-env }} bundle update
|
|
79
|
+
- name: Run tests
|
|
80
|
+
run: ${{ matrix.active-record-version-env }} bundle exec rake
|
data/.standard.yml
ADDED
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
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
|
+
|
|
14
|
+
## 2.3.6
|
|
15
|
+
|
|
16
|
+
* Drop support for Ruby 2.5
|
|
17
|
+
* Support Ruby 3.1
|
|
18
|
+
* Support Active Record 7.0
|
|
19
|
+
* Don't require `:against` if `:tsvector_column` is specified (Travis Hunter)
|
|
20
|
+
* Optionally disable transaction when rebuilding documents (Travis Hunter)
|
|
21
|
+
* Preserve columns when chaining ::with_pg_search_highlight (jcsanti)
|
|
22
|
+
|
|
3
23
|
## 2.3.5
|
|
4
24
|
|
|
5
25
|
* Add table of contents to README (Barry Woolgar)
|
data/Gemfile
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
source
|
|
3
|
+
source "https://rubygems.org"
|
|
4
4
|
|
|
5
5
|
gemspec
|
|
6
6
|
|
|
7
|
-
gem
|
|
7
|
+
gem "pg", ">= 0.21.0", platform: :ruby
|
|
8
8
|
gem "activerecord-jdbcpostgresql-adapter", ">= 1.3.1", platform: :jruby
|
|
9
9
|
|
|
10
|
-
if ENV[
|
|
11
|
-
gem
|
|
12
|
-
gem
|
|
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
|
|
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
|
|
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
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
# [pg_search](http://github.com/Casecommons/pg_search/)
|
|
2
2
|
|
|
3
3
|
[](https://rubygems.org/gems/pg_search)
|
|
4
|
-
[](https://codeclimate.com/github/Casecommons/pg_search/maintainability)
|
|
6
|
-
[](https://codeclimate.com/github/Casecommons/pg_search/coverage)
|
|
7
|
-
[](http://inch-ci.org/github/Casecommons/pg_search)
|
|
4
|
+
[](https://github.com/Casecommons/pg_search/actions/workflows/ci.yml)
|
|
8
5
|
[](https://gitter.im/Casecommons/pg_search?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
9
6
|
|
|
10
7
|
## DESCRIPTION
|
|
@@ -12,12 +9,12 @@
|
|
|
12
9
|
PgSearch builds named scopes that take advantage of PostgreSQL's full text
|
|
13
10
|
search.
|
|
14
11
|
|
|
15
|
-
Read the blog post introducing PgSearch at https://
|
|
12
|
+
Read the blog post introducing PgSearch at https://tanzu.vmware.com/content/blog/pg-search-how-i-learned-to-stop-worrying-and-love-postgresql-full-text-search
|
|
16
13
|
|
|
17
14
|
## REQUIREMENTS
|
|
18
15
|
|
|
19
|
-
* Ruby
|
|
20
|
-
*
|
|
16
|
+
* Ruby 3.0+
|
|
17
|
+
* Active Record 6.1+
|
|
21
18
|
* PostgreSQL 9.2+
|
|
22
19
|
* [PostgreSQL extensions](https://github.com/Casecommons/pg_search/wiki/Installing-PostgreSQL-Extensions) for certain features
|
|
23
20
|
|
|
@@ -51,7 +48,7 @@ To add PgSearch to an Active Record model, simply include the PgSearch module.
|
|
|
51
48
|
class Shape < ActiveRecord::Base
|
|
52
49
|
include PgSearch::Model
|
|
53
50
|
end
|
|
54
|
-
```
|
|
51
|
+
```
|
|
55
52
|
|
|
56
53
|
### Contents
|
|
57
54
|
* [Multi-search vs. search scopes](#multi-search-vs-search-scopes)
|
|
@@ -201,17 +198,22 @@ problematic_record.published? # => true
|
|
|
201
198
|
PgSearch.multisearch("timestamp") # => Includes problematic_record
|
|
202
199
|
```
|
|
203
200
|
|
|
204
|
-
#### More Options
|
|
201
|
+
#### More Options
|
|
205
202
|
|
|
206
203
|
**Conditionally update pg_search_documents**
|
|
207
204
|
|
|
208
|
-
You can
|
|
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?`.
|
|
209
210
|
|
|
210
211
|
```ruby
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
212
|
+
class Message < ActiveRecord::Base
|
|
213
|
+
include PgSearch::Model
|
|
214
|
+
multisearchable against: [:body],
|
|
215
|
+
update_if: :body_previously_changed?
|
|
216
|
+
end
|
|
215
217
|
```
|
|
216
218
|
|
|
217
219
|
**Specify additional attributes to be saved on the pg_search_documents table**
|
|
@@ -244,7 +246,8 @@ This allows much faster searches without joins later on by doing something like:
|
|
|
244
246
|
PgSearch.multisearch(params['search']).where(author_id: 2)
|
|
245
247
|
```
|
|
246
248
|
|
|
247
|
-
*NOTE: You must currently manually call `record.update_pg_search_document` for
|
|
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*
|
|
248
251
|
|
|
249
252
|
#### Multi-search associations
|
|
250
253
|
|
|
@@ -319,7 +322,7 @@ To remove all of the documents for a given class, you can simply delete all of
|
|
|
319
322
|
the PgSearch::Document records.
|
|
320
323
|
|
|
321
324
|
```ruby
|
|
322
|
-
PgSearch::Document.
|
|
325
|
+
PgSearch::Document.delete_by(searchable_type: "Animal")
|
|
323
326
|
```
|
|
324
327
|
|
|
325
328
|
To regenerate the documents for a given class, run:
|
|
@@ -338,6 +341,13 @@ like so:
|
|
|
338
341
|
PgSearch::Multisearch.rebuild(Product, clean_up: false)
|
|
339
342
|
```
|
|
340
343
|
|
|
344
|
+
```rebuild``` runs inside a single transaction. To run outside of a transaction,
|
|
345
|
+
you can pass ```transactional: false``` like so:
|
|
346
|
+
|
|
347
|
+
```ruby
|
|
348
|
+
PgSearch::Multisearch.rebuild(Product, transactional: false)
|
|
349
|
+
```
|
|
350
|
+
|
|
341
351
|
Rebuild is also available as a Rake task, for convenience.
|
|
342
352
|
|
|
343
353
|
$ rake pg_search:multisearch:rebuild[BlogPost]
|
|
@@ -349,15 +359,11 @@ pg_search_documents tables. The following will set the schema search path to
|
|
|
349
359
|
|
|
350
360
|
$ rake pg_search:multisearch:rebuild[BlogPost,my_schema]
|
|
351
361
|
|
|
352
|
-
For models that are multisearchable
|
|
362
|
+
For models that are multisearchable `:against` methods that directly map to
|
|
353
363
|
Active Record attributes, an efficient single SQL statement is run to update
|
|
354
|
-
the pg_search_documents table all at once. However, if you call any dynamic
|
|
355
|
-
methods in
|
|
356
|
-
|
|
357
|
-
```ruby
|
|
358
|
-
PgSearch::Document.delete_all(searchable_type: "Ingredient")
|
|
359
|
-
Ingredient.find_each { |record| record.update_pg_search_document }
|
|
360
|
-
```
|
|
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.
|
|
361
367
|
|
|
362
368
|
You can also provide a custom implementation for rebuilding the documents by
|
|
363
369
|
adding a class method called `rebuild_pg_search_documents` to your model.
|
|
@@ -383,7 +389,7 @@ class Movie < ActiveRecord::Base
|
|
|
383
389
|
INSERT INTO pg_search_documents (searchable_type, searchable_id, content, created_at, updated_at)
|
|
384
390
|
SELECT 'Movie' AS searchable_type,
|
|
385
391
|
movies.id AS searchable_id,
|
|
386
|
-
(
|
|
392
|
+
CONCAT_WS(' ', movies.name, directors.name) AS content,
|
|
387
393
|
now() AS created_at,
|
|
388
394
|
now() AS updated_at
|
|
389
395
|
FROM movies
|
|
@@ -393,6 +399,7 @@ class Movie < ActiveRecord::Base
|
|
|
393
399
|
end
|
|
394
400
|
end
|
|
395
401
|
```
|
|
402
|
+
**Note:** If using PostgreSQL before 9.1, replace the `CONCAT_WS()` function call with double-pipe concatenation, eg. `(movies.name || ' ' || directors.name)`. However, now be aware that if *any* of the joined values is NULL then the final `content` value will also be NULL, whereas `CONCAT_WS()` will selectively ignore NULL values.
|
|
396
403
|
|
|
397
404
|
#### Disabling multi-search indexing temporarily
|
|
398
405
|
|
|
@@ -545,6 +552,21 @@ class Beer < ActiveRecord::Base
|
|
|
545
552
|
end
|
|
546
553
|
```
|
|
547
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
|
+
|
|
548
570
|
The currently implemented features are
|
|
549
571
|
|
|
550
572
|
* :tsearch - [Full text search](http://www.postgresql.org/docs/current/static/textsearch-intro.html), which is built-in to PostgreSQL
|
|
@@ -657,7 +679,7 @@ Animal.with_name_matching("fish !red !blue") # => [one_fish, two_fish]
|
|
|
657
679
|
|
|
658
680
|
PostgreSQL full text search also support multiple dictionaries for stemming.
|
|
659
681
|
You can learn more about how dictionaries work by reading the [PostgreSQL
|
|
660
|
-
documention](http://www.postgresql.org/docs/current/static/textsearch-dictionaries.html).
|
|
682
|
+
documention](http://www.postgresql.org/docs/current/static/textsearch-dictionaries.html).
|
|
661
683
|
If you use one of the language dictionaries, such as "english",
|
|
662
684
|
then variants of words (e.g. "jumping" and "jumped") will match each other. If
|
|
663
685
|
you don't want stemming, you should pick the "simple" dictionary which does
|
|
@@ -679,12 +701,12 @@ class BoringTweet < ActiveRecord::Base
|
|
|
679
701
|
}
|
|
680
702
|
end
|
|
681
703
|
|
|
682
|
-
|
|
704
|
+
sleep = BoringTweet.create! text: "I snoozed my alarm for fourteen hours today. I bet I can beat that tomorrow! #sleep"
|
|
683
705
|
sleeping = BoringTweet.create! text: "You know what I like? Sleeping. That's what. #enjoyment"
|
|
684
|
-
|
|
706
|
+
sleeps = BoringTweet.create! text: "In the jungle, the mighty jungle, the lion sleeps #tonight"
|
|
685
707
|
|
|
686
|
-
BoringTweet.kinda_matching("sleeping") # => [
|
|
687
|
-
BoringTweet.literally_matching("
|
|
708
|
+
BoringTweet.kinda_matching("sleeping") # => [sleep, sleeping, sleeps]
|
|
709
|
+
BoringTweet.literally_matching("sleeps") # => [sleeps]
|
|
688
710
|
```
|
|
689
711
|
|
|
690
712
|
##### :normalization
|
|
@@ -829,7 +851,7 @@ used for searching.
|
|
|
829
851
|
Double Metaphone support is currently available as part of the [fuzzystrmatch
|
|
830
852
|
extension](http://www.postgresql.org/docs/current/static/fuzzystrmatch.html)
|
|
831
853
|
that must be installed before this feature can be used. In addition to the
|
|
832
|
-
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
|
|
833
855
|
and run a migration for this, run:
|
|
834
856
|
|
|
835
857
|
$ rails g pg_search:migration:dmetaphone
|
|
@@ -864,7 +886,7 @@ Trigram search works by counting how many three-letter substrings (or
|
|
|
864
886
|
Trigram search has some ability to work even with typos and misspellings in
|
|
865
887
|
the query or text.
|
|
866
888
|
|
|
867
|
-
Trigram support is currently available as part of the
|
|
889
|
+
Trigram support is currently available as part of the
|
|
868
890
|
[pg_trgm extension](http://www.postgresql.org/docs/current/static/pgtrgm.html) that must be installed before this
|
|
869
891
|
feature can be used.
|
|
870
892
|
|
|
@@ -928,7 +950,7 @@ Vegetable.strictly_spelled_like("collyflower") # => []
|
|
|
928
950
|
Allows you to match words in longer strings.
|
|
929
951
|
By default, trigram searches use `%` or `similarity()` as a similarity value.
|
|
930
952
|
Set `word_similarity` to `true` to opt for `<%` and `word_similarity` instead.
|
|
931
|
-
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
|
|
932
954
|
and the word with greatest similarity.
|
|
933
955
|
|
|
934
956
|
```ruby
|
|
@@ -954,12 +976,12 @@ Sentence.similarity_like("word") # => []
|
|
|
954
976
|
Sentence.word_similarity_like("word") # => [sentence]
|
|
955
977
|
```
|
|
956
978
|
|
|
957
|
-
### Limiting Fields When Combining Features
|
|
979
|
+
### Limiting Fields When Combining Features
|
|
958
980
|
|
|
959
|
-
Sometimes when doing queries combining different features you
|
|
960
|
-
might want to
|
|
981
|
+
Sometimes when doing queries combining different features you
|
|
982
|
+
might want to search against only some of the fields with certain features.
|
|
961
983
|
For example perhaps you want to only do a trigram search against the shorter fields
|
|
962
|
-
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
|
|
963
985
|
which fields using the 'only' option:
|
|
964
986
|
|
|
965
987
|
```ruby
|
|
@@ -978,7 +1000,7 @@ class Image < ActiveRecord::Base
|
|
|
978
1000
|
end
|
|
979
1001
|
```
|
|
980
1002
|
|
|
981
|
-
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'
|
|
982
1004
|
and long_description: 'This description is so long that it would make a trigram search
|
|
983
1005
|
fail any reasonable threshold limit' with:
|
|
984
1006
|
|
|
@@ -1196,5 +1218,5 @@ for discussing pg_search and other Casebook PBC open source projects.
|
|
|
1196
1218
|
|
|
1197
1219
|
## LICENSE
|
|
1198
1220
|
|
|
1199
|
-
Copyright © 2010–
|
|
1221
|
+
Copyright © 2010–2022 [Casebook PBC](http://www.casebook.net).
|
|
1200
1222
|
Licensed under the MIT license, see [LICENSE](/LICENSE) file.
|
data/Rakefile
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "bundler"
|
|
4
4
|
Bundler::GemHelper.install_tasks
|
|
5
5
|
|
|
6
|
-
require
|
|
6
|
+
require "rspec/core/rake_task"
|
|
7
7
|
RSpec::Core::RakeTask.new(:spec)
|
|
8
8
|
|
|
9
|
-
require "
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
require "standard/rake"
|
|
10
|
+
|
|
11
|
+
desc "Check test coverage"
|
|
12
|
+
task :undercover do
|
|
13
|
+
system("git fetch --unshallow") if ENV["CI"]
|
|
14
|
+
exit(1) unless system("bin/undercover --compare origin/master")
|
|
12
15
|
end
|
|
13
16
|
|
|
14
|
-
task default: %w[spec
|
|
17
|
+
task default: %w[spec standard undercover]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
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
|
|
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(@
|
|
35
|
+
@connection.quote_column_name(@name)
|
|
34
36
|
end
|
|
35
37
|
|
|
36
38
|
def expression
|
|
@@ -80,7 +80,7 @@ module PgSearch
|
|
|
80
80
|
attr_reader :options
|
|
81
81
|
|
|
82
82
|
def default_options
|
|
83
|
-
{
|
|
83
|
+
{using: :tsearch}
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
VALID_KEYS = %w[
|
|
@@ -92,8 +92,11 @@ module PgSearch
|
|
|
92
92
|
}.freeze
|
|
93
93
|
|
|
94
94
|
def assert_valid_options(options)
|
|
95
|
-
unless options[:against] || options[:associated_against]
|
|
96
|
-
raise
|
|
95
|
+
unless options[:against] || options[:associated_against] || using_tsvector_column?(options[:using])
|
|
96
|
+
raise(
|
|
97
|
+
ArgumentError,
|
|
98
|
+
"the search scope #{@name} must have :against, :associated_against, or :tsvector_column in its options"
|
|
99
|
+
)
|
|
97
100
|
end
|
|
98
101
|
|
|
99
102
|
options.assert_valid_keys(VALID_KEYS)
|
|
@@ -104,5 +107,12 @@ module PgSearch
|
|
|
104
107
|
end
|
|
105
108
|
end
|
|
106
109
|
end
|
|
110
|
+
|
|
111
|
+
def using_tsvector_column?(options)
|
|
112
|
+
return unless options.is_a?(Hash)
|
|
113
|
+
|
|
114
|
+
options.dig(:dmetaphone, :tsvector_column).present? ||
|
|
115
|
+
options.dig(:tsearch, :tsvector_column).present?
|
|
116
|
+
end
|
|
107
117
|
end
|
|
108
118
|
end
|
data/lib/pg_search/document.rb
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
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 =
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
PgSearch.multisearch_options.call(*args)
|
|
21
|
+
else
|
|
22
|
+
{query: args.first}.merge(PgSearch.multisearch_options)
|
|
23
|
+
end
|
|
24
24
|
|
|
25
|
-
{
|
|
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:
|
|
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
|
-
|
|
38
|
+
"word_similarity"
|
|
39
39
|
else
|
|
40
|
-
|
|
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
|
|