pg_search 2.1.3 → 2.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -6
- data/.travis.yml +12 -3
- data/CHANGELOG.md +121 -116
- data/Gemfile +2 -0
- data/README.md +1 -1
- data/Rakefile +2 -0
- data/lib/pg_search.rb +5 -3
- data/lib/pg_search/configuration.rb +5 -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/document.rb +4 -2
- data/lib/pg_search/features.rb +2 -0
- data/lib/pg_search/features/dmetaphone.rb +2 -0
- data/lib/pg_search/features/feature.rb +3 -1
- data/lib/pg_search/features/trigram.rb +2 -0
- data/lib/pg_search/features/tsearch.rb +2 -0
- data/lib/pg_search/migration/dmetaphone_generator.rb +3 -1
- data/lib/pg_search/migration/generator.rb +2 -0
- data/lib/pg_search/migration/multisearch_generator.rb +2 -1
- data/lib/pg_search/multisearch.rb +3 -3
- data/lib/pg_search/multisearch/rebuilder.rb +4 -2
- data/lib/pg_search/multisearchable.rb +2 -2
- data/lib/pg_search/normalizer.rb +2 -0
- data/lib/pg_search/railtie.rb +2 -0
- data/lib/pg_search/scope_options.rb +8 -6
- data/lib/pg_search/tasks.rb +2 -0
- data/lib/pg_search/version.rb +3 -1
- data/pg_search.gemspec +6 -5
- data/spec/integration/associations_spec.rb +9 -7
- data/spec/integration/pagination_spec.rb +2 -0
- data/spec/integration/pg_search_spec.rb +26 -24
- data/spec/integration/single_table_inheritance_spec.rb +2 -1
- data/spec/lib/pg_search/configuration/association_spec.rb +5 -3
- data/spec/lib/pg_search/configuration/column_spec.rb +2 -0
- data/spec/lib/pg_search/configuration/foreign_column_spec.rb +3 -1
- data/spec/lib/pg_search/features/dmetaphone_spec.rb +2 -0
- data/spec/lib/pg_search/features/trigram_spec.rb +2 -0
- data/spec/lib/pg_search/features/tsearch_spec.rb +6 -4
- data/spec/lib/pg_search/multisearch/rebuilder_spec.rb +2 -0
- data/spec/lib/pg_search/multisearch_spec.rb +2 -0
- data/spec/lib/pg_search/multisearchable_spec.rb +8 -6
- data/spec/lib/pg_search/normalizer_spec.rb +2 -0
- data/spec/lib/pg_search_spec.rb +5 -3
- data/spec/spec_helper.rb +2 -0
- data/spec/support/database.rb +3 -1
- data/spec/support/with_model.rb +2 -0
- metadata +6 -23
- data/.rubocop_todo.yml +0 -153
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -17,7 +17,7 @@ Read the blog post introducing PgSearch at https://content.pivotal.io/blog/pg-se
|
|
17
17
|
|
18
18
|
## REQUIREMENTS
|
19
19
|
|
20
|
-
* Ruby 2.
|
20
|
+
* Ruby 2.3+
|
21
21
|
* ActiveRecord 4.2+
|
22
22
|
* PostgreSQL 9.2+
|
23
23
|
* [PostgreSQL extensions](https://github.com/Casecommons/pg_search/wiki/Installing-PostgreSQL-Extensions) for certain features
|
data/Rakefile
CHANGED
data/lib/pg_search.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_record"
|
2
4
|
require "active_support/concern"
|
3
5
|
require "active_support/core_ext/module/attribute_accessors"
|
@@ -25,7 +27,7 @@ module PgSearch
|
|
25
27
|
options_proc = if options.respond_to?(:call)
|
26
28
|
options
|
27
29
|
elsif options.respond_to?(:merge)
|
28
|
-
->(query) { {:query => query}.merge(options) }
|
30
|
+
->(query) { { :query => query }.merge(options) }
|
29
31
|
else
|
30
32
|
raise ArgumentError, 'pg_search_scope expects a Hash or Proc'
|
31
33
|
end
|
@@ -68,11 +70,11 @@ module PgSearch
|
|
68
70
|
def method_missing(symbol, *args)
|
69
71
|
case symbol
|
70
72
|
when :pg_search_rank
|
71
|
-
raise PgSearchRankNotSelected
|
73
|
+
raise PgSearchRankNotSelected unless respond_to?(:pg_search_rank)
|
72
74
|
|
73
75
|
read_attribute(:pg_search_rank).to_f
|
74
76
|
when :pg_search_highlight
|
75
|
-
raise PgSearchHighlightNotSelected
|
77
|
+
raise PgSearchHighlightNotSelected unless respond_to?(:pg_search_highlight)
|
76
78
|
|
77
79
|
read_attribute(:pg_search_highlight)
|
78
80
|
else
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "pg_search/configuration/association"
|
2
4
|
require "pg_search/configuration/column"
|
3
5
|
require "pg_search/configuration/foreign_column"
|
@@ -17,7 +19,7 @@ module PgSearch
|
|
17
19
|
def alias(*strings)
|
18
20
|
name = Array(strings).compact.join("_")
|
19
21
|
# By default, PostgreSQL limits names to 32 characters, so we hash and limit to 32 characters.
|
20
|
-
"pg_search_#{Digest::SHA2.hexdigest(name)}"
|
22
|
+
"pg_search_#{Digest::SHA2.hexdigest(name)}".first(32)
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
@@ -78,7 +80,7 @@ module PgSearch
|
|
78
80
|
attr_reader :options
|
79
81
|
|
80
82
|
def default_options
|
81
|
-
{:using => :tsearch}
|
83
|
+
{ :using => :tsearch }
|
82
84
|
end
|
83
85
|
|
84
86
|
VALID_KEYS = %w[
|
@@ -87,7 +89,7 @@ module PgSearch
|
|
87
89
|
|
88
90
|
VALID_VALUES = {
|
89
91
|
:ignoring => [:accents]
|
90
|
-
}
|
92
|
+
}.freeze
|
91
93
|
|
92
94
|
def assert_valid_options(options)
|
93
95
|
unless options[:against] || options[:associated_against]
|
data/lib/pg_search/document.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'logger'
|
2
4
|
|
3
5
|
module PgSearch
|
@@ -17,10 +19,10 @@ module PgSearch
|
|
17
19
|
options = if PgSearch.multisearch_options.respond_to?(:call)
|
18
20
|
PgSearch.multisearch_options.call(*args)
|
19
21
|
else
|
20
|
-
{:query => args.first}.merge(PgSearch.multisearch_options)
|
22
|
+
{ :query => args.first }.merge(PgSearch.multisearch_options)
|
21
23
|
end
|
22
24
|
|
23
|
-
{:against => :content}.merge(options)
|
25
|
+
{ :against => :content }.merge(options)
|
24
26
|
}
|
25
27
|
end
|
26
28
|
end
|
data/lib/pg_search/features.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/core_ext/module/delegation"
|
2
4
|
require "active_support/core_ext/hash/keys"
|
3
5
|
|
@@ -23,7 +25,7 @@ module PgSearch
|
|
23
25
|
attr_reader :query, :options, :all_columns, :model, :normalizer
|
24
26
|
|
25
27
|
def document
|
26
|
-
columns.map
|
28
|
+
columns.map(&:to_sql).join(" || ' ' || ")
|
27
29
|
end
|
28
30
|
|
29
31
|
def columns
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'pg_search/migration/generator'
|
2
4
|
|
3
5
|
module PgSearch
|
4
6
|
module Migration
|
5
7
|
class DmetaphoneGenerator < Generator
|
6
8
|
def migration_name
|
7
|
-
'add_pg_search_dmetaphone_support_functions'
|
9
|
+
'add_pg_search_dmetaphone_support_functions'
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "pg_search/multisearch/rebuilder"
|
2
4
|
|
3
5
|
module PgSearch
|
4
6
|
module Multisearch
|
5
7
|
class << self
|
6
|
-
def rebuild(model, clean_up=true)
|
8
|
+
def rebuild(model, clean_up = true)
|
7
9
|
model.transaction do
|
8
10
|
PgSearch::Document.where(:searchable_type => model.base_class.name).delete_all if clean_up
|
9
11
|
Rebuilder.new(model).rebuild
|
@@ -22,5 +24,3 @@ module PgSearch
|
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
25
|
-
|
26
|
-
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PgSearch
|
2
4
|
module Multisearch
|
3
5
|
class Rebuilder
|
4
6
|
def initialize(model, time_source = Time.method(:now))
|
5
|
-
raise ModelNotMultisearchable
|
7
|
+
raise ModelNotMultisearchable, model unless model.respond_to?(:pg_search_multisearchable_options)
|
6
8
|
|
7
9
|
@model = model
|
8
10
|
@time_source = time_source
|
@@ -12,7 +14,7 @@ module PgSearch
|
|
12
14
|
if model.respond_to?(:rebuild_pg_search_documents)
|
13
15
|
model.rebuild_pg_search_documents
|
14
16
|
elsif conditional? || dynamic?
|
15
|
-
model.find_each
|
17
|
+
model.find_each(&:update_pg_search_document)
|
16
18
|
else
|
17
19
|
model.connection.execute(rebuild_sql)
|
18
20
|
end
|
@@ -50,7 +50,7 @@ module PgSearch
|
|
50
50
|
if should_have_document
|
51
51
|
create_or_update_pg_search_document
|
52
52
|
else
|
53
|
-
pg_search_document
|
53
|
+
pg_search_document&.destroy
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -58,7 +58,7 @@ module PgSearch
|
|
58
58
|
if !pg_search_document
|
59
59
|
create_pg_search_document(pg_search_document_attrs)
|
60
60
|
elsif should_update_pg_search_document?
|
61
|
-
pg_search_document.
|
61
|
+
pg_search_document.update(pg_search_document_attrs)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
data/lib/pg_search/normalizer.rb
CHANGED
data/lib/pg_search/railtie.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/core_ext/module/delegation"
|
2
4
|
|
3
5
|
module PgSearch
|
@@ -25,7 +27,7 @@ module PgSearch
|
|
25
27
|
# workaround for https://github.com/Casecommons/pg_search/issues/14
|
26
28
|
module DisableEagerLoading
|
27
29
|
def eager_loading?
|
28
|
-
|
30
|
+
false
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
@@ -38,7 +40,7 @@ module PgSearch
|
|
38
40
|
end
|
39
41
|
|
40
42
|
def tsearch
|
41
|
-
raise TypeError
|
43
|
+
raise TypeError, "You need to instantiate this module with []"
|
42
44
|
end
|
43
45
|
|
44
46
|
def with_pg_search_highlight
|
@@ -140,13 +142,13 @@ module PgSearch
|
|
140
142
|
:dmetaphone => Features::DMetaphone,
|
141
143
|
:tsearch => Features::TSearch,
|
142
144
|
:trigram => Features::Trigram
|
143
|
-
}
|
145
|
+
}.freeze
|
144
146
|
|
145
|
-
def feature_for(feature_name)
|
147
|
+
def feature_for(feature_name)
|
146
148
|
feature_name = feature_name.to_sym
|
147
149
|
feature_class = FEATURE_CLASSES[feature_name]
|
148
150
|
|
149
|
-
raise ArgumentError
|
151
|
+
raise ArgumentError, "Unknown feature: #{feature_name}" unless feature_class
|
150
152
|
|
151
153
|
normalizer = Normalizer.new(config)
|
152
154
|
|
@@ -161,7 +163,7 @@ module PgSearch
|
|
161
163
|
|
162
164
|
def rank
|
163
165
|
(config.ranking_sql || ":tsearch").gsub(/:(\w*)/) do
|
164
|
-
feature_for(
|
166
|
+
feature_for(Regexp.last_match(1)).rank.to_sql
|
165
167
|
end
|
166
168
|
end
|
167
169
|
|
data/lib/pg_search/tasks.rb
CHANGED
data/lib/pg_search/version.rb
CHANGED
data/pg_search.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
2
4
|
require 'pg_search/version'
|
3
5
|
|
@@ -8,8 +10,8 @@ Gem::Specification.new do |s|
|
|
8
10
|
s.authors = ['Grant Hutchins', 'Case Commons, LLC']
|
9
11
|
s.email = %w[gems@nertzy.com casecommons-dev@googlegroups.com]
|
10
12
|
s.homepage = 'https://github.com/Casecommons/pg_search'
|
11
|
-
s.summary =
|
12
|
-
s.description =
|
13
|
+
s.summary = "PgSearch builds Active Record named scopes that take advantage of PostgreSQL's full text search"
|
14
|
+
s.description = "PgSearch builds Active Record named scopes that take advantage of PostgreSQL's full text search"
|
13
15
|
s.licenses = ['MIT']
|
14
16
|
|
15
17
|
s.files = `git ls-files`.split("\n")
|
@@ -18,15 +20,14 @@ Gem::Specification.new do |s|
|
|
18
20
|
|
19
21
|
s.add_dependency 'activerecord', '>= 4.2'
|
20
22
|
s.add_dependency 'activesupport', '>= 4.2'
|
21
|
-
s.add_dependency 'arel', '>= 6'
|
22
23
|
|
23
24
|
s.add_development_dependency 'codeclimate-test-reporter'
|
24
25
|
s.add_development_dependency 'pry'
|
25
26
|
s.add_development_dependency 'rake'
|
26
27
|
s.add_development_dependency 'rspec', '>= 3.3'
|
27
|
-
s.add_development_dependency 'rubocop', '>= 0.
|
28
|
+
s.add_development_dependency 'rubocop', '>= 0.63.0'
|
28
29
|
s.add_development_dependency 'simplecov'
|
29
30
|
s.add_development_dependency 'with_model', '>= 1.2'
|
30
31
|
|
31
|
-
s.required_ruby_version = '>= 2.
|
32
|
+
s.required_ruby_version = '>= 2.3'
|
32
33
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
describe PgSearch do
|
@@ -19,7 +21,7 @@ describe PgSearch do
|
|
19
21
|
include PgSearch
|
20
22
|
belongs_to :another_model, :class_name => 'AssociatedModel'
|
21
23
|
|
22
|
-
pg_search_scope :with_another, :associated_against => {:another_model => :title}
|
24
|
+
pg_search_scope :with_another, :associated_against => { :another_model => :title }
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
@@ -56,7 +58,7 @@ describe PgSearch do
|
|
56
58
|
include PgSearch
|
57
59
|
belongs_to :another_model, :class_name => 'AssociatedModel'
|
58
60
|
|
59
|
-
pg_search_scope :with_associated, :against => :title, :associated_against => {:another_model => :title}
|
61
|
+
pg_search_scope :with_associated, :against => :title, :associated_against => { :another_model => :title }
|
60
62
|
end
|
61
63
|
end
|
62
64
|
|
@@ -92,7 +94,7 @@ describe PgSearch do
|
|
92
94
|
include PgSearch
|
93
95
|
has_many :other_models, :class_name => 'AssociatedModelWithHasMany', :foreign_key => 'ModelWithHasMany_id'
|
94
96
|
|
95
|
-
pg_search_scope :with_associated, :against => [:title], :associated_against => {:other_models => :title}
|
97
|
+
pg_search_scope :with_associated, :against => [:title], :associated_against => { :other_models => :title }
|
96
98
|
end
|
97
99
|
end
|
98
100
|
|
@@ -172,7 +174,7 @@ describe PgSearch do
|
|
172
174
|
|
173
175
|
pg_search_scope :with_associated,
|
174
176
|
:against => :title,
|
175
|
-
:associated_against => {:models_of_first_type => :title, :model_of_second_type => :title}
|
177
|
+
:associated_against => { :models_of_first_type => :title, :model_of_second_type => :title }
|
176
178
|
end
|
177
179
|
end
|
178
180
|
|
@@ -231,7 +233,7 @@ describe PgSearch do
|
|
231
233
|
:foreign_key => 'ModelWithDoubleAssociation_again_id'
|
232
234
|
|
233
235
|
pg_search_scope :with_associated, :against => :title,
|
234
|
-
:associated_against => {:things => :title, :thingamabobs => :title}
|
236
|
+
:associated_against => { :things => :title, :thingamabobs => :title }
|
235
237
|
end
|
236
238
|
end
|
237
239
|
|
@@ -283,7 +285,7 @@ describe PgSearch do
|
|
283
285
|
include PgSearch
|
284
286
|
belongs_to :another_model, :class_name => 'AssociatedModel'
|
285
287
|
|
286
|
-
pg_search_scope :with_associated, :associated_against => {:another_model => %i[title author]}
|
288
|
+
pg_search_scope :with_associated, :associated_against => { :another_model => %i[title author] }
|
287
289
|
end
|
288
290
|
end
|
289
291
|
|
@@ -336,7 +338,7 @@ describe PgSearch do
|
|
336
338
|
include PgSearch
|
337
339
|
belongs_to :another_model, class_name: 'AssociatedModel'
|
338
340
|
|
339
|
-
pg_search_scope :with_associated, associated_against: {another_model: :number}
|
341
|
+
pg_search_scope :with_associated, associated_against: { another_model: :number }
|
340
342
|
end
|
341
343
|
end
|
342
344
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
describe "an Active Record model which includes PgSearch" do
|
@@ -65,7 +67,7 @@ describe "an Active Record model which includes PgSearch" do
|
|
65
67
|
context "dynamically" do
|
66
68
|
it "raises an exception when invoked" do
|
67
69
|
ModelWithPgSearch.pg_search_scope :with_unknown_option,
|
68
|
-
->(*) { {:against => :content, :foo => :bar} }
|
70
|
+
->(*) { { :against => :content, :foo => :bar } }
|
69
71
|
|
70
72
|
expect {
|
71
73
|
ModelWithPgSearch.with_unknown_option("foo")
|
@@ -88,7 +90,7 @@ describe "an Active Record model which includes PgSearch" do
|
|
88
90
|
context "dynamically" do
|
89
91
|
it "raises an exception when invoked" do
|
90
92
|
ModelWithPgSearch.pg_search_scope :with_unknown_using,
|
91
|
-
->(*) { {:against => :content, :using => :foo} }
|
93
|
+
->(*) { { :against => :content, :using => :foo } }
|
92
94
|
|
93
95
|
expect {
|
94
96
|
ModelWithPgSearch.with_unknown_using("foo")
|
@@ -111,7 +113,7 @@ describe "an Active Record model which includes PgSearch" do
|
|
111
113
|
context "dynamically" do
|
112
114
|
it "raises an exception when invoked" do
|
113
115
|
ModelWithPgSearch.pg_search_scope :with_unknown_ignoring,
|
114
|
-
->(*) { {:against => :content, :ignoring => :foo} }
|
116
|
+
->(*) { { :against => :content, :ignoring => :foo } }
|
115
117
|
|
116
118
|
expect {
|
117
119
|
ModelWithPgSearch.with_unknown_ignoring("foo")
|
@@ -130,7 +132,7 @@ describe "an Active Record model which includes PgSearch" do
|
|
130
132
|
|
131
133
|
context "dynamically" do
|
132
134
|
it "raises an exception when invoked" do
|
133
|
-
ModelWithPgSearch.pg_search_scope :with_unknown_ignoring, ->(*){ {} }
|
135
|
+
ModelWithPgSearch.pg_search_scope :with_unknown_ignoring, ->(*) { {} }
|
134
136
|
|
135
137
|
expect {
|
136
138
|
ModelWithPgSearch.with_unknown_ignoring("foo")
|
@@ -222,7 +224,7 @@ describe "an Active Record model which includes PgSearch" do
|
|
222
224
|
has_many :houses
|
223
225
|
pg_search_scope :named, against: [:name]
|
224
226
|
scope :with_house_in_city, lambda { |city|
|
225
|
-
joins(:houses).where(House.table_name.to_sym => {city: city})
|
227
|
+
joins(:houses).where(House.table_name.to_sym => { city: city })
|
226
228
|
}
|
227
229
|
scope :house_search_city, lambda { |query|
|
228
230
|
joins(:houses).merge(House.search_city(query))
|
@@ -342,7 +344,7 @@ describe "an Active Record model which includes PgSearch" do
|
|
342
344
|
twice = ModelWithPgSearch.create!(:content => 'foo foo')
|
343
345
|
|
344
346
|
records = ModelWithPgSearch.search_content('foo')
|
345
|
-
|
347
|
+
.where("#{PgSearch::Configuration.alias(ModelWithPgSearch.table_name)}.rank > 0.07")
|
346
348
|
|
347
349
|
expect(records).to eq [twice]
|
348
350
|
end
|
@@ -537,8 +539,8 @@ describe "an Active Record model which includes PgSearch" do
|
|
537
539
|
|
538
540
|
context "when a threshold is specified" do
|
539
541
|
before do
|
540
|
-
ModelWithPgSearch.pg_search_scope :with_strict_trigrams, :against => %i[title content], :using => {trigram: {threshold: 0.5}}
|
541
|
-
ModelWithPgSearch.pg_search_scope :with_permissive_trigrams, :against => %i[title content], :using => {trigram: {threshold: 0.1}}
|
542
|
+
ModelWithPgSearch.pg_search_scope :with_strict_trigrams, :against => %i[title content], :using => { trigram: { threshold: 0.5 } }
|
543
|
+
ModelWithPgSearch.pg_search_scope :with_permissive_trigrams, :against => %i[title content], :using => { trigram: { threshold: 0.1 } }
|
542
544
|
end
|
543
545
|
|
544
546
|
it "uses the threshold in the trigram expression" do
|
@@ -565,7 +567,7 @@ describe "an Active Record model which includes PgSearch" do
|
|
565
567
|
ModelWithPgSearch.pg_search_scope :search_title_with_prefixes,
|
566
568
|
:against => :title,
|
567
569
|
:using => {
|
568
|
-
:tsearch => {:prefix => true}
|
570
|
+
:tsearch => { :prefix => true }
|
569
571
|
}
|
570
572
|
end
|
571
573
|
|
@@ -594,7 +596,7 @@ describe "an Active Record model which includes PgSearch" do
|
|
594
596
|
ModelWithPgSearch.pg_search_scope :search_content_with_english,
|
595
597
|
:against => :content,
|
596
598
|
:using => {
|
597
|
-
:tsearch => {:dictionary => :english}
|
599
|
+
:tsearch => { :dictionary => :english }
|
598
600
|
}
|
599
601
|
end
|
600
602
|
|
@@ -682,7 +684,7 @@ describe "an Active Record model which includes PgSearch" do
|
|
682
684
|
ModelWithPgSearch.pg_search_scope :search_content_with_normalization,
|
683
685
|
:against => :content,
|
684
686
|
:using => {
|
685
|
-
:tsearch => {:normalization => 2}
|
687
|
+
:tsearch => { :normalization => 2 }
|
686
688
|
}
|
687
689
|
end
|
688
690
|
|
@@ -729,7 +731,7 @@ describe "an Active Record model which includes PgSearch" do
|
|
729
731
|
context "against columns ranked with a hash" do
|
730
732
|
before do
|
731
733
|
ModelWithPgSearch.pg_search_scope :search_weighted_by_hash,
|
732
|
-
:against => {:content => 'B', :title => 'A'}
|
734
|
+
:against => { :content => 'B', :title => 'A' }
|
733
735
|
end
|
734
736
|
|
735
737
|
it "returns results sorted by weighted rank" do
|
@@ -763,7 +765,7 @@ describe "an Active Record model which includes PgSearch" do
|
|
763
765
|
ModelWithPgSearch.pg_search_scope :search_title_with_any_word,
|
764
766
|
:against => :title,
|
765
767
|
:using => {
|
766
|
-
:tsearch => {:any_word => true}
|
768
|
+
:tsearch => { :any_word => true }
|
767
769
|
}
|
768
770
|
|
769
771
|
ModelWithPgSearch.pg_search_scope :search_title_with_all_words,
|
@@ -788,7 +790,7 @@ describe "an Active Record model which includes PgSearch" do
|
|
788
790
|
ModelWithPgSearch.pg_search_scope :search_with_negation,
|
789
791
|
:against => :title,
|
790
792
|
:using => {
|
791
|
-
:tsearch => {:negation => true}
|
793
|
+
:tsearch => { :negation => true }
|
792
794
|
}
|
793
795
|
end
|
794
796
|
|
@@ -880,7 +882,7 @@ describe "an Active Record model which includes PgSearch" do
|
|
880
882
|
ModelWithPgSearch.pg_search_scope :with_tsearch,
|
881
883
|
:against => :title,
|
882
884
|
:using => [
|
883
|
-
[:tsearch, {:dictionary => 'english'}]
|
885
|
+
[:tsearch, { :dictionary => 'english' }]
|
884
886
|
]
|
885
887
|
|
886
888
|
ModelWithPgSearch.pg_search_scope :with_trigram,
|
@@ -895,7 +897,7 @@ describe "an Active Record model which includes PgSearch" do
|
|
895
897
|
ModelWithPgSearch.pg_search_scope :with_tsearch_and_trigram,
|
896
898
|
:against => :title,
|
897
899
|
:using => [
|
898
|
-
[:tsearch, {:dictionary => 'english'}],
|
900
|
+
[:tsearch, { :dictionary => 'english' }],
|
899
901
|
:trigram
|
900
902
|
]
|
901
903
|
|
@@ -903,7 +905,7 @@ describe "an Active Record model which includes PgSearch" do
|
|
903
905
|
:against => %i[content title],
|
904
906
|
:ignoring => :accents,
|
905
907
|
:using => {
|
906
|
-
:tsearch => {:dictionary => 'english'},
|
908
|
+
:tsearch => { :dictionary => 'english' },
|
907
909
|
:dmetaphone => {},
|
908
910
|
:trigram => {}
|
909
911
|
}
|
@@ -949,8 +951,8 @@ describe "an Active Record model which includes PgSearch" do
|
|
949
951
|
|
950
952
|
context "with feature-specific configuration" do
|
951
953
|
before do
|
952
|
-
@tsearch_config = tsearch_config = {:dictionary => 'english'}
|
953
|
-
@trigram_config = trigram_config = {:foo => 'bar'}
|
954
|
+
@tsearch_config = tsearch_config = { :dictionary => 'english' }
|
955
|
+
@trigram_config = trigram_config = { :foo => 'bar' }
|
954
956
|
|
955
957
|
ModelWithPgSearch.pg_search_scope :with_tsearch_and_trigram_using_hash,
|
956
958
|
:against => :title,
|
@@ -1011,7 +1013,7 @@ describe "an Active Record model which includes PgSearch" do
|
|
1011
1013
|
unexpected.comments.create(body: 'commentwo')
|
1012
1014
|
|
1013
1015
|
Post.pg_search_scope :search_by_content_with_tsvector,
|
1014
|
-
:associated_against => {comments: [:body]},
|
1016
|
+
:associated_against => { comments: [:body] },
|
1015
1017
|
:using => {
|
1016
1018
|
:tsearch => {
|
1017
1019
|
:tsvector_column => 'content_tsvector',
|
@@ -1171,8 +1173,8 @@ describe "an Active Record model which includes PgSearch" do
|
|
1171
1173
|
|
1172
1174
|
multiplied_result =
|
1173
1175
|
ModelWithPgSearch.search_content_with_importance_as_rank_multiplier("foo")
|
1174
|
-
|
1175
|
-
|
1176
|
+
.with_pg_search_rank
|
1177
|
+
.first
|
1176
1178
|
|
1177
1179
|
multiplied_rank = multiplied_result.pg_search_rank
|
1178
1180
|
|
@@ -1280,8 +1282,8 @@ describe "an Active Record model which includes PgSearch" do
|
|
1280
1282
|
ModelWithPgSearch.pg_search_scope :search_content_ranked_by_dmetaphone,
|
1281
1283
|
:against => :content,
|
1282
1284
|
:using => {
|
1283
|
-
:tsearch => {:any_word => true, :prefix => true},
|
1284
|
-
:dmetaphone => {:any_word => true, :prefix => true, :sort_only => true}
|
1285
|
+
:tsearch => { :any_word => true, :prefix => true },
|
1286
|
+
:dmetaphone => { :any_word => true, :prefix => true, :sort_only => true }
|
1285
1287
|
},
|
1286
1288
|
:ranked_by => ":tsearch + (0.5 * :dmetaphone)"
|
1287
1289
|
|