pg_search 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +4 -0
- data/lib/pg_search/features/tsearch.rb +44 -13
- data/lib/pg_search/scope_options.rb +0 -2
- data/lib/pg_search/version.rb +1 -1
- data/pg_search.gemspec +0 -2
- data/spec/lib/pg_search/configuration/association_spec.rb +6 -6
- data/spec/lib/pg_search/features/tsearch_spec.rb +30 -0
- data/spec/lib/pg_search_spec.rb +1 -1
- data/spec/support/database.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 253c1319e785dfac16b15e9ffc72d7d37b60eda5
|
4
|
+
data.tar.gz: 78931e1fac31befac51f12b5ae2c26c13a11994a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53f22f8135d1992271bae14aa8b77cc76fd75d625b60c01075157383f9716c3aee9e1bf6e404e79b21cdbb0a7e611c9b820e3553a05485ba485f3b404a2afa28
|
7
|
+
data.tar.gz: 768c5c7a66b4875cce05f12b4e0bbe50ddd8dc8a6bd3afdcb2acf9db2334ffe1ad1d04d99814a0bf38876a7829320faeda5227886a13b5c81720a33d7438223b
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "active_support/core_ext/module/delegation"
|
2
|
+
require 'active_support/deprecation'
|
2
3
|
|
3
4
|
module PgSearch
|
4
5
|
module Features
|
@@ -35,11 +36,14 @@ module PgSearch
|
|
35
36
|
def ts_headline_options
|
36
37
|
return '' unless options[:highlight].is_a?(Hash)
|
37
38
|
|
38
|
-
headline_options
|
39
|
-
|
39
|
+
headline_options
|
40
|
+
.merge(deprecated_headline_options)
|
41
|
+
.map { |key, value| "#{key} = #{value}" unless value.nil? }
|
42
|
+
.compact
|
43
|
+
.join(", ")
|
40
44
|
end
|
41
45
|
|
42
|
-
def
|
46
|
+
def headline_options
|
43
47
|
indifferent_options = options.with_indifferent_access
|
44
48
|
|
45
49
|
%w[
|
@@ -48,20 +52,47 @@ module PgSearch
|
|
48
52
|
hash.tap do
|
49
53
|
value = indifferent_options[:highlight][key]
|
50
54
|
|
51
|
-
hash[key] =
|
52
|
-
when String
|
53
|
-
%("#{value.gsub('"', '""')}")
|
54
|
-
when true
|
55
|
-
"TRUE"
|
56
|
-
when false
|
57
|
-
"FALSE"
|
58
|
-
else
|
59
|
-
value
|
60
|
-
end
|
55
|
+
hash[key] = ts_headline_option_value(value)
|
61
56
|
end
|
62
57
|
end
|
63
58
|
end
|
64
59
|
|
60
|
+
def deprecated_headline_options
|
61
|
+
indifferent_options = options.with_indifferent_access
|
62
|
+
|
63
|
+
%w[
|
64
|
+
start_sel stop_sel max_fragments max_words min_words short_word fragment_delimiter highlight_all
|
65
|
+
].reduce({}) do |hash, deprecated_key|
|
66
|
+
hash.tap do
|
67
|
+
value = indifferent_options[:highlight][deprecated_key]
|
68
|
+
|
69
|
+
unless value.nil?
|
70
|
+
key = deprecated_key.camelize
|
71
|
+
|
72
|
+
ActiveSupport::Deprecation.warn(
|
73
|
+
"pg_search 3.0 will no longer accept :#{deprecated_key} as an argument to :ts_headline, " \
|
74
|
+
"use :#{key} instead."
|
75
|
+
)
|
76
|
+
|
77
|
+
hash[key] = ts_headline_option_value(value)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def ts_headline_option_value(value)
|
84
|
+
case value
|
85
|
+
when String
|
86
|
+
%("#{value.gsub('"', '""')}")
|
87
|
+
when true
|
88
|
+
"TRUE"
|
89
|
+
when false
|
90
|
+
"FALSE"
|
91
|
+
else
|
92
|
+
value
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
65
96
|
DISALLOWED_TSQUERY_CHARACTERS = /['?\\:]/
|
66
97
|
|
67
98
|
def tsquery_for_term(unsanitized_term) # rubocop:disable Metrics/AbcSize
|
data/lib/pg_search/version.rb
CHANGED
data/pg_search.gemspec
CHANGED
@@ -48,7 +48,7 @@ describe PgSearch::Configuration::Association do
|
|
48
48
|
|
49
49
|
describe "#join" do
|
50
50
|
let(:expected_sql) do
|
51
|
-
<<-
|
51
|
+
<<-SQL.gsub(/\s+/, ' ').strip
|
52
52
|
LEFT OUTER JOIN
|
53
53
|
(SELECT model_id AS id,
|
54
54
|
#{column_select} AS #{association.columns.first.alias}
|
@@ -56,7 +56,7 @@ describe PgSearch::Configuration::Association do
|
|
56
56
|
INNER JOIN \"#{association.table_name}\"
|
57
57
|
ON \"#{association.table_name}\".\"user_id\" = \"#{User.table_name}\".\"id\") #{association.subselect_alias}
|
58
58
|
ON #{association.subselect_alias}.id = model_id
|
59
|
-
|
59
|
+
SQL
|
60
60
|
end
|
61
61
|
let(:column_select) do
|
62
62
|
"\"#{association.table_name}\".\"url\"::text"
|
@@ -79,7 +79,7 @@ describe PgSearch::Configuration::Association do
|
|
79
79
|
|
80
80
|
describe "#join" do
|
81
81
|
let(:expected_sql) do
|
82
|
-
<<-
|
82
|
+
<<-SQL.gsub(/\s+/, ' ').strip
|
83
83
|
LEFT OUTER JOIN
|
84
84
|
(SELECT model_id AS id,
|
85
85
|
#{column_select} AS #{association.columns.first.alias}
|
@@ -87,7 +87,7 @@ describe PgSearch::Configuration::Association do
|
|
87
87
|
INNER JOIN \"#{association.table_name}\"
|
88
88
|
ON \"#{association.table_name}\".\"id\" = \"#{User.table_name}\".\"site_id\") #{association.subselect_alias}
|
89
89
|
ON #{association.subselect_alias}.id = model_id
|
90
|
-
|
90
|
+
SQL
|
91
91
|
end
|
92
92
|
let(:column_select) do
|
93
93
|
"\"#{association.table_name}\".\"title\"::text"
|
@@ -110,7 +110,7 @@ describe PgSearch::Configuration::Association do
|
|
110
110
|
|
111
111
|
describe "#join" do
|
112
112
|
let(:expected_sql) do
|
113
|
-
<<-
|
113
|
+
<<-SQL.gsub(/\s+/, ' ').strip
|
114
114
|
LEFT OUTER JOIN
|
115
115
|
(SELECT model_id AS id,
|
116
116
|
string_agg(\"#{association.table_name}\".\"name\"::text, ' ') AS #{association.columns.first.alias}
|
@@ -119,7 +119,7 @@ describe PgSearch::Configuration::Association do
|
|
119
119
|
ON \"#{association.table_name}\".\"site_id\" = \"#{Site.table_name}\".\"id\"
|
120
120
|
GROUP BY model_id) #{association.subselect_alias}
|
121
121
|
ON #{association.subselect_alias}.id = model_id
|
122
|
-
|
122
|
+
SQL
|
123
123
|
end
|
124
124
|
|
125
125
|
it "returns the correct SQL join" do
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "spec_helper"
|
2
|
+
require "active_support/deprecation"
|
2
3
|
|
3
4
|
describe PgSearch::Features::TSearch do
|
4
5
|
describe "#rank" do
|
@@ -201,6 +202,35 @@ describe PgSearch::Features::TSearch do
|
|
201
202
|
|
202
203
|
expect(feature.highlight.to_sql).to eq(expected_sql)
|
203
204
|
end
|
205
|
+
|
206
|
+
it "passes deprecated options to ts_headline" do
|
207
|
+
query = "query"
|
208
|
+
columns = [
|
209
|
+
PgSearch::Configuration::Column.new(:name, nil, Model)
|
210
|
+
]
|
211
|
+
options = {
|
212
|
+
highlight: {
|
213
|
+
start_sel: '<start class="search">',
|
214
|
+
stop_sel: '<stop>',
|
215
|
+
max_words: 123,
|
216
|
+
min_words: 456,
|
217
|
+
short_word: 4,
|
218
|
+
highlight_all: false,
|
219
|
+
max_fragments: 3,
|
220
|
+
fragment_delimiter: '…'
|
221
|
+
}
|
222
|
+
}
|
223
|
+
|
224
|
+
config = double(:config, :ignore => [])
|
225
|
+
normalizer = PgSearch::Normalizer.new(config)
|
226
|
+
|
227
|
+
feature = described_class.new(query, options, columns, Model, normalizer)
|
228
|
+
|
229
|
+
highlight_sql = ActiveSupport::Deprecation.silence { feature.highlight.to_sql }
|
230
|
+
expected_sql = %{(ts_headline('simple', (coalesce(#{Model.quoted_table_name}."name"::text, '')), (to_tsquery('simple', ''' ' || 'query' || ' ''')), 'StartSel = "<start class=""search"">", StopSel = "<stop>", MaxFragments = 3, MaxWords = 123, MinWords = 456, ShortWord = 4, FragmentDelimiter = "…", HighlightAll = FALSE'))}
|
231
|
+
|
232
|
+
expect(highlight_sql).to eq(expected_sql)
|
233
|
+
end
|
204
234
|
end
|
205
235
|
end
|
206
236
|
end
|
data/spec/lib/pg_search_spec.rb
CHANGED
data/spec/support/database.rb
CHANGED
@@ -42,7 +42,7 @@ def install_extension(name)
|
|
42
42
|
extension = connection.execute "SELECT * FROM pg_catalog.pg_extension WHERE extname = '#{name}';"
|
43
43
|
return unless extension.none?
|
44
44
|
connection.execute "CREATE EXTENSION #{name};"
|
45
|
-
rescue => exception
|
45
|
+
rescue => exception # rubocop:disable Lint/RescueWithoutErrorClass
|
46
46
|
at_exit do
|
47
47
|
puts "-" * 80
|
48
48
|
puts "Please install the #{name} extension"
|
@@ -54,7 +54,7 @@ end
|
|
54
54
|
def install_extension_if_missing(name, query, expected_result)
|
55
55
|
result = ActiveRecord::Base.connection.select_value(query)
|
56
56
|
raise "Unexpected output for #{query}: #{result.inspect}" unless result.downcase == expected_result.downcase
|
57
|
-
rescue
|
57
|
+
rescue # rubocop:disable Lint/RescueWithoutErrorClass
|
58
58
|
install_extension(name)
|
59
59
|
end
|
60
60
|
|
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.1
|
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: 2017-
|
12
|
+
date: 2017-09-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -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.
|
244
|
+
rubygems_version: 2.5.1
|
245
245
|
signing_key:
|
246
246
|
specification_version: 4
|
247
247
|
summary: PgSearch builds Active Record named scopes that take advantage of PostgreSQL's
|