Skip to content

Commit a9c76ef

Browse files
committed
Merge remote-tracking branch 'case/master' into 2.3.6/single-association-performance
2 parents 8d6bcfa + 2ed9190 commit a9c76ef

41 files changed

Lines changed: 755 additions & 913 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,33 +36,28 @@ jobs:
3636
strategy:
3737
fail-fast: false
3838
matrix:
39-
ruby-version: ['2.7', '3.0', '3.1']
39+
ruby-version: ['2.7', '3.0', '3.1', '3.2']
4040
active-record-version-env:
41-
- ACTIVE_RECORD_VERSION="~> 5.2.0"
4241
- ACTIVE_RECORD_VERSION="~> 6.0.0"
4342
- ACTIVE_RECORD_VERSION="~> 6.1.0"
4443
- ACTIVE_RECORD_VERSION="~> 7.0.0"
4544
allow-failure: [false]
4645
include:
47-
- ruby-version: '3.1'
46+
- ruby-version: '3.2'
4847
active-record-version-env: ACTIVE_RECORD_BRANCH="main"
4948
allow-failure: true
50-
- ruby-version: '3.1'
49+
- ruby-version: '3.2'
5150
active-record-version-env: ACTIVE_RECORD_BRANCH="7-0-stable"
5251
allow-failure: true
53-
- ruby-version: '3.1'
52+
- ruby-version: '3.2'
5453
active-record-version-env: ACTIVE_RECORD_BRANCH="6-1-stable"
5554
allow-failure: true
56-
exclude:
57-
- ruby-version: '3.0'
58-
active-record-version-env: ACTIVE_RECORD_VERSION="~> 5.2.0"
59-
allow-failure: false
60-
- ruby-version: '3.1'
61-
active-record-version-env: ACTIVE_RECORD_VERSION="~> 5.2.0"
62-
allow-failure: false
55+
- ruby-version: '3.3.0-preview1'
56+
active-record-version-env: ACTIVE_RECORD_VERSION="~> 7.0.0"
57+
allow-failure: true
6358
continue-on-error: ${{ matrix.allow-failure }}
6459
steps:
65-
- uses: actions/checkout@v2
60+
- uses: actions/checkout@v3
6661
- name: Set up Ruby
6762
uses: ruby/setup-ruby@v1
6863
with:

.rubocop.yml

Lines changed: 11 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,137 +1,34 @@
11
require:
2+
- standard
23
- rubocop-performance
34
- rubocop-rails
45
- rubocop-rake
56
- rubocop-rspec
67

8+
inherit_gem:
9+
standard: config/base.yml
10+
711
AllCops:
812
TargetRubyVersion: 2.7
9-
NewCops: enable
13+
NewCops: disable
1014
Exclude:
1115
- bin/**/*
1216
- vendor/**/*
1317

14-
Style/StringLiterals:
15-
Enabled: false
16-
17-
Layout/LineLength:
18-
Max: 120
19-
20-
Metrics/MethodLength:
21-
Max: 15
22-
23-
Metrics/BlockLength:
24-
Exclude:
25-
- spec/**/*
26-
27-
Layout/ParameterAlignment:
28-
EnforcedStyle: with_fixed_indentation
29-
30-
Style/NumericPredicate:
31-
Enabled: false
32-
33-
Style/PercentLiteralDelimiters:
34-
PreferredDelimiters:
35-
'%w': '[]'
36-
'%W': '[]'
37-
38-
Style/GuardClause:
39-
Enabled: false
40-
41-
Naming/VariableNumber:
42-
EnforcedStyle: snake_case
43-
44-
Bundler/OrderedGems:
45-
Enabled: false
46-
47-
Bundler/DuplicatedGem:
48-
Enabled: false
49-
50-
Style/EmptyMethod:
51-
EnforcedStyle: expanded
52-
53-
Layout/FirstArrayElementIndentation:
54-
EnforcedStyle: consistent
55-
56-
Style/Documentation:
57-
Enabled: false
58-
59-
Style/WordArray:
60-
EnforcedStyle: percent
61-
MinSize: 3
62-
63-
Style/HashEachMethods:
18+
Lint/RedundantCopDisableDirective:
6419
Enabled: true
6520

