Skip to content

Commit

Permalink
Merge remote-tracking branch 'case/master' into 2.3.6/single-associat…
Browse files Browse the repository at this point in the history
…ion-performance
  • Loading branch information
mhenrixon committed Aug 16, 2023
2 parents 8d6bcfa + 2ed9190 commit 4f528b8
Show file tree
Hide file tree
Showing 41 changed files with 751 additions and 904 deletions.
21 changes: 8 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,28 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby-version: ['2.7', '3.0', '3.1']
ruby-version: ['2.7', '3.0', '3.1', '3.2']
active-record-version-env:
- ACTIVE_RECORD_VERSION="~> 5.2.0"
- ACTIVE_RECORD_VERSION="~> 6.0.0"
- ACTIVE_RECORD_VERSION="~> 6.1.0"
- ACTIVE_RECORD_VERSION="~> 7.0.0"
allow-failure: [false]
include:
- ruby-version: '3.1'
- ruby-version: '3.2'
active-record-version-env: ACTIVE_RECORD_BRANCH="main"
allow-failure: true
- ruby-version: '3.1'
- ruby-version: '3.2'
active-record-version-env: ACTIVE_RECORD_BRANCH="7-0-stable"
allow-failure: true
- ruby-version: '3.1'
- ruby-version: '3.2'
active-record-version-env: ACTIVE_RECORD_BRANCH="6-1-stable"
allow-failure: true
exclude:
- ruby-version: '3.0'
active-record-version-env: ACTIVE_RECORD_VERSION="~> 5.2.0"
allow-failure: false
- ruby-version: '3.1'
active-record-version-env: ACTIVE_RECORD_VERSION="~> 5.2.0"
allow-failure: false
- ruby-version: '3.3.0-preview1'
active-record-version-env: ACTIVE_RECORD_VERSION="~> 7.0.0"
allow-failure: true
continue-on-error: ${{ matrix.allow-failure }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
Expand Down
125 changes: 11 additions & 114 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,137 +1,34 @@
require:
- standard
- rubocop-performance
- rubocop-rails
- rubocop-rake
- rubocop-rspec

inherit_gem:
standard: config/base.yml

AllCops:
TargetRubyVersion: 2.7
NewCops: enable
NewCops: disable
Exclude:
- bin/**/*
- vendor/**/*

Style/StringLiterals:
Enabled: false

Layout/LineLength:
Max: 120

Metrics/MethodLength:
Max: 15

Metrics/BlockLength:
Exclude:
- spec/**/*

Layout/ParameterAlignment:
EnforcedStyle: with_fixed_indentation

Style/NumericPredicate:
Enabled: false

Style/PercentLiteralDelimiters:
PreferredDelimiters:
'%w': '[]'
'%W': '[]'

Style/GuardClause:
Enabled: false

Naming/VariableNumber:
EnforcedStyle: snake_case

Bundler/OrderedGems:
Enabled: false

Bundler/DuplicatedGem:
Enabled: false

Style/EmptyMethod:
EnforcedStyle: expanded

Layout/FirstArrayElementIndentation:
EnforcedStyle: consistent

Style/Documentation:
Enabled: false

Style/WordArray:
EnforcedStyle: percent
MinSize: 3

Style/HashEachMethods:
Lint/RedundantCopDisableDirective:
Enabled: true

Style/HashTransformKeys:
Lint/RedundantCopEnableDirective:
Enabled: true

Style/HashTransformValues:
Enabled: true

Rails/ApplicationRecord:
Bundler/DuplicatedGem:
Enabled: false

Rails/TimeZone:
Rails/ApplicationRecord:
Enabled: false

RSpec/ContextWording:
Prefixes:
- using
- via
- when
- with
- without

Lint/RaiseException:
Enabled: true

Lint/StructNewOverride:
Enabled: true

Layout/SpaceAroundMethodCallOperator:
Enabled: true

Style/ExponentialNotation:
Enabled: true

RSpec/DescribedClass:
Enabled: true

RSpec/ExpectInHook:
Rails/RakeEnvironment:
Enabled: false

RSpec/FilePath:
CustomTransform:
TSearch: "tsearch"
DMetaphone: "dmetaphone"

Layout/EmptyLinesAroundAttributeAccessor:
Enabled: true

Lint/DeprecatedOpenSSLConstant:
Enabled: true

Style/SlicingWithRange:
Enabled: true

Lint/MixedRegexpCaptureTypes:
Enabled: true

Style/RedundantFetchBlock:
Enabled: true

Style/RedundantRegexpCharacterClass:
Enabled: true

Style/RedundantRegexpEscape:
Enabled: true

RSpec/MultipleExpectations:
Max: 5

RSpec/ExampleLength:
Max: 15

Rails/RakeEnvironment:
Rails/TimeZone:
Enabled: false
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby 2.7.6
27 changes: 21 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"

gemspec

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

if ENV['ACTIVE_RECORD_BRANCH']
gem 'activerecord', git: 'https://github.com/rails/rails.git', branch: ENV.fetch('ACTIVE_RECORD_BRANCH', nil)
gem 'arel', git: 'https://github.com/rails/arel.git' if ENV.fetch('ACTIVE_RECORD_BRANCH', nil) == 'master'
if ENV["ACTIVE_RECORD_BRANCH"]
gem "activerecord", git: "https://github.com/rails/rails.git", branch: ENV.fetch("ACTIVE_RECORD_BRANCH", nil)
gem "arel", git: "https://github.com/rails/arel.git" if ENV.fetch("ACTIVE_RECORD_BRANCH", nil) == "master"
end

gem 'activerecord', ENV.fetch('ACTIVE_RECORD_VERSION', nil) if ENV['ACTIVE_RECORD_VERSION']
gem "activerecord", ENV.fetch("ACTIVE_RECORD_VERSION", nil) if ENV["ACTIVE_RECORD_VERSION"]

gem "pry"
gem "rake"
gem "rspec"
gem "rubocop"
gem "rubocop-performance"
gem "rubocop-rails"
gem "rubocop-rake"
gem "rubocop-rspec"
gem "simplecov"
gem "simplecov-lcov"
gem "standard", ">= 1.23.0"
gem "undercover"
gem "warning"
gem "with_model"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Read the blog post introducing PgSearch at https://tanzu.vmware.com/content/blog
## REQUIREMENTS

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

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

Sometimes when doing queries combining different features you
might want to searching against only some of the fields with certain features.
might want to search against only some of the fields with certain features.
For example perhaps you want to only do a trigram search against the shorter fields
so that you don't need to reduce the threshold excessively. You can specify
which fields using the 'only' option:
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

require 'bundler'
require "bundler"
Bundler::GemHelper.install_tasks

require 'rspec/core/rake_task'
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)

