pg_search 2.1.2 → 2.2.0
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/.rubocop.yml +11 -7
- data/.travis.yml +33 -42
- data/CHANGELOG.md +140 -112
- data/CONTRIBUTING.md +5 -3
- data/Gemfile +6 -4
- data/LICENSE +1 -1
- data/README.md +221 -159
- data/Rakefile +3 -5
- 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 +8 -4
- data/lib/pg_search/document.rb +5 -3
- data/lib/pg_search/features/dmetaphone.rb +3 -1
- 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 +4 -1
- 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/create_pg_search_documents.rb.erb +1 -1
- data/lib/pg_search/multisearch/rebuilder.rb +7 -3
- data/lib/pg_search/multisearch.rb +4 -4
- 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 +21 -41
- data/lib/pg_search/tasks.rb +3 -0
- data/lib/pg_search/version.rb +3 -1
- data/lib/pg_search.rb +10 -5
- data/pg_search.gemspec +8 -7
- data/spec/integration/associations_spec.rb +103 -101
- data/spec/integration/pagination_spec.rb +9 -7
- data/spec/integration/pg_search_spec.rb +266 -255
- data/spec/integration/single_table_inheritance_spec.rb +16 -15
- data/spec/lib/pg_search/configuration/association_spec.rb +7 -5
- data/spec/lib/pg_search/configuration/column_spec.rb +2 -0
- data/spec/lib/pg_search/configuration/foreign_column_spec.rb +5 -3
- data/spec/lib/pg_search/features/dmetaphone_spec.rb +6 -4
- data/spec/lib/pg_search/features/trigram_spec.rb +39 -12
- data/spec/lib/pg_search/features/tsearch_spec.rb +23 -21
- data/spec/lib/pg_search/multisearch/rebuilder_spec.rb +32 -11
- data/spec/lib/pg_search/multisearch_spec.rb +9 -7
- data/spec/lib/pg_search/multisearchable_spec.rb +68 -27
- data/spec/lib/pg_search/normalizer_spec.rb +7 -5
- data/spec/lib/pg_search_spec.rb +33 -31
- data/spec/spec_helper.rb +3 -1
- data/spec/support/database.rb +16 -20
- data/spec/support/with_model.rb +2 -0
- metadata +13 -30
- data/.rubocop_todo.yml +0 -163
- data/Guardfile +0 -6
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler'
|
2
4
|
Bundler::GemHelper.install_tasks
|
3
5
|
|
@@ -9,8 +11,4 @@ RuboCop::RakeTask.new do |t|
|
|
9
11
|
t.options = %w[--display-cop-names]
|
10
12
|
end
|
11
13
|
|
12
|
-
task :
|
13
|
-
sh 'bin/codeclimate-test-reporter' if ENV['CODECLIMATE_REPO_TOKEN']
|
14
|
-
end
|
15
|
-
|
16
|
-
task :default => %w[spec codeclimate rubocop]
|
14
|
+
task default: %w[spec rubocop]
|
@@ -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
|
|
@@ -27,6 +29,7 @@ module PgSearch
|
|
27
29
|
|
28
30
|
def regular_columns
|
29
31
|
return [] unless options[:against]
|
32
|
+
|
30
33
|
Array(options[:against]).map do |column_name, weight|
|
31
34
|
Column.new(column_name, weight, model)
|
32
35
|
end
|
@@ -34,6 +37,7 @@ module PgSearch
|
|
34
37
|
|
35
38
|
def associations
|
36
39
|
return [] unless options[:associated_against]
|
40
|
+
|
37
41
|
options[:associated_against].map do |association, column_names|
|
38
42
|
Association.new(model, association, column_names)
|
39
43
|
end.flatten
|
@@ -76,7 +80,7 @@ module PgSearch
|
|
76
80
|
attr_reader :options
|
77
81
|
|
78
82
|
def default_options
|
79
|
-
{:
|
83
|
+
{ using: :tsearch }
|
80
84
|
end
|
81
85
|
|
82
86
|
VALID_KEYS = %w[
|
@@ -84,8 +88,8 @@ module PgSearch
|
|
84
88
|
].map(&:to_sym)
|
85
89
|
|
86
90
|
VALID_VALUES = {
|
87
|
-
:
|
88
|
-
}
|
91
|
+
ignoring: [:accents]
|
92
|
+
}.freeze
|
89
93
|
|
90
94
|
def assert_valid_options(options)
|
91
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
|
@@ -5,7 +7,7 @@ module PgSearch
|
|
5
7
|
include PgSearch
|
6
8
|
|
7
9
|
self.table_name = 'pg_search_documents'
|
8
|
-
belongs_to :searchable, :
|
10
|
+
belongs_to :searchable, polymorphic: true
|
9
11
|
|
10
12
|
# The logger might not have loaded yet.
|
11
13
|
# https://github.com/Casecommons/pg_search/issues/26
|
@@ -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
|
-
{:
|
22
|
+
{ query: args.first }.merge(PgSearch.multisearch_options)
|
21
23
|
end
|
22
24
|
|
23
|
-
{:
|
25
|
+
{ against: :content }.merge(options)
|
24
26
|
}
|
25
27
|
end
|
26
28
|
end
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PgSearch
|
2
4
|
module Features
|
3
5
|
class DMetaphone
|
4
6
|
def initialize(query, options, columns, model, normalizer)
|
5
7
|
dmetaphone_normalizer = Normalizer.new(normalizer)
|
6
|
-
options = (options || {}).merge(:
|
8
|
+
options = (options || {}).merge(dictionary: 'simple')
|
7
9
|
@tsearch = TSearch.new(query, options, columns, model, dmetaphone_normalizer)
|
8
10
|
end
|
9
11
|
|
@@ -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
|
|
@@ -8,7 +10,7 @@ module PgSearch
|
|
8
10
|
%i[only sort_only]
|
9
11
|
end
|
10
12
|
|
11
|
-
delegate :connection, :quoted_table_name, :
|
13
|
+
delegate :connection, :quoted_table_name, to: :'@model'
|
12
14
|
|
13
15
|
def initialize(query, options, all_columns, model, normalizer)
|
14
16
|
@query = query
|
@@ -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,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PgSearch
|
2
4
|
module Features
|
3
5
|
class Trigram < Feature
|
4
6
|
def self.valid_options
|
5
|
-
super + [
|
7
|
+
super + %i[threshold word_similarity]
|
6
8
|
end
|
7
9
|
|
8
10
|
def conditions
|
@@ -12,7 +14,11 @@ module PgSearch
|
|
12
14
|
)
|
13
15
|
else
|
14
16
|
Arel::Nodes::Grouping.new(
|
15
|
-
Arel::Nodes::InfixOperation.new(
|
17
|
+
Arel::Nodes::InfixOperation.new(
|
18
|
+
infix_operator,
|
19
|
+
normalized_query,
|
20
|
+
normalized_document
|
21
|
+
)
|
16
22
|
)
|
17
23
|
end
|
18
24
|
end
|
@@ -23,12 +29,32 @@ module PgSearch
|
|
23
29
|
|
24
30
|
private
|
25
31
|
|
32
|
+
def word_similarity?
|
33
|
+
options[:word_similarity]
|
34
|
+
end
|
35
|
+
|
36
|
+
def similarity_function
|
37
|
+
if word_similarity?
|
38
|
+
'word_similarity'
|
39
|
+
else
|
40
|
+
'similarity'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def infix_operator
|
45
|
+
if word_similarity?
|
46
|
+
'<%'
|
47
|
+
else
|
48
|
+
'%'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
26
52
|
def similarity
|
27
53
|
Arel::Nodes::NamedFunction.new(
|
28
|
-
|
54
|
+
similarity_function,
|
29
55
|
[
|
30
|
-
|
31
|
-
|
56
|
+
normalized_query,
|
57
|
+
normalized_document
|
32
58
|
]
|
33
59
|
)
|
34
60
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/core_ext/module/delegation"
|
2
4
|
require 'active_support/deprecation'
|
3
5
|
|
@@ -93,7 +95,7 @@ module PgSearch
|
|
93
95
|
end
|
94
96
|
end
|
95
97
|
|
96
|
-
DISALLOWED_TSQUERY_CHARACTERS = /['
|
98
|
+
DISALLOWED_TSQUERY_CHARACTERS = /['?\\:‘’]/.freeze
|
97
99
|
|
98
100
|
def tsquery_for_term(unsanitized_term) # rubocop:disable Metrics/AbcSize
|
99
101
|
if options[:negation] && unsanitized_term.start_with?("!")
|
@@ -128,6 +130,7 @@ module PgSearch
|
|
128
130
|
|
129
131
|
def tsquery
|
130
132
|
return "''" if query.blank?
|
133
|
+
|
131
134
|
query_terms = query.split(" ").compact
|
132
135
|
tsquery_terms = query_terms.map { |term| tsquery_for_term(term) }
|
133
136
|
tsquery_terms.join(options[:any_word] ? ' || ' : ' && ')
|
data/lib/pg_search/features.rb
CHANGED
@@ -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,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_record'
|
2
4
|
require 'rails/generators/base'
|
3
5
|
|
@@ -8,7 +10,7 @@ module PgSearch
|
|
8
10
|
|
9
11
|
def self.inherited(subclass)
|
10
12
|
super
|
11
|
-
subclass.source_root File.expand_path('
|
13
|
+
subclass.source_root File.expand_path('templates', __dir__)
|
12
14
|
end
|
13
15
|
|
14
16
|
def create_migration
|
@@ -20,7 +22,7 @@ module PgSearch
|
|
20
22
|
private
|
21
23
|
|
22
24
|
def read_sql_file(filename)
|
23
|
-
sql_directory = File.expand_path('
|
25
|
+
sql_directory = File.expand_path('../../../sql', __dir__)
|
24
26
|
source_path = File.join(sql_directory, "#{filename}.sql")
|
25
27
|
File.read(source_path).strip
|
26
28
|
end
|
@@ -3,7 +3,7 @@ class CreatePgSearchDocuments < ActiveRecord::Migration<%= migration_version %>
|
|
3
3
|
say_with_time("Creating table for pg_search multisearch") do
|
4
4
|
create_table :pg_search_documents do |t|
|
5
5
|
t.text :content
|
6
|
-
t.belongs_to :searchable, :
|
6
|
+
t.belongs_to :searchable, polymorphic: true, index: true
|
7
7
|
t.timestamps null: false
|
8
8
|
end
|
9
9
|
end
|
@@ -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
|
@@ -74,7 +76,9 @@ module PgSearch
|
|
74
76
|
end
|
75
77
|
|
76
78
|
def content_expressions
|
77
|
-
columns.map
|
79
|
+
columns.map do |column|
|
80
|
+
%{coalesce(:model_table.#{connection.quote_column_name(column)}::text, '')}
|
81
|
+
end.join(" || ' ' || ")
|
78
82
|
end
|
79
83
|
|
80
84
|
def columns
|
@@ -1,11 +1,13 @@
|
|
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
|
-
PgSearch::Document.where(:
|
10
|
+
PgSearch::Document.where(searchable_type: model.base_class.name).delete_all if clean_up
|
9
11
|
Rebuilder.new(model).rebuild
|
10
12
|
end
|
11
13
|
end
|
@@ -22,5 +24,3 @@ module PgSearch
|
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
25
|
-
|
26
|
-
|
@@ -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
|
@@ -5,12 +7,12 @@ module PgSearch
|
|
5
7
|
def self.included(mod)
|
6
8
|
mod.class_eval do
|
7
9
|
has_one :pg_search_document,
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
as: :searchable,
|
11
|
+
class_name: "PgSearch::Document",
|
12
|
+
dependent: :delete
|
11
13
|
|
12
14
|
after_save :update_pg_search_document,
|
13
|
-
|
15
|
+
if: -> { PgSearch.multisearch_enabled? }
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
@@ -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
|
@@ -46,7 +50,7 @@ module PgSearch
|
|
46
50
|
if should_have_document
|
47
51
|
create_or_update_pg_search_document
|
48
52
|
else
|
49
|
-
pg_search_document
|
53
|
+
pg_search_document&.destroy
|
50
54
|
end
|
51
55
|
end
|
52
56
|
|
@@ -54,7 +58,7 @@ module PgSearch
|
|
54
58
|
if !pg_search_document
|
55
59
|
create_pg_search_document(pg_search_document_attrs)
|
56
60
|
elsif should_update_pg_search_document?
|
57
|
-
pg_search_document.
|
61
|
+
pg_search_document.update(pg_search_document_attrs)
|
58
62
|
end
|
59
63
|
end
|
60
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
|
@@ -17,18 +19,10 @@ module PgSearch
|
|
17
19
|
scope
|
18
20
|
.joins(rank_join(rank_table_alias))
|
19
21
|
.order(Arel.sql("#{rank_table_alias}.rank DESC, #{order_within_rank}"))
|
20
|
-
.extend(DisableEagerLoading)
|
21
22
|
.extend(WithPgSearchRank)
|
22
23
|
.extend(WithPgSearchHighlight[feature_for(:tsearch)])
|
23
24
|
end
|
24
25
|
|
25
|
-
# workaround for https://github.com/Casecommons/pg_search/issues/14
|
26
|
-
module DisableEagerLoading
|
27
|
-
def eager_loading?
|
28
|
-
return false
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
26
|
module WithPgSearchHighlight
|
33
27
|
def self.[](tsearch)
|
34
28
|
Module.new do
|
@@ -38,7 +32,7 @@ module PgSearch
|
|
38
32
|
end
|
39
33
|
|
40
34
|
def tsearch
|
41
|
-
raise TypeError
|
35
|
+
raise TypeError, "You need to instantiate this module with []"
|
42
36
|
end
|
43
37
|
|
44
38
|
def with_pg_search_highlight
|
@@ -67,7 +61,7 @@ module PgSearch
|
|
67
61
|
def pg_search_rank_table_alias(include_counter = false)
|
68
62
|
components = [arel_table.name]
|
69
63
|
if include_counter
|
70
|
-
count =
|
64
|
+
count = increment_counter
|
71
65
|
components << count if count > 0
|
72
66
|
end
|
73
67
|
|
@@ -76,22 +70,16 @@ module PgSearch
|
|
76
70
|
|
77
71
|
private
|
78
72
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
@
|
83
|
-
end
|
84
|
-
|
85
|
-
def pg_search_scope_application_count_plus_plus
|
86
|
-
count = pg_search_scope_application_count
|
87
|
-
self.pg_search_scope_application_count = pg_search_scope_application_count + 1
|
88
|
-
count
|
73
|
+
def increment_counter
|
74
|
+
@counter ||= 0
|
75
|
+
ensure
|
76
|
+
@counter += 1
|
89
77
|
end
|
90
78
|
end
|
91
79
|
|
92
80
|
private
|
93
81
|
|
94
|
-
delegate :connection, :quoted_table_name, :
|
82
|
+
delegate :connection, :quoted_table_name, to: :model
|
95
83
|
|
96
84
|
def subquery
|
97
85
|
model
|
@@ -105,19 +93,10 @@ module PgSearch
|
|
105
93
|
end
|
106
94
|
|
107
95
|
def conditions
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
conditions.map! do |feature_name, _feature_options|
|
113
|
-
feature_for(feature_name).conditions
|
114
|
-
end
|
115
|
-
|
116
|
-
conditions = conditions.inject do |accumulator, expression|
|
117
|
-
Arel::Nodes::Or.new(accumulator, expression)
|
118
|
-
end
|
119
|
-
|
120
|
-
conditions.to_sql
|
96
|
+
config.features
|
97
|
+
.reject { |_feature_name, feature_options| feature_options && feature_options[:sort_only] }
|
98
|
+
.map { |feature_name, _feature_options| feature_for(feature_name).conditions }
|
99
|
+
.inject { |accumulator, expression| Arel::Nodes::Or.new(accumulator, expression) }
|
121
100
|
end
|
122
101
|
|
123
102
|
def order_within_rank
|
@@ -137,16 +116,16 @@ module PgSearch
|
|
137
116
|
end
|
138
117
|
|
139
118
|
FEATURE_CLASSES = {
|
140
|
-
:
|
141
|
-
:
|
142
|
-
:
|
143
|
-
}
|
119
|
+
dmetaphone: Features::DMetaphone,
|
120
|
+
tsearch: Features::TSearch,
|
121
|
+
trigram: Features::Trigram
|
122
|
+
}.freeze
|
144
123
|
|
145
|
-
def feature_for(feature_name)
|
124
|
+
def feature_for(feature_name)
|
146
125
|
feature_name = feature_name.to_sym
|
147
126
|
feature_class = FEATURE_CLASSES[feature_name]
|
148
127
|
|
149
|
-
raise ArgumentError
|
128
|
+
raise ArgumentError, "Unknown feature: #{feature_name}" unless feature_class
|
150
129
|
|
151
130
|
normalizer = Normalizer.new(config)
|
152
131
|
|
@@ -161,7 +140,7 @@ module PgSearch
|
|
161
140
|
|
162
141
|
def rank
|
163
142
|
(config.ranking_sql || ":tsearch").gsub(/:(\w*)/) do
|
164
|
-
feature_for(
|
143
|
+
feature_for(Regexp.last_match(1)).rank.to_sql
|
165
144
|
end
|
166
145
|
end
|
167
146
|
|
@@ -171,6 +150,7 @@ module PgSearch
|
|
171
150
|
|
172
151
|
def include_table_aliasing_for_rank(scope)
|
173
152
|
return scope if scope.included_modules.include?(PgSearchRankTableAliasing)
|
153
|
+
|
174
154
|
scope.all.spawn.tap do |new_scope|
|
175
155
|
new_scope.class_eval { include PgSearchRankTableAliasing }
|
176
156
|
end
|
data/lib/pg_search/tasks.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rake'
|
2
4
|
require 'pg_search'
|
3
5
|
|
@@ -6,6 +8,7 @@ namespace :pg_search do
|
|
6
8
|
desc "Rebuild PgSearch multisearch records for a given model"
|
7
9
|
task :rebuild, %i[model schema] => :environment do |_task, args|
|
8
10
|
raise ArgumentError, <<-MESSAGE.strip_heredoc unless args.model
|
11
|
+
|
9
12
|
You must pass a model as an argument.
|
10
13
|
Example: rake pg_search:multisearch:rebuild[BlogPost]
|
11
14
|
MESSAGE
|
data/lib/pg_search/version.rb
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"
|
@@ -24,9 +26,10 @@ module PgSearch
|
|
24
26
|
def pg_search_scope(name, options)
|
25
27
|
options_proc = if options.respond_to?(:call)
|
26
28
|
options
|
29
|
+
elsif options.respond_to?(:merge)
|
30
|
+
->(query) { { query: query }.merge(options) }
|
27
31
|
else
|
28
|
-
raise ArgumentError,
|
29
|
-
->(query) { {:query => query}.merge(options) }
|
32
|
+
raise ArgumentError, 'pg_search_scope expects a Hash or Proc'
|
30
33
|
end
|
31
34
|
|
32
35
|
define_singleton_method(name) do |*args|
|
@@ -37,7 +40,7 @@ module PgSearch
|
|
37
40
|
end
|
38
41
|
|
39
42
|
def multisearchable(options = {})
|
40
|
-
include PgSearch::Multisearchable
|
43
|
+
include PgSearch::Multisearchable
|
41
44
|
class_attribute :pg_search_multisearchable_options
|
42
45
|
self.pg_search_multisearchable_options = options
|
43
46
|
end
|
@@ -67,10 +70,12 @@ module PgSearch
|
|
67
70
|
def method_missing(symbol, *args)
|
68
71
|
case symbol
|
69
72
|
when :pg_search_rank
|
70
|
-
raise PgSearchRankNotSelected
|
73
|
+
raise PgSearchRankNotSelected unless respond_to?(:pg_search_rank)
|
74
|
+
|
71
75
|
read_attribute(:pg_search_rank).to_f
|
72
76
|
when :pg_search_highlight
|
73
|
-
raise PgSearchHighlightNotSelected
|
77
|
+
raise PgSearchHighlightNotSelected unless respond_to?(:pg_search_highlight)
|
78
|
+
|
74
79
|
read_attribute(:pg_search_highlight)
|
75
80
|
else
|
76
81
|
super
|
data/pg_search.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
2
4
|
require 'pg_search/version'
|
3
5
|
|
4
6
|
Gem::Specification.new do |s|
|
@@ -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
|
-
s.add_development_dependency 'codeclimate-test-reporter'
|
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.68.1'
|
28
|
+
s.add_development_dependency 'rubocop-performance'
|
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.4'
|
32
33
|
end
|