pg_search 2.1.2 → 2.3.6
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 +5 -5
- data/.codeclimate.yml +1 -0
- data/.editorconfig +10 -0
- data/.github/dependabot.yml +11 -0
- data/.github/workflows/ci.yml +75 -0
- data/.jrubyrc +1 -0
- data/.rubocop.yml +95 -10
- data/.travis.yml +26 -48
- data/CHANGELOG.md +179 -112
- data/CODE_OF_CONDUCT.md +76 -0
- data/CONTRIBUTING.md +5 -3
- data/Gemfile +6 -4
- data/LICENSE +1 -1
- data/README.md +307 -198
- data/Rakefile +7 -3
- data/lib/pg_search/configuration/association.rb +2 -0
- data/lib/pg_search/configuration/column.rb +2 -0
- data/lib/pg_search/configuration/foreign_column.rb +2 -0
- data/lib/pg_search/configuration.rb +20 -6
- data/lib/pg_search/document.rb +7 -5
- data/lib/pg_search/features/dmetaphone.rb +7 -7
- data/lib/pg_search/features/feature.rb +4 -2
- data/lib/pg_search/features/trigram.rb +31 -5
- data/lib/pg_search/features/tsearch.rb +18 -14
- data/lib/pg_search/features.rb +2 -0
- data/lib/pg_search/migration/dmetaphone_generator.rb +3 -1
- data/lib/pg_search/migration/generator.rb +4 -2
- data/lib/pg_search/migration/multisearch_generator.rb +2 -1
- 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 +3 -3
- data/lib/pg_search/model.rb +57 -0
- data/lib/pg_search/multisearch/rebuilder.rb +14 -6
- data/lib/pg_search/multisearch.rb +23 -6
- data/lib/pg_search/multisearchable.rb +10 -6
- data/lib/pg_search/normalizer.rb +2 -0
- data/lib/pg_search/railtie.rb +2 -0
- data/lib/pg_search/scope_options.rb +26 -49
- data/lib/pg_search/tasks.rb +5 -1
- data/lib/pg_search/version.rb +3 -1
- data/lib/pg_search.rb +17 -55
- data/pg_search.gemspec +19 -11
- data/spec/.rubocop.yml +2 -2
- data/spec/integration/.rubocop.yml +11 -0
- data/spec/integration/associations_spec.rb +125 -162
- data/spec/integration/deprecation_spec.rb +33 -0
- data/spec/integration/pagination_spec.rb +10 -8
- data/spec/integration/pg_search_spec.rb +359 -306
- data/spec/integration/single_table_inheritance_spec.rb +18 -17
- data/spec/lib/pg_search/configuration/association_spec.rb +17 -13
- data/spec/lib/pg_search/configuration/column_spec.rb +2 -0
- data/spec/lib/pg_search/configuration/foreign_column_spec.rb +6 -4
- data/spec/lib/pg_search/features/dmetaphone_spec.rb +6 -4
- data/spec/lib/pg_search/features/trigram_spec.rb +51 -20
- data/spec/lib/pg_search/features/tsearch_spec.rb +29 -21
- data/spec/lib/pg_search/multisearch/rebuilder_spec.rb +151 -85
- data/spec/lib/pg_search/multisearch_spec.rb +67 -37
- data/spec/lib/pg_search/multisearchable_spec.rb +217 -123
- data/spec/lib/pg_search/normalizer_spec.rb +14 -10
- data/spec/lib/pg_search_spec.rb +102 -89
- data/spec/spec_helper.rb +25 -6
- data/spec/support/database.rb +19 -21
- data/spec/support/with_model.rb +2 -0
- metadata +106 -29
- data/.autotest +0 -5
- data/.rubocop_todo.yml +0 -163
- data/Guardfile +0 -6
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
describe "a pg_search_scope on an STI subclass" do
|
@@ -9,8 +11,8 @@ describe "a pg_search_scope on an STI subclass" do
|
|
9
11
|
end
|
10
12
|
|
11
13
|
model do
|
12
|
-
include PgSearch
|
13
|
-
pg_search_scope :search_content, :
|
14
|
+
include PgSearch::Model
|
15
|
+
pg_search_scope :search_content, against: :content
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
@@ -21,14 +23,14 @@ describe "a pg_search_scope on an STI subclass" do
|
|
21
23
|
|
22
24
|
it "returns only results for that subclass" do
|
23
25
|
included = [
|
24
|
-
SearchableSubclassModel.create!(:
|
26
|
+
SearchableSubclassModel.create!(content: "foo bar")
|
25
27
|
]
|
26
28
|
excluded = [
|
27
|
-
SearchableSubclassModel.create!(:
|
28
|
-
SuperclassModel.create!(:
|
29
|
-
SuperclassModel.create!(:
|
30
|
-
AnotherSearchableSubclassModel.create!(:
|
31
|
-
AnotherSearchableSubclassModel.create!(:
|
29
|
+
SearchableSubclassModel.create!(content: "baz"),
|
30
|
+
SuperclassModel.create!(content: "foo bar"),
|
31
|
+
SuperclassModel.create!(content: "baz"),
|
32
|
+
AnotherSearchableSubclassModel.create!(content: "foo bar"),
|
33
|
+
AnotherSearchableSubclassModel.create!(content: "baz")
|
32
34
|
]
|
33
35
|
|
34
36
|
expect(SuperclassModel.count).to eq(6)
|
@@ -49,9 +51,9 @@ describe "a pg_search_scope on an STI subclass" do
|
|
49
51
|
end
|
50
52
|
|
51
53
|
model do
|
52
|
-
include PgSearch
|
54
|
+
include PgSearch::Model
|
53
55
|
self.inheritance_column = 'custom_type'
|
54
|
-
pg_search_scope :search_content, :
|
56
|
+
pg_search_scope :search_content, against: :content
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
@@ -62,14 +64,14 @@ describe "a pg_search_scope on an STI subclass" do
|
|
62
64
|
|
63
65
|
it "returns only results for that subclass" do
|
64
66
|
included = [
|
65
|
-
SearchableSubclassModel.create!(:
|
67
|
+
SearchableSubclassModel.create!(content: "foo bar")
|
66
68
|
]
|
67
69
|
excluded = [
|
68
|
-
SearchableSubclassModel.create!(:
|
69
|
-
SuperclassModel.create!(:
|
70
|
-
SuperclassModel.create!(:
|
71
|
-
AnotherSearchableSubclassModel.create!(:
|
72
|
-
AnotherSearchableSubclassModel.create!(:
|
70
|
+
SearchableSubclassModel.create!(content: "baz"),
|
71
|
+
SuperclassModel.create!(content: "foo bar"),
|
72
|
+
SuperclassModel.create!(content: "baz"),
|
73
|
+
AnotherSearchableSubclassModel.create!(content: "foo bar"),
|
74
|
+
AnotherSearchableSubclassModel.create!(content: "baz")
|
73
75
|
]
|
74
76
|
|
75
77
|
expect(SuperclassModel.count).to eq(6)
|
@@ -82,4 +84,3 @@ describe "a pg_search_scope on an STI subclass" do
|
|
82
84
|
end
|
83
85
|
end
|
84
86
|
end
|
85
|
-
|
@@ -1,5 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
5
|
+
# rubocop:disable RSpec/NestedGroups
|
3
6
|
describe PgSearch::Configuration::Association do
|
4
7
|
with_model :Avatar do
|
5
8
|
table do |t|
|
@@ -15,12 +18,12 @@ describe PgSearch::Configuration::Association do
|
|
15
18
|
end
|
16
19
|
|
17
20
|
model do
|
18
|
-
include PgSearch
|
19
|
-
has_one :avatar, :
|
21
|
+
include PgSearch::Model
|
22
|
+
has_one :avatar, class_name: "Avatar"
|
20
23
|
belongs_to :site
|
21
24
|
|
22
|
-
pg_search_scope :with_avatar, :
|
23
|
-
pg_search_scope :with_site, :
|
25
|
+
pg_search_scope :with_avatar, associated_against: { avatar: :url }
|
26
|
+
pg_search_scope :with_site, associated_against: { site: :title }
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
@@ -30,14 +33,14 @@ describe PgSearch::Configuration::Association do
|
|
30
33
|
end
|
31
34
|
|
32
35
|
model do
|
33
|
-
include PgSearch
|
34
|
-
has_many :users, :
|
36
|
+
include PgSearch::Model
|
37
|
+
has_many :users, class_name: "User"
|
35
38
|
|
36
|
-
pg_search_scope :with_users, :
|
39
|
+
pg_search_scope :with_users, associated_against: { users: :name }
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
40
|
-
context "has_one" do
|
43
|
+
context "with has_one" do
|
41
44
|
let(:association) { described_class.new(User, :avatar, :url) }
|
42
45
|
|
43
46
|
describe "#table_name" do
|
@@ -48,7 +51,7 @@ describe PgSearch::Configuration::Association do
|
|
48
51
|
|
49
52
|
describe "#join" do
|
50
53
|
let(:expected_sql) do
|
51
|
-
|
54
|
+
<<~SQL.squish
|
52
55
|
LEFT OUTER JOIN
|
53
56
|
(SELECT model_id AS id,
|
54
57
|
#{column_select} AS #{association.columns.first.alias}
|
@@ -68,7 +71,7 @@ describe PgSearch::Configuration::Association do
|
|
68
71
|
end
|
69
72
|
end
|
70
73
|
|
71
|
-
context "belongs_to" do
|
74
|
+
context "with belongs_to" do
|
72
75
|
let(:association) { described_class.new(User, :site, :title) }
|
73
76
|
|
74
77
|
describe "#table_name" do
|
@@ -79,7 +82,7 @@ describe PgSearch::Configuration::Association do
|
|
79
82
|
|
80
83
|
describe "#join" do
|
81
84
|
let(:expected_sql) do
|
82
|
-
|
85
|
+
<<~SQL.squish
|
83
86
|
LEFT OUTER JOIN
|
84
87
|
(SELECT model_id AS id,
|
85
88
|
#{column_select} AS #{association.columns.first.alias}
|
@@ -99,7 +102,7 @@ describe PgSearch::Configuration::Association do
|
|
99
102
|
end
|
100
103
|
end
|
101
104
|
|
102
|
-
context "has_many" do
|
105
|
+
context "with has_many" do
|
103
106
|
let(:association) { described_class.new(Site, :users, :name) }
|
104
107
|
|
105
108
|
describe "#table_name" do
|
@@ -110,7 +113,7 @@ describe PgSearch::Configuration::Association do
|
|
110
113
|
|
111
114
|
describe "#join" do
|
112
115
|
let(:expected_sql) do
|
113
|
-
|
116
|
+
<<~SQL.squish
|
114
117
|
LEFT OUTER JOIN
|
115
118
|
(SELECT model_id AS id,
|
116
119
|
string_agg(\"#{association.table_name}\".\"name\"::text, ' ') AS #{association.columns.first.alias}
|
@@ -136,3 +139,4 @@ describe PgSearch::Configuration::Association do
|
|
136
139
|
end
|
137
140
|
end
|
138
141
|
end
|
142
|
+
# rubocop:enable RSpec/NestedGroups
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
describe PgSearch::Configuration::ForeignColumn do
|
@@ -15,17 +17,17 @@ describe PgSearch::Configuration::ForeignColumn do
|
|
15
17
|
end
|
16
18
|
|
17
19
|
model do
|
18
|
-
include PgSearch
|
20
|
+
include PgSearch::Model
|
19
21
|
belongs_to :another_model, class_name: 'AssociatedModel'
|
20
22
|
|
21
|
-
pg_search_scope :with_another, :
|
23
|
+
pg_search_scope :with_another, associated_against: { another_model: :title }
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
27
|
it "returns a consistent string" do
|
26
28
|
association = PgSearch::Configuration::Association.new(Model,
|
27
|
-
|
28
|
-
|
29
|
+
:another_model,
|
30
|
+
:title)
|
29
31
|
foreign_column = described_class.new("title", nil, Model, association)
|
30
32
|
|
31
33
|
column_alias = foreign_column.alias
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
describe PgSearch::Features::DMetaphone do
|
@@ -13,10 +15,10 @@ describe PgSearch::Features::DMetaphone do
|
|
13
15
|
query = "query"
|
14
16
|
columns = [
|
15
17
|
PgSearch::Configuration::Column.new(:name, nil, Model),
|
16
|
-
PgSearch::Configuration::Column.new(:content, nil, Model)
|
18
|
+
PgSearch::Configuration::Column.new(:content, nil, Model)
|
17
19
|
]
|
18
20
|
options = {}
|
19
|
-
config =
|
21
|
+
config = instance_double("PgSearch::Configuration", :config, ignore: [])
|
20
22
|
normalizer = PgSearch::Normalizer.new(config)
|
21
23
|
|
22
24
|
feature = described_class.new(query, options, columns, Model, normalizer)
|
@@ -38,10 +40,10 @@ describe PgSearch::Features::DMetaphone do
|
|
38
40
|
query = "query"
|
39
41
|
columns = [
|
40
42
|
PgSearch::Configuration::Column.new(:name, nil, Model),
|
41
|
-
PgSearch::Configuration::Column.new(:content, nil, Model)
|
43
|
+
PgSearch::Configuration::Column.new(:content, nil, Model)
|
42
44
|
]
|
43
45
|
options = {}
|
44
|
-
config =
|
46
|
+
config = instance_double("PgSearch::Configuration", :config, ignore: [])
|
45
47
|
normalizer = PgSearch::Normalizer.new(config)
|
46
48
|
|
47
49
|
feature = described_class.new(query, options, columns, Model, normalizer)
|
@@ -1,8 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'ostruct'
|
3
5
|
|
6
|
+
# rubocop:disable RSpec/MultipleMemoizedHelpers, RSpec/NestedGroups
|
4
7
|
describe PgSearch::Features::Trigram do
|
5
8
|
subject(:feature) { described_class.new(query, options, columns, Model, normalizer) }
|
9
|
+
|
6
10
|
let(:query) { 'lolwut' }
|
7
11
|
let(:options) { {} }
|
8
12
|
let(:columns) {
|
@@ -12,11 +16,13 @@ describe PgSearch::Features::Trigram do
|
|
12
16
|
]
|
13
17
|
}
|
14
18
|
let(:normalizer) { PgSearch::Normalizer.new(config) }
|
15
|
-
let(:config) { OpenStruct.new(:
|
19
|
+
let(:config) { OpenStruct.new(ignore: []) } # rubocop:disable Style/OpenStructUse
|
16
20
|
|
17
21
|
let(:coalesced_columns) do
|
18
|
-
|
19
|
-
coalesce(#{Model.quoted_table_name}."name"::text, '')
|
22
|
+
<<~SQL.squish
|
23
|
+
coalesce(#{Model.quoted_table_name}."name"::text, '')
|
24
|
+
|| ' '
|
25
|
+
|| coalesce(#{Model.quoted_table_name}."content"::text, '')
|
20
26
|
SQL
|
21
27
|
end
|
22
28
|
|
@@ -30,44 +36,68 @@ describe PgSearch::Features::Trigram do
|
|
30
36
|
describe 'conditions' do
|
31
37
|
it 'escapes the search document and query' do
|
32
38
|
config.ignore = []
|
33
|
-
expect(feature.conditions.to_sql).to eq("(
|
39
|
+
expect(feature.conditions.to_sql).to eq("('#{query}' % (#{coalesced_columns}))")
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when searching by word_similarity' do
|
43
|
+
let(:options) do
|
44
|
+
{ word_similarity: true }
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'uses the "<%" operator when searching by word_similarity' do
|
48
|
+
config.ignore = []
|
49
|
+
expect(feature.conditions.to_sql).to eq("('#{query}' <% (#{coalesced_columns}))")
|
50
|
+
end
|
34
51
|
end
|
35
52
|
|
36
|
-
context 'ignoring accents' do
|
53
|
+
context 'when ignoring accents' do
|
37
54
|
it 'escapes the search document and query, but not the accent function' do
|
38
55
|
config.ignore = [:accents]
|
39
|
-
expect(feature.conditions.to_sql).to eq("(
|
56
|
+
expect(feature.conditions.to_sql).to eq("(unaccent('#{query}') % (unaccent(#{coalesced_columns})))")
|
40
57
|
end
|
41
58
|
end
|
42
59
|
|
43
60
|
context 'when a threshold is specified' do
|
44
|
-
|
45
|
-
|
61
|
+
context 'when searching by similarity' do
|
62
|
+
let(:options) do
|
63
|
+
{ threshold: 0.5 }
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'uses a minimum similarity expression instead of the "%" operator' do
|
67
|
+
expect(feature.conditions.to_sql).to eq(
|
68
|
+
"(similarity('#{query}', (#{coalesced_columns})) >= 0.5)"
|
69
|
+
)
|
70
|
+
end
|
46
71
|
end
|
47
72
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
73
|
+
context 'when searching by word_similarity' do
|
74
|
+
let(:options) do
|
75
|
+
{ threshold: 0.5, word_similarity: true }
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'uses a minimum similarity expression instead of the "<%" operator' do
|
79
|
+
expect(feature.conditions.to_sql).to eq(
|
80
|
+
"(word_similarity('#{query}', (#{coalesced_columns})) >= 0.5)"
|
81
|
+
)
|
82
|
+
end
|
52
83
|
end
|
53
84
|
end
|
54
85
|
|
55
|
-
context 'only certain columns are selected' do
|
56
|
-
context 'one column' do
|
86
|
+
context 'when only certain columns are selected' do
|
87
|
+
context 'with one column' do
|
57
88
|
let(:options) { { only: :name } }
|
58
89
|
|
59
90
|
it 'only searches against the select column' do
|
60
|
-
options = { only: :name }
|
61
91
|
coalesced_column = "coalesce(#{Model.quoted_table_name}.\"name\"::text, '')"
|
62
|
-
expect(feature.conditions.to_sql).to eq("(
|
92
|
+
expect(feature.conditions.to_sql).to eq("('#{query}' % (#{coalesced_column}))")
|
63
93
|
end
|
64
94
|
end
|
65
|
-
|
95
|
+
|
96
|
+
context 'with multiple columns' do
|
66
97
|
let(:options) { { only: %i[name content] } }
|
67
98
|
|
68
99
|
it 'concatenates when multiples columns are selected' do
|
69
|
-
|
70
|
-
expect(feature.conditions.to_sql).to eq("((#{coalesced_columns}) % '#{query}')")
|
100
|
+
expect(feature.conditions.to_sql).to eq("('#{query}' % (#{coalesced_columns}))")
|
71
101
|
end
|
72
102
|
end
|
73
103
|
end
|
@@ -75,7 +105,8 @@ describe PgSearch::Features::Trigram do
|
|
75
105
|
|
76
106
|
describe '#rank' do
|
77
107
|
it 'returns an expression using the similarity() function' do
|
78
|
-
expect(feature.rank.to_sql).to eq("(similarity(
|
108
|
+
expect(feature.rank.to_sql).to eq("(similarity('#{query}', (#{coalesced_columns})))")
|
79
109
|
end
|
80
110
|
end
|
81
111
|
end
|
112
|
+
# rubocop:enable RSpec/MultipleMemoizedHelpers, RSpec/NestedGroups
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
require "active_support/deprecation"
|
3
5
|
|
@@ -14,10 +16,10 @@ describe PgSearch::Features::TSearch do
|
|
14
16
|
query = "query"
|
15
17
|
columns = [
|
16
18
|
PgSearch::Configuration::Column.new(:name, nil, Model),
|
17
|
-
PgSearch::Configuration::Column.new(:content, nil, Model)
|
19
|
+
PgSearch::Configuration::Column.new(:content, nil, Model)
|
18
20
|
]
|
19
21
|
options = {}
|
20
|
-
config =
|
22
|
+
config = instance_double("PgSearch::Configuration", :config, ignore: [])
|
21
23
|
normalizer = PgSearch::Normalizer.new(config)
|
22
24
|
|
23
25
|
feature = described_class.new(query, options, columns, Model, normalizer)
|
@@ -39,10 +41,10 @@ describe PgSearch::Features::TSearch do
|
|
39
41
|
query = "query"
|
40
42
|
columns = [
|
41
43
|
PgSearch::Configuration::Column.new(:name, nil, Model),
|
42
|
-
PgSearch::Configuration::Column.new(:content, nil, Model)
|
44
|
+
PgSearch::Configuration::Column.new(:content, nil, Model)
|
43
45
|
]
|
44
46
|
options = {}
|
45
|
-
config =
|
47
|
+
config = instance_double("PgSearch::Configuration", :config, ignore: [])
|
46
48
|
normalizer = PgSearch::Normalizer.new(config)
|
47
49
|
|
48
50
|
feature = described_class.new(query, options, columns, Model, normalizer)
|
@@ -56,10 +58,10 @@ describe PgSearch::Features::TSearch do
|
|
56
58
|
query = "!query"
|
57
59
|
columns = [
|
58
60
|
PgSearch::Configuration::Column.new(:name, nil, Model),
|
59
|
-
PgSearch::Configuration::Column.new(:content, nil, Model)
|
61
|
+
PgSearch::Configuration::Column.new(:content, nil, Model)
|
60
62
|
]
|
61
|
-
options = {:
|
62
|
-
config =
|
63
|
+
options = { negation: true }
|
64
|
+
config = instance_double("PgSearch::Configuration", :config, ignore: [])
|
63
65
|
normalizer = PgSearch::Normalizer.new(config)
|
64
66
|
|
65
67
|
feature = described_class.new(query, options, columns, Model, normalizer)
|
@@ -74,10 +76,10 @@ describe PgSearch::Features::TSearch do
|
|
74
76
|
query = "!query"
|
75
77
|
columns = [
|
76
78
|
PgSearch::Configuration::Column.new(:name, nil, Model),
|
77
|
-
PgSearch::Configuration::Column.new(:content, nil, Model)
|
79
|
+
PgSearch::Configuration::Column.new(:content, nil, Model)
|
78
80
|
]
|
79
|
-
options = {:
|
80
|
-
config =
|
81
|
+
options = { negation: false }
|
82
|
+
config = instance_double("PgSearch::Configuration", :config, ignore: [])
|
81
83
|
normalizer = PgSearch::Normalizer.new(config)
|
82
84
|
|
83
85
|
feature = described_class.new(query, options, columns, Model, normalizer)
|
@@ -92,10 +94,10 @@ describe PgSearch::Features::TSearch do
|
|
92
94
|
query = "query"
|
93
95
|
columns = [
|
94
96
|
PgSearch::Configuration::Column.new(:name, nil, Model),
|
95
|
-
PgSearch::Configuration::Column.new(:content, nil, Model)
|
97
|
+
PgSearch::Configuration::Column.new(:content, nil, Model)
|
96
98
|
]
|
97
|
-
options = {tsvector_column: "my_tsvector"}
|
98
|
-
config =
|
99
|
+
options = { tsvector_column: "my_tsvector" }
|
100
|
+
config = instance_double("PgSearch::Configuration", :config, ignore: [])
|
99
101
|
normalizer = PgSearch::Normalizer.new(config)
|
100
102
|
|
101
103
|
feature = described_class.new(query, options, columns, Model, normalizer)
|
@@ -110,10 +112,10 @@ describe PgSearch::Features::TSearch do
|
|
110
112
|
query = "query"
|
111
113
|
columns = [
|
112
114
|
PgSearch::Configuration::Column.new(:name, nil, Model),
|
113
|
-
PgSearch::Configuration::Column.new(:content, nil, Model)
|
115
|
+
PgSearch::Configuration::Column.new(:content, nil, Model)
|
114
116
|
]
|
115
|
-
options = {tsvector_column: ["tsvector1", "tsvector2"]}
|
116
|
-
config =
|
117
|
+
options = { tsvector_column: ["tsvector1", "tsvector2"] }
|
118
|
+
config = instance_double("PgSearch::Configuration", :config, ignore: [])
|
117
119
|
normalizer = PgSearch::Normalizer.new(config)
|
118
120
|
|
119
121
|
feature = described_class.new(query, options, columns, Model, normalizer)
|
@@ -139,7 +141,7 @@ describe PgSearch::Features::TSearch do
|
|
139
141
|
]
|
140
142
|
options = {}
|
141
143
|
|
142
|
-
config =
|
144
|
+
config = instance_double("PgSearch::Configuration", :config, ignore: [])
|
143
145
|
normalizer = PgSearch::Normalizer.new(config)
|
144
146
|
|
145
147
|
feature = described_class.new(query, options, columns, Model, normalizer)
|
@@ -149,11 +151,12 @@ describe PgSearch::Features::TSearch do
|
|
149
151
|
end
|
150
152
|
|
151
153
|
context "when options[:dictionary] is passed" do
|
154
|
+
# rubocop:disable RSpec/ExampleLength
|
152
155
|
it 'uses the provided dictionary' do
|
153
156
|
query = "query"
|
154
157
|
columns = [
|
155
158
|
PgSearch::Configuration::Column.new(:name, nil, Model),
|
156
|
-
PgSearch::Configuration::Column.new(:content, nil, Model)
|
159
|
+
PgSearch::Configuration::Column.new(:content, nil, Model)
|
157
160
|
]
|
158
161
|
options = {
|
159
162
|
dictionary: "spanish",
|
@@ -163,7 +166,7 @@ describe PgSearch::Features::TSearch do
|
|
163
166
|
}
|
164
167
|
}
|
165
168
|
|
166
|
-
config =
|
169
|
+
config = instance_double("PgSearch::Configuration", :config, ignore: [])
|
167
170
|
normalizer = PgSearch::Normalizer.new(config)
|
168
171
|
|
169
172
|
feature = described_class.new(query, options, columns, Model, normalizer)
|
@@ -172,9 +175,11 @@ describe PgSearch::Features::TSearch do
|
|
172
175
|
|
173
176
|
expect(feature.highlight.to_sql).to eq(expected_sql)
|
174
177
|
end
|
178
|
+
# rubocop:enable RSpec/ExampleLength
|
175
179
|
end
|
176
180
|
|
177
181
|
context "when options[:highlight] has options set" do
|
182
|
+
# rubocop:disable RSpec/ExampleLength
|
178
183
|
it "passes the options to ts_headline" do
|
179
184
|
query = "query"
|
180
185
|
columns = [
|
@@ -193,7 +198,7 @@ describe PgSearch::Features::TSearch do
|
|
193
198
|
}
|
194
199
|
}
|
195
200
|
|
196
|
-
config =
|
201
|
+
config = instance_double("PgSearch::Configuration", :config, ignore: [])
|
197
202
|
normalizer = PgSearch::Normalizer.new(config)
|
198
203
|
|
199
204
|
feature = described_class.new(query, options, columns, Model, normalizer)
|
@@ -202,7 +207,9 @@ describe PgSearch::Features::TSearch do
|
|
202
207
|
|
203
208
|
expect(feature.highlight.to_sql).to eq(expected_sql)
|
204
209
|
end
|
210
|
+
# rubocop:enable RSpec/ExampleLength
|
205
211
|
|
212
|
+
# rubocop:disable RSpec/ExampleLength
|
206
213
|
it "passes deprecated options to ts_headline" do
|
207
214
|
query = "query"
|
208
215
|
columns = [
|
@@ -221,7 +228,7 @@ describe PgSearch::Features::TSearch do
|
|
221
228
|
}
|
222
229
|
}
|
223
230
|
|
224
|
-
config =
|
231
|
+
config = instance_double("PgSearch::Configuration", :config, ignore: [])
|
225
232
|
normalizer = PgSearch::Normalizer.new(config)
|
226
233
|
|
227
234
|
feature = described_class.new(query, options, columns, Model, normalizer)
|
@@ -231,6 +238,7 @@ describe PgSearch::Features::TSearch do
|
|
231
238
|
|
232
239
|
expect(highlight_sql).to eq(expected_sql)
|
233
240
|
end
|
241
|
+
# rubocop:enable RSpec/ExampleLength
|
234
242
|
end
|
235
243
|
end
|
236
244
|
end
|