require "rubocop/rake_task"
Expand Down
2 changes: 1 addition & 1 deletion lib/pg_search/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def order_within_rank
attr_reader :options

def default_options
{ using: :tsearch }
{using: :tsearch}
end

VALID_KEYS = %w[
Expand Down
17 changes: 6 additions & 11 deletions lib/pg_search/configuration/association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,17 @@ def selects

def selects_for_singular_association
columns.map do |column|
if column.tsvector_column
"tsvector_agg(#{column.full_name}) AS #{column.alias}"
else
case postgresql_version
when 0..90000
"array_to_string(array_agg(#{column.full_name}::text), ' ') AS #{column.alias}"
else
"string_agg(#{column.full_name}::text, ' ') AS #{column.alias}"
end
end
"#{column.full_name}::text AS #{column.alias}"
end.join(", ")
end

def selects_for_multiple_association
columns.map do |column|
"string_agg(#{column.full_name}::text, ' ') AS #{column.alias}"
if column.tsvector_column
"tsvector_agg(#{column.full_name}) AS #{column.alias}"
else
"string_agg(#{column.full_name}::text, ' ') AS #{column.alias}"
end
end.join(", ")
end

Expand Down
12 changes: 7 additions & 5 deletions lib/pg_search/configuration/column.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# frozen_string_literal: true

require 'digest'
require "digest"

module PgSearch
class Configuration
class Column
attr_reader :weight, :tsvector_column, :name

def initialize(column_name, weight, model)
@name = column_name.to_s
@column_name = column_name.to_s
@name = column_name.to_s
@column_name = column_name
if weight.is_a?(Hash)
@weight = weight[:weight]
@tsvector_column = weight[:tsvector_column]
Expand All @@ -21,14 +21,16 @@ def initialize(column_name, weight, model)
end

def full_name
return @column_name if @column_name.is_a?(Arel::Nodes::SqlLiteral)

"#{table_name}.#{column_name}"
end

def to_sql
if tsvector_column
"coalesce(#{expression}, '')"
else
"coalesce(#{expression}::text, '')"
"coalesce((#{expression})::text, '')"
end
end

Expand All @@ -39,7 +41,7 @@ def table_name
end

def column_name
@connection.quote_column_name(@column_name)
@connection.quote_column_name(@name)
end

def expression
Expand Down
2 changes: 1 addition & 1 deletion lib/pg_search/configuration/foreign_column.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'digest'
require "digest"

module PgSearch
class Configuration
Expand Down
14 changes: 7 additions & 7 deletions lib/pg_search/document.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# frozen_string_literal: true

require 'logger'
require "logger"

module PgSearch
class Document < ActiveRecord::Base
include PgSearch::Model

self.table_name = 'pg_search_documents'
self.table_name = "pg_search_documents"
belongs_to :searchable, polymorphic: true

# The logger might not have loaded yet.
Expand All @@ -17,12 +17,12 @@ def self.logger

pg_search_scope :search, lambda { |*args|
options = if PgSearch.multisearch_options.respond_to?(:call)
PgSearch.multisearch_options.call(*args)
else
{ query: args.first }.merge(PgSearch.multisearch_options)
end
PgSearch.multisearch_options.call(*args)
else
{query: args.first}.merge(PgSearch.multisearch_options)
end

{ against: :content }.merge(options)
{against: :content}.merge(options)
}
end
end
2 changes: 1 addition & 1 deletion lib/pg_search/features/dmetaphone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Features
class DMetaphone
def initialize(query, options, columns, model, normalizer)
dmetaphone_normalizer = Normalizer.new(normalizer)
options = (options || {}).merge(dictionary: 'simple')
options = (options || {}).merge(dictionary: "simple")
@tsearch = TSearch.new(query, options, columns, model, dmetaphone_normalizer)
end

Expand Down
Loading

0 comments on commit 4f528b8

Please sign in to comment.