66-
Style/HashTransformKeys:
21+
Lint/RedundantCopEnableDirective:
6722
Enabled: true
6823

69-
Style/HashTransformValues:
70-
Enabled: true
71-
72-
Rails/ApplicationRecord:
24+
Bundler/DuplicatedGem:
7325
Enabled: false
7426

75-
Rails/TimeZone:
27+
Rails/ApplicationRecord:
7628
Enabled: false
7729

78-
RSpec/ContextWording:
79-
Prefixes:
80-
- using
81-
- via
82-
- when
83-
- with
84-
- without
85-
86-
Lint/RaiseException:
87-
Enabled: true
88-
89-
Lint/StructNewOverride:
90-
Enabled: true
91-
92-
Layout/SpaceAroundMethodCallOperator:
93-
Enabled: true
94-
95-
Style/ExponentialNotation:
96-
Enabled: true
97-
98-
RSpec/DescribedClass:
99-
Enabled: true
100-
101-
RSpec/ExpectInHook:
30+
Rails/RakeEnvironment:
10231
Enabled: false
10332

104-
RSpec/FilePath:
105-
CustomTransform:
106-
TSearch: "tsearch"
107-
DMetaphone: "dmetaphone"
108-
109-
Layout/EmptyLinesAroundAttributeAccessor:
110-
Enabled: true
111-
112-
Lint/DeprecatedOpenSSLConstant:
113-
Enabled: true
114-
115-
Style/SlicingWithRange:
116-
Enabled: true
117-
118-
Lint/MixedRegexpCaptureTypes:
119-
Enabled: true
120-
121-
Style/RedundantFetchBlock:
122-
Enabled: true
123-
124-
Style/RedundantRegexpCharacterClass:
125-
Enabled: true
126-
127-
Style/RedundantRegexpEscape:
128-
Enabled: true
129-
130-
RSpec/MultipleExpectations:
131-
Max: 5
132-
133-
RSpec/ExampleLength:
134-
Max: 15
135-
136-
Rails/RakeEnvironment:
33+
Rails/TimeZone:
13734
Enabled: false

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ruby 2.7.6

Gemfile

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
# frozen_string_literal: true
22

3-
source 'https://rubygems.org'
3+
source "https://rubygems.org"
44

55
gemspec
66

7-
gem 'pg', '>= 0.21.0', platform: :ruby
7+
gem "pg", ">= 0.21.0", platform: :ruby
88
gem "activerecord-jdbcpostgresql-adapter", ">= 1.3.1", platform: :jruby
99

10-
if ENV['ACTIVE_RECORD_BRANCH']
11-
gem 'activerecord', git: 'https://github.com/rails/rails.git', branch: ENV.fetch('ACTIVE_RECORD_BRANCH', nil)
12-
gem 'arel', git: 'https://github.com/rails/arel.git' if ENV.fetch('ACTIVE_RECORD_BRANCH', nil) == 'master'
10+
if ENV["ACTIVE_RECORD_BRANCH"]
11+
gem "activerecord", git: "https://github.com/rails/rails.git", branch: ENV.fetch("ACTIVE_RECORD_BRANCH", nil)
12+
gem "arel", git: "https://github.com/rails/arel.git" if ENV.fetch("ACTIVE_RECORD_BRANCH", nil) == "master"
1313
end
1414

15-
gem 'activerecord', ENV.fetch('ACTIVE_RECORD_VERSION', nil) if ENV['ACTIVE_RECORD_VERSION']
15+
gem "activerecord", ENV.fetch("ACTIVE_RECORD_VERSION", nil) if ENV["ACTIVE_RECORD_VERSION"]
16+
17+
gem "pry"
18+
gem "rake"
19+
gem "rspec"
20+
gem "rubocop"
21+
gem "rubocop-performance"
22+
gem "rubocop-rails"
23+
gem "rubocop-rake"
24+
gem "rubocop-rspec"
25+
gem "simplecov"
26+
gem "simplecov-lcov"
27+
gem "standard", ">= 1.23.0"
28+
gem "undercover"
29+
gem "warning"
30+
gem "with_model"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Read the blog post introducing PgSearch at https://tanzu.vmware.com/content/blog
1414
## REQUIREMENTS
1515

