pg_search 2.1.4 → 2.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -4
- data/.travis.yml +27 -25
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -4
- data/README.md +184 -151
- data/Rakefile +1 -5
- data/lib/pg_search.rb +1 -1
- data/lib/pg_search/configuration.rb +2 -2
- data/lib/pg_search/document.rb +3 -3
- data/lib/pg_search/features/dmetaphone.rb +1 -1
- data/lib/pg_search/features/feature.rb +1 -1
- data/lib/pg_search/migration/templates/create_pg_search_documents.rb.erb +1 -1
- data/lib/pg_search/multisearch.rb +1 -1
- data/lib/pg_search/multisearchable.rb +4 -4
- data/lib/pg_search/scope_options.rb +13 -28
- data/lib/pg_search/version.rb +1 -1
- data/pg_search.gemspec +1 -2
- data/spec/integration/associations_spec.rb +100 -100
- data/spec/integration/pagination_spec.rb +7 -7
- data/spec/integration/pg_search_spec.rb +225 -225
- data/spec/integration/single_table_inheritance_spec.rb +14 -14
- data/spec/lib/pg_search/configuration/association_spec.rb +5 -5
- 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 +1 -1
- data/spec/lib/pg_search/features/tsearch_spec.rb +12 -12
- data/spec/lib/pg_search/multisearch/rebuilder_spec.rb +10 -10
- data/spec/lib/pg_search/multisearch_spec.rb +5 -5
- data/spec/lib/pg_search/multisearchable_spec.rb +26 -26
- data/spec/lib/pg_search/normalizer_spec.rb +5 -5
- data/spec/lib/pg_search_spec.rb +30 -30
- data/spec/spec_helper.rb +1 -1
- data/spec/support/database.rb +12 -19
- metadata +4 -18
@@ -7,7 +7,7 @@ describe PgSearch::Normalizer do
|
|
7
7
|
context "when config[:ignore] includes :accents" do
|
8
8
|
context "when passed an Arel node" do
|
9
9
|
it "wraps the expression in unaccent()" do
|
10
|
-
config = double("config", :
|
10
|
+
config = double("config", ignore: [:accents])
|
11
11
|
node = Arel::Nodes::NamedFunction.new("foo", [Arel::Nodes.build_quoted("bar")])
|
12
12
|
|
13
13
|
normalizer = PgSearch::Normalizer.new(config)
|
@@ -19,7 +19,7 @@ describe PgSearch::Normalizer do
|
|
19
19
|
allow(PgSearch).to receive(:unaccent_function).and_return("my_unaccent")
|
20
20
|
node = Arel::Nodes::NamedFunction.new("foo", [Arel::Nodes.build_quoted("bar")])
|
21
21
|
|
22
|
-
config = double("config", :
|
22
|
+
config = double("config", ignore: [:accents])
|
23
23
|
|
24
24
|
normalizer = PgSearch::Normalizer.new(config)
|
25
25
|
expect(normalizer.add_normalization(node)).to eq("my_unaccent(foo('bar'))")
|
@@ -29,7 +29,7 @@ describe PgSearch::Normalizer do
|
|
29
29
|
|
30
30
|
context "when passed a String" do
|
31
31
|
it "wraps the expression in unaccent()" do
|
32
|
-
config = double("config", :
|
32
|
+
config = double("config", ignore: [:accents])
|
33
33
|
|
34
34
|
normalizer = PgSearch::Normalizer.new(config)
|
35
35
|
expect(normalizer.add_normalization("foo")).to eq("unaccent(foo)")
|
@@ -39,7 +39,7 @@ describe PgSearch::Normalizer do
|
|
39
39
|
it "wraps the expression in that function" do
|
40
40
|
allow(PgSearch).to receive(:unaccent_function).and_return("my_unaccent")
|
41
41
|
|
42
|
-
config = double("config", :
|
42
|
+
config = double("config", ignore: [:accents])
|
43
43
|
|
44
44
|
normalizer = PgSearch::Normalizer.new(config)
|
45
45
|
expect(normalizer.add_normalization("foo")).to eq("my_unaccent(foo)")
|
@@ -50,7 +50,7 @@ describe PgSearch::Normalizer do
|
|
50
50
|
|
51
51
|
context "when config[:ignore] does not include :accents" do
|
52
52
|
it "passes the expression through" do
|
53
|
-
config = double("config", :
|
53
|
+
config = double("config", ignore: [])
|
54
54
|
|
55
55
|
normalizer = PgSearch::Normalizer.new(config)
|
56
56
|
expect(normalizer.add_normalization("foo")).to eq("foo")
|
data/spec/lib/pg_search_spec.rb
CHANGED
@@ -32,7 +32,7 @@ describe PgSearch do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
context "with PgSearch.multisearch_options set to a Hash" do
|
35
|
-
before { allow(PgSearch).to receive(:multisearch_options).and_return(:
|
35
|
+
before { allow(PgSearch).to receive(:multisearch_options).and_return(using: :dmetaphone) }
|
36
36
|
subject do
|
37
37
|
PgSearch::Document.clear_searchable_cache
|
38
38
|
PgSearch.multisearch(query).map(&:searchable)
|
@@ -44,11 +44,11 @@ describe PgSearch do
|
|
44
44
|
end
|
45
45
|
model do
|
46
46
|
include PgSearch
|
47
|
-
multisearchable :
|
47
|
+
multisearchable against: :title
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
let!(:soundalike_record) { MultisearchableModel.create!(:
|
51
|
+
let!(:soundalike_record) { MultisearchableModel.create!(title: 'foning') }
|
52
52
|
let(:query) { "Phoning" }
|
53
53
|
it { is_expected.to include(soundalike_record) }
|
54
54
|
end
|
@@ -63,9 +63,9 @@ describe PgSearch do
|
|
63
63
|
allow(PgSearch).to receive(:multisearch_options) do
|
64
64
|
lambda do |query, soundalike|
|
65
65
|
if soundalike
|
66
|
-
{ :
|
66
|
+
{ using: :dmetaphone, query: query }
|
67
67
|
else
|
68
|
-
{ :
|
68
|
+
{ query: query }
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
@@ -77,11 +77,11 @@ describe PgSearch do
|
|
77
77
|
end
|
78
78
|
model do
|
79
79
|
include PgSearch
|
80
|
-
multisearchable :
|
80
|
+
multisearchable against: :title
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
let!(:soundalike_record) { MultisearchableModel.create!(:
|
84
|
+
let!(:soundalike_record) { MultisearchableModel.create!(title: 'foning') }
|
85
85
|
let(:query) { "Phoning" }
|
86
86
|
|
87
87
|
context "with soundalike true" do
|
@@ -107,7 +107,7 @@ describe PgSearch do
|
|
107
107
|
before do
|
108
108
|
searchable_subclass_model = Class.new(SuperclassModel) do
|
109
109
|
include PgSearch
|
110
|
-
multisearchable :
|
110
|
+
multisearchable against: :content
|
111
111
|
end
|
112
112
|
stub_const("SearchableSubclassModel", searchable_subclass_model)
|
113
113
|
stub_const("AnotherSearchableSubclassModel", searchable_subclass_model)
|
@@ -115,13 +115,13 @@ describe PgSearch do
|
|
115
115
|
end
|
116
116
|
|
117
117
|
it "returns only results for that subclass" do
|
118
|
-
included = SearchableSubclassModel.create!(:
|
118
|
+
included = SearchableSubclassModel.create!(content: "foo bar")
|
119
119
|
|
120
|
-
SearchableSubclassModel.create!(:
|
121
|
-
SuperclassModel.create!(:
|
122
|
-
SuperclassModel.create!(:
|
123
|
-
NonSearchableSubclassModel.create!(:
|
124
|
-
NonSearchableSubclassModel.create!(:
|
120
|
+
SearchableSubclassModel.create!(content: "baz")
|
121
|
+
SuperclassModel.create!(content: "foo bar")
|
122
|
+
SuperclassModel.create!(content: "baz")
|
123
|
+
NonSearchableSubclassModel.create!(content: "foo bar")
|
124
|
+
NonSearchableSubclassModel.create!(content: "baz")
|
125
125
|
|
126
126
|
expect(SuperclassModel.count).to be 6
|
127
127
|
expect(SearchableSubclassModel.count).to be 2
|
@@ -134,7 +134,7 @@ describe PgSearch do
|
|
134
134
|
end
|
135
135
|
|
136
136
|
it "updates an existing STI model does not create a new pg_search document" do
|
137
|
-
model = SearchableSubclassModel.create!(:
|
137
|
+
model = SearchableSubclassModel.create!(content: "foo bar")
|
138
138
|
expect(SearchableSubclassModel.count).to eq(1)
|
139
139
|
# We fetch the model from the database again otherwise
|
140
140
|
# the pg_search_document from the cache is used.
|
@@ -146,12 +146,12 @@ describe PgSearch do
|
|
146
146
|
end
|
147
147
|
|
148
148
|
it "reindexing works" do
|
149
|
-
NonSearchableSubclassModel.create!(:
|
150
|
-
NonSearchableSubclassModel.create!(:
|
151
|
-
expected = SearchableSubclassModel.create!(:
|
152
|
-
SuperclassModel.create!(:
|
153
|
-
SuperclassModel.create!(:
|
154
|
-
SuperclassModel.create!(:
|
149
|
+
NonSearchableSubclassModel.create!(content: "foo bar")
|
150
|
+
NonSearchableSubclassModel.create!(content: "baz")
|
151
|
+
expected = SearchableSubclassModel.create!(content: "baz")
|
152
|
+
SuperclassModel.create!(content: "foo bar")
|
153
|
+
SuperclassModel.create!(content: "baz")
|
154
|
+
SuperclassModel.create!(content: "baz2")
|
155
155
|
|
156
156
|
expect(SuperclassModel.count).to be 6
|
157
157
|
expect(NonSearchableSubclassModel.count).to be 2
|
@@ -168,8 +168,8 @@ describe PgSearch do
|
|
168
168
|
end
|
169
169
|
|
170
170
|
it "reindexing searchable STI doesn't clobber other related STI models" do
|
171
|
-
SearchableSubclassModel.create!(:
|
172
|
-
AnotherSearchableSubclassModel.create!(:
|
171
|
+
SearchableSubclassModel.create!(content: "baz")
|
172
|
+
AnotherSearchableSubclassModel.create!(content: "baz")
|
173
173
|
|
174
174
|
expect(PgSearch::Document.count).to be 2
|
175
175
|
PgSearch::Multisearch.rebuild(SearchableSubclassModel)
|
@@ -197,7 +197,7 @@ describe PgSearch do
|
|
197
197
|
before do
|
198
198
|
searchable_subclass_model = Class.new(SuperclassModel) do
|
199
199
|
include PgSearch
|
200
|
-
multisearchable :
|
200
|
+
multisearchable against: :content
|
201
201
|
end
|
202
202
|
stub_const("SearchableSubclassModel", searchable_subclass_model)
|
203
203
|
stub_const("AnotherSearchableSubclassModel", searchable_subclass_model)
|
@@ -205,13 +205,13 @@ describe PgSearch do
|
|
205
205
|
end
|
206
206
|
|
207
207
|
it "returns only results for that subclass" do
|
208
|
-
included = SearchableSubclassModel.create!(:
|
208
|
+
included = SearchableSubclassModel.create!(content: "foo bar")
|
209
209
|
|
210
|
-
SearchableSubclassModel.create!(:
|
211
|
-
SuperclassModel.create!(:
|
212
|
-
SuperclassModel.create!(:
|
213
|
-
NonSearchableSubclassModel.create!(:
|
214
|
-
NonSearchableSubclassModel.create!(:
|
210
|
+
SearchableSubclassModel.create!(content: "baz")
|
211
|
+
SuperclassModel.create!(content: "foo bar")
|
212
|
+
SuperclassModel.create!(content: "baz")
|
213
|
+
NonSearchableSubclassModel.create!(content: "foo bar")
|
214
|
+
NonSearchableSubclassModel.create!(content: "baz")
|
215
215
|
|
216
216
|
expect(SuperclassModel.count).to be 6
|
217
217
|
expect(SearchableSubclassModel.count).to be 2
|
data/spec/spec_helper.rb
CHANGED
@@ -22,7 +22,7 @@ require 'support/database'
|
|
22
22
|
require 'support/with_model'
|
23
23
|
|
24
24
|
DOCUMENTS_SCHEMA = lambda do |t|
|
25
|
-
t.belongs_to :searchable, :
|
25
|
+
t.belongs_to :searchable, polymorphic: true, index: true
|
26
26
|
t.text :content
|
27
27
|
t.timestamps null: false
|
28
28
|
end
|
data/spec/support/database.rb
CHANGED
@@ -1,29 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
case RUBY_PLATFORM
|
4
|
+
when "java"
|
4
5
|
require "activerecord-jdbc-adapter"
|
5
|
-
|
6
|
+
ERROR_CLASS = ActiveRecord::JDBCError
|
6
7
|
else
|
7
8
|
require "pg"
|
8
|
-
|
9
|
+
ERROR_CLASS = PG::Error
|
9
10
|
end
|
10
11
|
|
11
|
-
error_classes << ActiveRecord::NoDatabaseError if defined? ActiveRecord::NoDatabaseError
|
12
|
-
|
13
12
|
begin
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
ActiveRecord::Base.establish_connection(:adapter => 'postgresql',
|
21
|
-
:database => 'pg_search_test',
|
22
|
-
:username => database_user,
|
23
|
-
:min_messages => 'warning')
|
13
|
+
ActiveRecord::Base.establish_connection(adapter: 'postgresql',
|
14
|
+
database: 'pg_search_test',
|
15
|
+
username: (ENV["TRAVIS"] ? "postgres" : ENV["USER"]),
|
16
|
+
min_messages: 'warning')
|
24
17
|
connection = ActiveRecord::Base.connection
|
25
18
|
connection.execute("SELECT 1")
|
26
|
-
rescue
|
19
|
+
rescue ERROR_CLASS, ActiveRecord::NoDatabaseError => e
|
27
20
|
at_exit do
|
28
21
|
puts "-" * 80
|
29
22
|
puts "Unable to connect to database. Please run:"
|
@@ -31,7 +24,7 @@ rescue *error_classes => exception
|
|
31
24
|
puts " createdb pg_search_test"
|
32
25
|
puts "-" * 80
|
33
26
|
end
|
34
|
-
raise
|
27
|
+
raise e
|
35
28
|
end
|
36
29
|
|
37
30
|
if ENV["LOGGER"]
|
@@ -45,13 +38,13 @@ def install_extension(name)
|
|
45
38
|
return unless extension.none?
|
46
39
|
|
47
40
|
connection.execute "CREATE EXTENSION #{name};"
|
48
|
-
rescue StandardError =>
|
41
|
+
rescue StandardError => e
|
49
42
|
at_exit do
|
50
43
|
puts "-" * 80
|
51
44
|
puts "Please install the #{name} extension"
|
52
45
|
puts "-" * 80
|
53
46
|
end
|
54
|
-
raise
|
47
|
+
raise e
|
55
48
|
end
|
56
49
|
|
57
50
|
def install_extension_if_missing(name, query, expected_result)
|
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.5
|
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: 2019-
|
12
|
+
date: 2019-04-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -39,20 +39,6 @@ dependencies:
|
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '4.2'
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: codeclimate-test-reporter
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
45
|
-
requirements:
|
46
|
-
- - ">="
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: '0'
|
49
|
-
type: :development
|
50
|
-
prerelease: false
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - ">="
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: '0'
|
56
42
|
- !ruby/object:Gem::Dependency
|
57
43
|
name: pry
|
58
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -217,14 +203,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
217
203
|
requirements:
|
218
204
|
- - ">="
|
219
205
|
- !ruby/object:Gem::Version
|
220
|
-
version: '2.
|
206
|
+
version: '2.4'
|
221
207
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
222
208
|
requirements:
|
223
209
|
- - ">="
|
224
210
|
- !ruby/object:Gem::Version
|
225
211
|
version: '0'
|
226
212
|
requirements: []
|
227
|
-
rubygems_version: 3.0.
|
213
|
+
rubygems_version: 3.0.3
|
228
214
|
signing_key:
|
229
215
|
specification_version: 4
|
230
216
|
summary: PgSearch builds Active Record named scopes that take advantage of PostgreSQL's
|