pg_search 2.1.2 → 2.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +0 -10
- data/.travis.yml +14 -34
- data/CHANGELOG.md +7 -0
- data/CONTRIBUTING.md +5 -3
- data/Gemfile +1 -1
- data/README.md +4 -5
- data/lib/pg_search.rb +6 -3
- data/lib/pg_search/configuration.rb +2 -0
- data/lib/pg_search/features/tsearch.rb +2 -1
- data/lib/pg_search/migration/generator.rb +2 -2
- data/lib/pg_search/multisearch/rebuilder.rb +3 -1
- data/lib/pg_search/multisearchable.rb +4 -0
- data/lib/pg_search/scope_options.rb +1 -0
- data/lib/pg_search/tasks.rb +1 -0
- data/lib/pg_search/version.rb +1 -1
- data/pg_search.gemspec +3 -3
- data/spec/integration/pg_search_spec.rb +10 -1
- data/spec/lib/pg_search/features/dmetaphone_spec.rb +2 -2
- data/spec/lib/pg_search/features/tsearch_spec.rb +7 -7
- data/spec/lib/pg_search/multisearch/rebuilder_spec.rb +21 -2
- data/spec/lib/pg_search/multisearch_spec.rb +2 -2
- data/spec/lib/pg_search/multisearchable_spec.rb +39 -0
- data/spec/support/database.rb +1 -0
- metadata +7 -7
- data/Guardfile +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 490019a491cda1e15a0ab4fd68f89a1cc7c6d7371ff098a452a84c4c83314f7d
|
4
|
+
data.tar.gz: 5dc3c3bc842f669630cbf283af324ae9972cae624e3b15fe2d83ca354211ef8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c1f7f8f87d7d23b39b405a8c196016bba6f3c9c873931263072f6c0b4e5faae3d548fd69278daaa138d13ddbc741c83a2d04eb57e218c2f8e87539833c5a747
|
7
|
+
data.tar.gz: c8d5728f08af5f146b63b9999e782c46294aa078d853481702758a5f528a31f295b7f9822ed0a53abfc76b11b898229b503685eff4fd86c3595a4f1c4dc62d4c
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -138,16 +138,6 @@ Style/SymbolProc:
|
|
138
138
|
- 'lib/pg_search/features/feature.rb'
|
139
139
|
- 'lib/pg_search/multisearch/rebuilder.rb'
|
140
140
|
|
141
|
-
# Offense count: 10
|
142
|
-
# Cop supports --auto-correct.
|
143
|
-
# Configuration parameters: EnforcedStyleForMultiline, SupportedStylesForMultiline.
|
144
|
-
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
|
145
|
-
Style/TrailingCommaInLiteral:
|
146
|
-
Exclude:
|
147
|
-
- 'spec/integration/pg_search_spec.rb'
|
148
|
-
- 'spec/lib/pg_search/features/dmetaphone_spec.rb'
|
149
|
-
- 'spec/lib/pg_search/features/tsearch_spec.rb'
|
150
|
-
|
151
141
|
# Offense count: 2
|
152
142
|
# Cop supports --auto-correct.
|
153
143
|
Style/UnneededPercentQ:
|
data/.travis.yml
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
language: ruby
|
2
2
|
sudo: false
|
3
|
+
bundler_args: --binstubs
|
4
|
+
before_install: gem install bundler
|
3
5
|
|
4
6
|
rvm:
|
5
|
-
- "2.
|
6
|
-
- "2.
|
7
|
-
- "2.
|
8
|
-
- "2.
|
9
|
-
- jruby-9.1.14.0
|
7
|
+
- "2.5.3"
|
8
|
+
- "2.4.5"
|
9
|
+
- "2.3.8"
|
10
|
+
- "jruby-9.2.0.0"
|
10
11
|
|
11
12
|
env:
|
12
13
|
- ACTIVE_RECORD_BRANCH="master"
|
13
|
-
- ACTIVE_RECORD_BRANCH="5-
|
14
|
-
-
|
15
|
-
- ACTIVE_RECORD_BRANCH="4-2-stable"
|
16
|
-
- ACTIVE_RECORD_VERSION="~> 5.2.0.beta2"
|
14
|
+
- ACTIVE_RECORD_BRANCH="5-2-stable"
|
15
|
+
- ACTIVE_RECORD_VERSION="~> 5.2.0"
|
17
16
|
- ACTIVE_RECORD_VERSION="~> 5.1.0"
|
18
17
|
- ACTIVE_RECORD_VERSION="~> 5.0.0"
|
19
18
|
- ACTIVE_RECORD_VERSION="~> 4.2.9"
|
@@ -21,39 +20,20 @@ env:
|
|
21
20
|
matrix:
|
22
21
|
allow_failures:
|
23
22
|
- env: ACTIVE_RECORD_BRANCH="master"
|
24
|
-
- env: ACTIVE_RECORD_BRANCH="5-
|
25
|
-
- env: ACTIVE_RECORD_BRANCH="5-0-stable"
|
26
|
-
- env: ACTIVE_RECORD_BRANCH="4-2-stable"
|
27
|
-
- rvm: jruby-9.1.14.0
|
23
|
+
- env: ACTIVE_RECORD_BRANCH="5-2-stable"
|
28
24
|
exclude:
|
29
|
-
- rvm:
|
25
|
+
- rvm: 2.3.8
|
30
26
|
env: ACTIVE_RECORD_BRANCH="master"
|
31
|
-
- rvm:
|
32
|
-
env:
|
33
|
-
- rvm: "2.1.10"
|
34
|
-
env: ACTIVE_RECORD_BRANCH="5-0-stable"
|
35
|
-
- rvm: "2.1.10"
|
36
|
-
env: ACTIVE_RECORD_VERSION="~> 5.1.0"
|
37
|
-
- rvm: "2.1.10"
|
38
|
-
env: ACTIVE_RECORD_VERSION="~> 5.0.0"
|
39
|
-
- rvm: jruby-9.1.14.0
|
40
|
-
env: ACTIVE_RECORD_BRANCH="master"
|
41
|
-
- rvm: jruby-9.1.14.0
|
42
|
-
env: ACTIVE_RECORD_BRANCH="5-1-stable"
|
43
|
-
- rvm: jruby-9.1.14.0
|
44
|
-
env: ACTIVE_RECORD_BRANCH="5-0-stable"
|
45
|
-
- rvm: jruby-9.1.14.0
|
46
|
-
env: ACTIVE_RECORD_VERSION="~> 5.2.0.beta2"
|
47
|
-
- rvm: jruby-9.1.14.0
|
48
|
-
env: ACTIVE_RECORD_VERSION="~> 5.1.0"
|
49
|
-
- rvm: jruby-9.1.14.0
|
50
|
-
env: ACTIVE_RECORD_VERSION="~> 5.0.0"
|
27
|
+
- rvm: jruby-9.2.0.0
|
28
|
+
env: ACTIVE_RECORD_VERSION="~> 4.2.9"
|
51
29
|
|
52
30
|
before_script:
|
31
|
+
- "psql --version"
|
53
32
|
- "psql -c 'create database pg_search_test;' -U postgres >/dev/null"
|
54
33
|
|
55
34
|
script: "bin/rake"
|
56
35
|
|
57
36
|
addons:
|
37
|
+
postgresql: "9.6"
|
58
38
|
code_climate:
|
59
39
|
repo_token: 0a0e3e45118bc447e677d52c21d056a5471c4921d54f96ed7b2550d9fc5043ea
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# pg_search changelog
|
2
2
|
|
3
|
+
## 2.1.3
|
4
|
+
|
5
|
+
* Remove support for unsupported Ruby 2.1
|
6
|
+
* Disallow left/right single quotation marks in tsquery (Fabian Schwahn) (#382)
|
7
|
+
* Do not attempt to save an already-destroy PgSearch::Document (Oleg Dashevskii, Vokhmin Aleksei V) (#353)
|
8
|
+
* Quote column name when rebuilding (Jed Levin) (#379)
|
9
|
+
|
3
10
|
## 2.1.2
|
4
11
|
|
5
12
|
* Silence warnings in Rails 5.2.0.beta2 (Kevin Deisz)
|
data/CONTRIBUTING.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
First off, if you experience a bug, we welcome you to report it. Please provide a minimal test case showing the code that you ran, its output, and what you expected the output to be instead. If you are able to fix the bug and make a pull request, we are much more likely to get it resolved quickly, but don't feel bad to just report an issue if you don't know how to fix it.
|
4
4
|
|
5
|
-
|
5
|
+
View the [README](./README.md) to see which versions of Ruby, Active Record, and PostgreSQL are supported by pg_search. It can be hard to test against all of the various versions, but please do your best to avoid coding practices that only work in newer versions.
|
6
6
|
|
7
7
|
If you have a substantial feature to add, you might want to discuss it first on the [mailing list](https://groups.google.com/forum/#!forum/casecommons-dev). We might have thought hard about it already, and can sometimes help with tips and tricks.
|
8
8
|
|
@@ -10,8 +10,10 @@ When in doubt, go ahead and make a pull request. If something needs tweaking or
|
|
10
10
|
|
11
11
|
Don't be discouraged if the maintainers ask you to change your code. We are always appreciative when people work hard to modify our code, but we also have a lot of opinions about coding style and object design.
|
12
12
|
|
13
|
-
|
13
|
+
Our automated tests start by updating all gems to their latest version. This is by design, because we want to be proactive about compatibility with other libraries. You can do the same by running `bundle update` at any time. To test against a specific version of Active Record, you can set the `ACTIVE_RECORD_VERSION` environment variable.
|
14
14
|
|
15
|
-
$ ACTIVE_RECORD_VERSION=
|
15
|
+
$ ACTIVE_RECORD_VERSION=5.0 bundle update
|
16
|
+
|
17
|
+
Run the tests by running `bundle exec rake`, or `bin/rake` if you use Bundler binstubs.
|
16
18
|
|
17
19
|
Last, but not least, have fun! pg_search is a labor of love.
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,9 +2,8 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://img.shields.io/gem/v/pg_search.svg?style=flat)](https://rubygems.org/gems/pg_search)
|
4
4
|
[![Build Status](https://secure.travis-ci.org/Casecommons/pg_search.svg?branch=master)](https://travis-ci.org/Casecommons/pg_search)
|
5
|
-
[![
|
5
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/ae1a7c021e473e9b2486/maintainability)](https://codeclimate.com/github/Casecommons/pg_search/maintainability)
|
6
6
|
[![Test Coverage](https://codeclimate.com/github/Casecommons/pg_search/badges/coverage.svg)](https://codeclimate.com/github/Casecommons/pg_search/coverage)
|
7
|
-
[![Dependency Status](https://img.shields.io/gemnasium/Casecommons/pg_search.svg?style=flat)](https://gemnasium.com/Casecommons/pg_search)
|
8
7
|
[![Inline docs](http://inch-ci.org/github/Casecommons/pg_search.svg?branch=master&style=flat)](http://inch-ci.org/github/Casecommons/pg_search)
|
9
8
|
[![Join the chat at https://gitter.im/Casecommons/pg_search](https://img.shields.io/badge/gitter-join%20chat-blue.svg)](https://gitter.im/Casecommons/pg_search?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
10
9
|
[![Stories in Ready](https://img.shields.io/waffle/label/Casecommons/pg_search/in%20progress.svg)](https://waffle.io/Casecommons/pg_search)
|
@@ -18,7 +17,7 @@ Read the blog post introducing PgSearch at https://content.pivotal.io/blog/pg-se
|
|
18
17
|
|
19
18
|
## REQUIREMENTS
|
20
19
|
|
21
|
-
* Ruby 2.
|
20
|
+
* Ruby 2.2+
|
22
21
|
* ActiveRecord 4.2+
|
23
22
|
* PostgreSQL 9.2+
|
24
23
|
* [PostgreSQL extensions](https://github.com/Casecommons/pg_search/wiki/Installing-PostgreSQL-Extensions) for certain features
|
@@ -384,13 +383,13 @@ value if you wanted.
|
|
384
383
|
```ruby
|
385
384
|
class Person < ActiveRecord::Base
|
386
385
|
include PgSearch
|
387
|
-
pg_search_scope :search_by_name, lambda
|
386
|
+
pg_search_scope :search_by_name, lambda { |name_part, query|
|
388
387
|
raise ArgumentError unless [:first, :last].include?(name_part)
|
389
388
|
{
|
390
389
|
:against => name_part,
|
391
390
|
:query => query
|
392
391
|
}
|
393
|
-
|
392
|
+
}
|
394
393
|
end
|
395
394
|
|
396
395
|
person_1 = Person.create!(:first_name => "Grant", :last_name => "Hill")
|
data/lib/pg_search.rb
CHANGED
@@ -24,9 +24,10 @@ module PgSearch
|
|
24
24
|
def pg_search_scope(name, options)
|
25
25
|
options_proc = if options.respond_to?(:call)
|
26
26
|
options
|
27
|
-
|
28
|
-
raise ArgumentError, "pg_search_scope expects a Hash or Proc" unless options.respond_to?(:merge)
|
27
|
+
elsif options.respond_to?(:merge)
|
29
28
|
->(query) { {:query => query}.merge(options) }
|
29
|
+
else
|
30
|
+
raise ArgumentError, 'pg_search_scope expects a Hash or Proc'
|
30
31
|
end
|
31
32
|
|
32
33
|
define_singleton_method(name) do |*args|
|
@@ -37,7 +38,7 @@ module PgSearch
|
|
37
38
|
end
|
38
39
|
|
39
40
|
def multisearchable(options = {})
|
40
|
-
include PgSearch::Multisearchable
|
41
|
+
include PgSearch::Multisearchable
|
41
42
|
class_attribute :pg_search_multisearchable_options
|
42
43
|
self.pg_search_multisearchable_options = options
|
43
44
|
end
|
@@ -68,9 +69,11 @@ module PgSearch
|
|
68
69
|
case symbol
|
69
70
|
when :pg_search_rank
|
70
71
|
raise PgSearchRankNotSelected.new unless respond_to?(:pg_search_rank)
|
72
|
+
|
71
73
|
read_attribute(:pg_search_rank).to_f
|
72
74
|
when :pg_search_highlight
|
73
75
|
raise PgSearchHighlightNotSelected.new unless respond_to?(:pg_search_highlight)
|
76
|
+
|
74
77
|
read_attribute(:pg_search_highlight)
|
75
78
|
else
|
76
79
|
super
|
@@ -27,6 +27,7 @@ module PgSearch
|
|
27
27
|
|
28
28
|
def regular_columns
|
29
29
|
return [] unless options[:against]
|
30
|
+
|
30
31
|
Array(options[:against]).map do |column_name, weight|
|
31
32
|
Column.new(column_name, weight, model)
|
32
33
|
end
|
@@ -34,6 +35,7 @@ module PgSearch
|
|
34
35
|
|
35
36
|
def associations
|
36
37
|
return [] unless options[:associated_against]
|
38
|
+
|
37
39
|
options[:associated_against].map do |association, column_names|
|
38
40
|
Association.new(model, association, column_names)
|
39
41
|
end.flatten
|
@@ -93,7 +93,7 @@ module PgSearch
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
DISALLOWED_TSQUERY_CHARACTERS = /['
|
96
|
+
DISALLOWED_TSQUERY_CHARACTERS = /['?\\:‘’]/.freeze
|
97
97
|
|
98
98
|
def tsquery_for_term(unsanitized_term) # rubocop:disable Metrics/AbcSize
|
99
99
|
if options[:negation] && unsanitized_term.start_with?("!")
|
@@ -128,6 +128,7 @@ module PgSearch
|
|
128
128
|
|
129
129
|
def tsquery
|
130
130
|
return "''" if query.blank?
|
131
|
+
|
131
132
|
query_terms = query.split(" ").compact
|
132
133
|
tsquery_terms = query_terms.map { |term| tsquery_for_term(term) }
|
133
134
|
tsquery_terms.join(options[:any_word] ? ' || ' : ' && ')
|
@@ -8,7 +8,7 @@ module PgSearch
|
|
8
8
|
|
9
9
|
def self.inherited(subclass)
|
10
10
|
super
|
11
|
-
subclass.source_root File.expand_path('
|
11
|
+
subclass.source_root File.expand_path('templates', __dir__)
|
12
12
|
end
|
13
13
|
|
14
14
|
def create_migration
|
@@ -20,7 +20,7 @@ module PgSearch
|
|
20
20
|
private
|
21
21
|
|
22
22
|
def read_sql_file(filename)
|
23
|
-
sql_directory = File.expand_path('
|
23
|
+
sql_directory = File.expand_path('../../../sql', __dir__)
|
24
24
|
source_path = File.join(sql_directory, "#{filename}.sql")
|
25
25
|
File.read(source_path).strip
|
26
26
|
end
|
@@ -74,7 +74,9 @@ module PgSearch
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def content_expressions
|
77
|
-
columns.map
|
77
|
+
columns.map do |column|
|
78
|
+
%{coalesce(:model_table.#{connection.quote_column_name(column)}::text, '')}
|
79
|
+
end.join(" || ' ' || ")
|
78
80
|
end
|
79
81
|
|
80
82
|
def columns
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/core_ext/class/attribute"
|
2
4
|
|
3
5
|
module PgSearch
|
@@ -31,6 +33,8 @@ module PgSearch
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def should_update_pg_search_document?
|
36
|
+
return false if pg_search_document.destroyed?
|
37
|
+
|
34
38
|
conditions = Array(pg_search_multisearchable_options[:update_if])
|
35
39
|
conditions.all? { |condition| condition.to_proc.call(self) }
|
36
40
|
end
|
@@ -171,6 +171,7 @@ module PgSearch
|
|
171
171
|
|
172
172
|
def include_table_aliasing_for_rank(scope)
|
173
173
|
return scope if scope.included_modules.include?(PgSearchRankTableAliasing)
|
174
|
+
|
174
175
|
scope.all.spawn.tap do |new_scope|
|
175
176
|
new_scope.class_eval { include PgSearchRankTableAliasing }
|
176
177
|
end
|
data/lib/pg_search/tasks.rb
CHANGED
@@ -6,6 +6,7 @@ namespace :pg_search do
|
|
6
6
|
desc "Rebuild PgSearch multisearch records for a given model"
|
7
7
|
task :rebuild, %i[model schema] => :environment do |_task, args|
|
8
8
|
raise ArgumentError, <<-MESSAGE.strip_heredoc unless args.model
|
9
|
+
|
9
10
|
You must pass a model as an argument.
|
10
11
|
Example: rake pg_search:multisearch:rebuild[BlogPost]
|
11
12
|
MESSAGE
|
data/lib/pg_search/version.rb
CHANGED
data/pg_search.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
$LOAD_PATH.push File.expand_path('
|
1
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
2
2
|
require 'pg_search/version'
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
@@ -24,9 +24,9 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_development_dependency 'pry'
|
25
25
|
s.add_development_dependency 'rake'
|
26
26
|
s.add_development_dependency 'rspec', '>= 3.3'
|
27
|
-
s.add_development_dependency 'rubocop'
|
27
|
+
s.add_development_dependency 'rubocop', '>= 0.54.0'
|
28
28
|
s.add_development_dependency 'simplecov'
|
29
29
|
s.add_development_dependency 'with_model', '>= 1.2'
|
30
30
|
|
31
|
-
s.required_ruby_version = '>= 2.
|
31
|
+
s.required_ruby_version = '>= 2.2'
|
32
32
|
end
|
@@ -428,7 +428,7 @@ describe "an Active Record model which includes PgSearch" do
|
|
428
428
|
included = [
|
429
429
|
ModelWithPgSearch.create!(:content => 'foo bar'),
|
430
430
|
ModelWithPgSearch.create!(:content => 'bar foo'),
|
431
|
-
ModelWithPgSearch.create!(:content => 'bar foo baz')
|
431
|
+
ModelWithPgSearch.create!(:content => 'bar foo baz')
|
432
432
|
]
|
433
433
|
excluded = [
|
434
434
|
ModelWithPgSearch.create!(:content => 'foo'),
|
@@ -1130,6 +1130,15 @@ describe "an Active Record model which includes PgSearch" do
|
|
1130
1130
|
results = ModelWithPgSearch.search_title_without_accents("abcd\303\251f")
|
1131
1131
|
expect(results).to eq([included])
|
1132
1132
|
end
|
1133
|
+
|
1134
|
+
context "when the query includes accents" do
|
1135
|
+
it "does not create an erroneous tsquery expression" do
|
1136
|
+
included = ModelWithPgSearch.create!(:title => "Weird L‘Content")
|
1137
|
+
|
1138
|
+
results = ModelWithPgSearch.search_title_without_accents("L‘Content")
|
1139
|
+
expect(results).to eq([included])
|
1140
|
+
end
|
1141
|
+
end
|
1133
1142
|
end
|
1134
1143
|
|
1135
1144
|
context "when passed a :ranked_by expression" do
|
@@ -13,7 +13,7 @@ describe PgSearch::Features::DMetaphone do
|
|
13
13
|
query = "query"
|
14
14
|
columns = [
|
15
15
|
PgSearch::Configuration::Column.new(:name, nil, Model),
|
16
|
-
PgSearch::Configuration::Column.new(:content, nil, Model)
|
16
|
+
PgSearch::Configuration::Column.new(:content, nil, Model)
|
17
17
|
]
|
18
18
|
options = {}
|
19
19
|
config = double(:config, :ignore => [])
|
@@ -38,7 +38,7 @@ describe PgSearch::Features::DMetaphone do
|
|
38
38
|
query = "query"
|
39
39
|
columns = [
|
40
40
|
PgSearch::Configuration::Column.new(:name, nil, Model),
|
41
|
-
PgSearch::Configuration::Column.new(:content, nil, Model)
|
41
|
+
PgSearch::Configuration::Column.new(:content, nil, Model)
|
42
42
|
]
|
43
43
|
options = {}
|
44
44
|
config = double(:config, :ignore => [])
|
@@ -14,7 +14,7 @@ describe PgSearch::Features::TSearch do
|
|
14
14
|
query = "query"
|
15
15
|
columns = [
|
16
16
|
PgSearch::Configuration::Column.new(:name, nil, Model),
|
17
|
-
PgSearch::Configuration::Column.new(:content, nil, Model)
|
17
|
+
PgSearch::Configuration::Column.new(:content, nil, Model)
|
18
18
|
]
|
19
19
|
options = {}
|
20
20
|
config = double(:config, :ignore => [])
|
@@ -39,7 +39,7 @@ describe PgSearch::Features::TSearch do
|
|
39
39
|
query = "query"
|
40
40
|
columns = [
|
41
41
|
PgSearch::Configuration::Column.new(:name, nil, Model),
|
42
|
-
PgSearch::Configuration::Column.new(:content, nil, Model)
|
42
|
+
PgSearch::Configuration::Column.new(:content, nil, Model)
|
43
43
|
]
|
44
44
|
options = {}
|
45
45
|
config = double(:config, :ignore => [])
|
@@ -56,7 +56,7 @@ describe PgSearch::Features::TSearch do
|
|
56
56
|
query = "!query"
|
57
57
|
columns = [
|
58
58
|
PgSearch::Configuration::Column.new(:name, nil, Model),
|
59
|
-
PgSearch::Configuration::Column.new(:content, nil, Model)
|
59
|
+
PgSearch::Configuration::Column.new(:content, nil, Model)
|
60
60
|
]
|
61
61
|
options = {:negation => true}
|
62
62
|
config = double(:config, :ignore => [])
|
@@ -74,7 +74,7 @@ describe PgSearch::Features::TSearch do
|
|
74
74
|
query = "!query"
|
75
75
|
columns = [
|
76
76
|
PgSearch::Configuration::Column.new(:name, nil, Model),
|
77
|
-
PgSearch::Configuration::Column.new(:content, nil, Model)
|
77
|
+
PgSearch::Configuration::Column.new(:content, nil, Model)
|
78
78
|
]
|
79
79
|
options = {:negation => false}
|
80
80
|
config = double(:config, :ignore => [])
|
@@ -92,7 +92,7 @@ describe PgSearch::Features::TSearch do
|
|
92
92
|
query = "query"
|
93
93
|
columns = [
|
94
94
|
PgSearch::Configuration::Column.new(:name, nil, Model),
|
95
|
-
PgSearch::Configuration::Column.new(:content, nil, Model)
|
95
|
+
PgSearch::Configuration::Column.new(:content, nil, Model)
|
96
96
|
]
|
97
97
|
options = {tsvector_column: "my_tsvector"}
|
98
98
|
config = double(:config, :ignore => [])
|
@@ -110,7 +110,7 @@ describe PgSearch::Features::TSearch do
|
|
110
110
|
query = "query"
|
111
111
|
columns = [
|
112
112
|
PgSearch::Configuration::Column.new(:name, nil, Model),
|
113
|
-
PgSearch::Configuration::Column.new(:content, nil, Model)
|
113
|
+
PgSearch::Configuration::Column.new(:content, nil, Model)
|
114
114
|
]
|
115
115
|
options = {tsvector_column: ["tsvector1", "tsvector2"]}
|
116
116
|
config = double(:config, :ignore => [])
|
@@ -153,7 +153,7 @@ describe PgSearch::Features::TSearch do
|
|
153
153
|
query = "query"
|
154
154
|
columns = [
|
155
155
|
PgSearch::Configuration::Column.new(:name, nil, Model),
|
156
|
-
PgSearch::Configuration::Column.new(:content, nil, Model)
|
156
|
+
PgSearch::Configuration::Column.new(:content, nil, Model)
|
157
157
|
]
|
158
158
|
options = {
|
159
159
|
dictionary: "spanish",
|
@@ -112,7 +112,7 @@ describe PgSearch::Multisearch::Rebuilder do
|
|
112
112
|
SELECT 'Model' AS searchable_type,
|
113
113
|
#{Model.quoted_table_name}.#{Model.primary_key} AS searchable_id,
|
114
114
|
(
|
115
|
-
coalesce(#{Model.quoted_table_name}.name::text, '')
|
115
|
+
coalesce(#{Model.quoted_table_name}."name"::text, '')
|
116
116
|
) AS content,
|
117
117
|
'#{expected_timestamp}' AS created_at,
|
118
118
|
'#{expected_timestamp}' AS updated_at
|
@@ -132,6 +132,25 @@ describe PgSearch::Multisearch::Rebuilder do
|
|
132
132
|
expect(executed_sql.first.strip).to eq(expected_sql.strip)
|
133
133
|
end
|
134
134
|
|
135
|
+
context "for a model with a camel case column" do
|
136
|
+
with_model :ModelWithCamelCaseColumn do
|
137
|
+
table do |t|
|
138
|
+
t.string :camelName
|
139
|
+
end
|
140
|
+
|
141
|
+
model do
|
142
|
+
include PgSearch
|
143
|
+
multisearchable :against => :name
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
it "creates search document without PG error" do
|
148
|
+
time = Time.utc(2001, 1, 1, 0, 0, 0)
|
149
|
+
rebuilder = PgSearch::Multisearch::Rebuilder.new(Model, -> { time })
|
150
|
+
rebuilder.rebuild
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
135
154
|
context "for a model with a non-standard primary key" do
|
136
155
|
with_model :ModelWithNonStandardPrimaryKey do
|
137
156
|
table primary_key: :non_standard_primary_key do |t|
|
@@ -157,7 +176,7 @@ describe PgSearch::Multisearch::Rebuilder do
|
|
157
176
|
SELECT 'ModelWithNonStandardPrimaryKey' AS searchable_type,
|
158
177
|
#{ModelWithNonStandardPrimaryKey.quoted_table_name}.non_standard_primary_key AS searchable_id,
|
159
178
|
(
|
160
|
-
coalesce(#{ModelWithNonStandardPrimaryKey.quoted_table_name}.name::text, '')
|
179
|
+
coalesce(#{ModelWithNonStandardPrimaryKey.quoted_table_name}."name"::text, '')
|
161
180
|
) AS content,
|
162
181
|
'#{expected_timestamp}' AS created_at,
|
163
182
|
'#{expected_timestamp}' AS updated_at
|
@@ -121,7 +121,7 @@ describe PgSearch::Multisearch do
|
|
121
121
|
SELECT #{connection.quote(model.name)} AS searchable_type,
|
122
122
|
#{model.quoted_table_name}.id AS searchable_id,
|
123
123
|
(
|
124
|
-
coalesce(#{model.quoted_table_name}.title::text, '')
|
124
|
+
coalesce(#{model.quoted_table_name}."title"::text, '')
|
125
125
|
) AS content,
|
126
126
|
#{connection.quote(connection.quoted_date(now))} AS created_at,
|
127
127
|
#{connection.quote(connection.quoted_date(now))} AS updated_at
|
@@ -148,7 +148,7 @@ describe PgSearch::Multisearch do
|
|
148
148
|
SELECT #{connection.quote(model.name)} AS searchable_type,
|
149
149
|
#{model.quoted_table_name}.id AS searchable_id,
|
150
150
|
(
|
151
|
-
coalesce(#{model.quoted_table_name}.title::text, '') || ' ' || coalesce(#{model.quoted_table_name}.content::text, '')
|
151
|
+
coalesce(#{model.quoted_table_name}."title"::text, '') || ' ' || coalesce(#{model.quoted_table_name}."content"::text, '')
|
152
152
|
) AS content,
|
153
153
|
#{connection.quote(connection.quoted_date(now))} AS created_at,
|
154
154
|
#{connection.quote(connection.quoted_date(now))} AS updated_at
|
@@ -11,6 +11,33 @@ describe PgSearch::Multisearchable do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
with_model :MultisearchableParent do
|
15
|
+
table do |t|
|
16
|
+
t.string :secret
|
17
|
+
end
|
18
|
+
|
19
|
+
model do
|
20
|
+
include PgSearch
|
21
|
+
multisearchable
|
22
|
+
|
23
|
+
has_many :multisearchable_children, :dependent => :destroy
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
with_model :MultisearchableChild do
|
28
|
+
table do |t|
|
29
|
+
t.belongs_to :multisearchable_parent, index: false
|
30
|
+
end
|
31
|
+
|
32
|
+
model do
|
33
|
+
belongs_to :multisearchable_parent
|
34
|
+
|
35
|
+
after_destroy do
|
36
|
+
multisearchable_parent.update_attribute(:secret, rand(1000).to_s)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
14
41
|
describe "callbacks" do
|
15
42
|
describe "after_create" do
|
16
43
|
let(:record) { ModelThatIsMultisearchable.new }
|
@@ -92,6 +119,18 @@ describe PgSearch::Multisearchable do
|
|
92
119
|
expect { record.destroy }.to change(PgSearch::Document, :count).by(-1)
|
93
120
|
expect { PgSearch::Document.find(document.id) }.to raise_error(ActiveRecord::RecordNotFound)
|
94
121
|
end
|
122
|
+
|
123
|
+
it "should remove its document in case of complex associations" do
|
124
|
+
parent = MultisearchableParent.create!
|
125
|
+
|
126
|
+
MultisearchableChild.create!(multisearchable_parent: parent)
|
127
|
+
MultisearchableChild.create!(multisearchable_parent: parent)
|
128
|
+
|
129
|
+
document = parent.pg_search_document
|
130
|
+
|
131
|
+
expect { parent.destroy }.to change(PgSearch::Document, :count).by(-1)
|
132
|
+
expect { PgSearch::Document.find(document.id) }.to raise_error(ActiveRecord::RecordNotFound)
|
133
|
+
end
|
95
134
|
end
|
96
135
|
end
|
97
136
|
|
data/spec/support/database.rb
CHANGED
@@ -41,6 +41,7 @@ def install_extension(name)
|
|
41
41
|
connection = ActiveRecord::Base.connection
|
42
42
|
extension = connection.execute "SELECT * FROM pg_catalog.pg_extension WHERE extname = '#{name}';"
|
43
43
|
return unless extension.none?
|
44
|
+
|
44
45
|
connection.execute "CREATE EXTENSION #{name};"
|
45
46
|
rescue StandardError => exception
|
46
47
|
at_exit do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grant Hutchins
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2018-12-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -115,14 +115,14 @@ dependencies:
|
|
115
115
|
requirements:
|
116
116
|
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version:
|
118
|
+
version: 0.54.0
|
119
119
|
type: :development
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
123
|
- - ">="
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
125
|
+
version: 0.54.0
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
127
|
name: simplecov
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -171,10 +171,10 @@ files:
|
|
171
171
|
- CHANGELOG.md
|
172
172
|
- CONTRIBUTING.md
|
173
173
|
- Gemfile
|
174
|
-
- Guardfile
|
175
174
|
- LICENSE
|
176
175
|
- README.md
|
177
176
|
- Rakefile
|
177
|
+
- bin/rake
|
178
178
|
- lib/pg_search.rb
|
179
179
|
- lib/pg_search/configuration.rb
|
180
180
|
- lib/pg_search/configuration/association.rb
|
@@ -233,7 +233,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
233
233
|
requirements:
|
234
234
|
- - ">="
|
235
235
|
- !ruby/object:Gem::Version
|
236
|
-
version: '2.
|
236
|
+
version: '2.2'
|
237
237
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
238
238
|
requirements:
|
239
239
|
- - ">="
|
@@ -241,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
241
241
|
version: '0'
|
242
242
|
requirements: []
|
243
243
|
rubyforge_project:
|
244
|
-
rubygems_version: 2.6
|
244
|
+
rubygems_version: 2.7.6
|
245
245
|
signing_key:
|
246
246
|
specification_version: 4
|
247
247
|
summary: PgSearch builds Active Record named scopes that take advantage of PostgreSQL's
|