1616
* Ruby 2.7+
17-
* ActiveRecord 5.2+
17+
* Active Record 6.0+
1818
* PostgreSQL 9.2+
1919
* [PostgreSQL extensions](https://github.com/Casecommons/pg_search/wiki/Installing-PostgreSQL-Extensions) for certain features
2020

@@ -979,7 +979,7 @@ Sentence.word_similarity_like("word") # => [sentence]
979979
### Limiting Fields When Combining Features
980980

981981
Sometimes when doing queries combining different features you
982-
might want to searching against only some of the fields with certain features.
982+
might want to search against only some of the fields with certain features.
983983
For example perhaps you want to only do a trigram search against the shorter fields
984984
so that you don't need to reduce the threshold excessively. You can specify
985985
which fields using the 'only' option:

Rakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# frozen_string_literal: true
22

3-
require 'bundler'
3+
require "bundler"
44
Bundler::GemHelper.install_tasks
55

6-
require 'rspec/core/rake_task'
6+
require "rspec/core/rake_task"
77
RSpec::Core::RakeTask.new(:spec)
88

99
require "rubocop/rake_task"

lib/pg_search/configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def order_within_rank
8080
attr_reader :options
8181

8282
def default_options
83-
{ using: :tsearch }
83+
{using: :tsearch}
8484
end
8585

8686
VALID_KEYS = %w[

lib/pg_search/configuration/association.rb

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,17 @@ def selects
3939

4040
def selects_for_singular_association
4141
columns.map do |column|
42-
if column.tsvector_column
43-
"tsvector_agg(#{column.full_name}) AS #{column.alias}"
44-
else
45-
case postgresql_version
46-
when 0..90000
47-
"array_to_string(array_agg(#{column.full_name}::text), ' ') AS #{column.alias}"
48-
else
49-
"string_agg(#{column.full_name}::text, ' ') AS #{column.alias}"
50-
end
51-
end
42+
"#{column.full_name}::text AS #{column.alias}"
5243
end.join(", ")
5344
end
5445

5546
def selects_for_multiple_association
5647
columns.map do |column|
57-
"string_agg(#{column.full_name}::text, ' ') AS #{column.alias}"
48+
if column.tsvector_column
49+
"tsvector_agg(#{column.full_name}) AS #{column.alias}"
50+
else
51+
"string_agg(#{column.full_name}::text, ' ') AS #{column.alias}"
52+
end
5853
end.join(", ")
5954
end
6055

lib/pg_search/configuration/column.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# frozen_string_literal: true
22

3-
require 'digest'
3+
require "digest"
44

55
module PgSearch
66
class Configuration
77
class Column
88
attr_reader :weight, :tsvector_column, :name
99

1010
def initialize(column_name, weight, model)
11-
@name = column_name.to_s
12-
@column_name = column_name.to_s
11+
@name = column_name.to_s
12+
@column_name = column_name
1313
if weight.is_a?(Hash)
1414
@weight = weight[:weight]
1515
@tsvector_column = weight[:tsvector_column]
@@ -21,14 +21,16 @@ def initialize(column_name, weight, model)
2121
end
2222

2323
def full_name
24+
return @column_name if @column_name.is_a?(Arel::Nodes::SqlLiteral)
25+
2426
"#{table_name}.#{column_name}"
2527
end
2628

2729
def to_sql
2830
if tsvector_column
2931
"coalesce(#{expression}, '')"
3032
else
31-
"coalesce(#{expression}::text, '')"
33+
"coalesce((#{expression})::text, '')"
3234
end
3335
end
3436

@@ -39,7 +41,7 @@ def table_name
3941
end
4042

4143
def column_name
42-
@connection.quote_column_name(@column_name)
44+
@connection.quote_column_name(@name)
4345
end
4446

4547
def expression

lib/pg_search/configuration/foreign_column.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require 'digest'
3+
require "digest"
44

55
module PgSearch
66
class Configuration

0 commit comments

Comments
 (0)