Skip to content
CAI
Software that uses CAICheck a score

Casecommons/pg_search

67.7

Adequate · 19 September 2026

1.1k

lines of production code

Ruby

primary language

1

measurement over time

CAI band scale
CAI lens gauges

What this system is

This system is the PgSearch library, a Ruby gem that provides full-text search capabilities for Active Record models using PostgreSQL. It supports multiple search strategies including TSearch, Trigram, and phonetic matching via D-Metaphone, and enables searching across associated records. The library manages search indexing through a multisearch document table and handles complex scenarios like Single Table Inheritance and conditional indexing.

How it got here

2010 — Architectural refactor and modernization

8 changes.

This period focused on a major architectural refactor of PgSearch, replacing string-based SQL generation with composable Arel expressions to improve maintainability and compatibility with Rails 7.2 and 8.0. The update also introduced new phonetic search capabilities via D-Metaphone, standardized development environments with configuration files, and enforced stricter Ruby and Active Record version requirements.

2012–2015 — Testing expansion and migration modernization

11 changes.

This period focused on significantly expanding test coverage across PgSearch components, including multisearch, normalizers, and configuration classes, while adding integration tests for associations and STI. Concurrently, the project modernized its migration setup by replacing Rake tasks with Rails generators and updating templates to follow current Ruby and Rails conventions.

Features

Add .editorconfig, .rspec, and StandardRB configuration files

The project now includes configuration files to standardize development environment settings. An \.editorconfig\ file enforces consistent indentation (2 spaces), line endings (LF), and UTF-8 charset across editors. An \.rspec\ file is added to enable colored output during test runs. Additionally, a \.standard.yml\ file configures the StandardRB linter to target Ruby 3.3 and Rails 8.0, with performance and Rails plugins enabled. The \Rakefile\ is updated to include tasks for running specs and the StandardRB linter as part of the default build.

(repo-wide) · high confidence

A new SQL function \pg\_search\_dmetaphone\ is introduced to support phonetic search using the D-Metaphone algorithm. This function wraps the underlying \dmetaphone\ function, splitting input text by whitespace, applying the algorithm to each word, and rejoining the results. The addition of this function, along with its uninstall script, enables users to create indexes on phonetic representations of text fields, improving search performance for fuzzy matching scenarios.

sql · high confidence

Behavioural changes

Default binstub generation enabled in .bundle/config

The project now configures Bundler to generate binstubs by default, placing them in the \bin\ directory. This ensures that executable wrappers for gems are created automatically during installation, allowing users to run gem commands directly from the project's bin folder without needing to specify the full path or rely on global installations.

.bundle · high confidence

Deprecation of direct PgSearch inclusion and introduction of configuration options

Including \PgSearch\ directly into an Active Record model is now deprecated in favor of \PgSearch::Model\, with a warning issued at runtime to guide users toward the new API in version 3.0. The library also introduces module-level configuration via \mattr\_accessor\ for \multisearch\_options\ and \unaccent\_function\, and adds thread-safe methods to temporarily disable multisearch behavior. Additionally, new error classes (\PgSearchRankNotSelected\ and \PgSearchHighlightNotSelected\) are defined to provide clearer feedback when required chaining methods are omitted.

lib · high confidence

Migration setup now uses Rails generators instead of Rake tasks

The library has replaced its previous Rake-based migration setup with standard Rails generators. Users can now generate the necessary migration files (such as those for dmetaphone support and the multisearch documents table) using the Rails generator command, which creates timestamped migration files in db/migrate. This change also ensures that generated migrations include the ActiveRecord version tag for better compatibility tracking.

_lib/pg\search/migration · high confidence

The generated migration templates for pg\_search have been updated to use modern Ruby and Rails conventions. The templates now employ squiggly heredocs with String\#squish for SQL execution, require PostgreSQL 9.0 or higher, and ensure timestamps are created with null: false. Additionally, the polymorphic index for pg\_search\_documents is now generated by default, and the templates include the Rails version via the migration\_version helper.

_lib/pg\search/migration/templates · high confidence

Multisearch rebuild now respects model conditions and inheritance

The multisearch rebuild process has been refactored to handle complex model configurations more accurately. It now honors :if and :unless conditionals defined on multisearchable models, ensuring that only records meeting specific criteria are included in the search index. Additionally, it supports Single Table Inheritance (STI) by correctly filtering records based on the inheritance column, and it accommodates models with non-standard primary keys or dynamic column content by falling back to individual record updates when bulk SQL insertion is not feasible.

_lib/pg\search/multisearch · high confidence

PgSearch v2.4.0: Major architectural refactor and Rails 7.2 compatibility

This release upgrades the library to version 2.4.0, introducing a comprehensive architectural refactor that replaces string-based SQL generation with composable Arel expressions for search conditions, ranking, and joins. The internal configuration is now managed by a dedicated \PgSearch::Configuration\ class, and search features (TSearch, Trigram, DMetaphone) are extracted into distinct classes. Key behavioral changes include the removal of the deprecated \:joins\ option, the addition of an \:update\_if\ option to control when \PgSearch::Document\ records are updated, and the renaming of the \:normalizing\ API to \:ignoring\ for accent handling. The update also drops support for Active Record versions prior to 4.2 and adds compatibility with Active Record 7.2.

_lib/pg\search · high confidence

Refactored association search configuration to use Arel and standardize column casting

The association search configuration has been refactored to build queries using Arel nodes instead of raw SQL strings, improving composability and safety. New classes \Column\, \ForeignColumn\, and \Association\ handle the construction of search subqueries, ensuring that columns are always cast to text and NULL values are coalesced to empty strings. For \has\_one\ and \belongs\_to\ associations, the search logic now uses direct column casting rather than \string\_agg\, while multi-row associations continue to aggregate results. This change also introduces a new \ForeignColumn\ subclass to correctly handle column references within association joins.

_lib/pg\search/configuration · high confidence

Refactored search features into dedicated classes with Arel integration

The search logic in lib/pg\_search/features has been restructured by extracting TSearch, Trigram, and DMetaphone implementations into their own classes (TSearch, Trigram, DMetaphone) inheriting from a new Feature superclass. This change replaces string-based SQL construction with Arel nodes for conditions, ranks, and highlights, improving compatibility and maintainability. The TSearch feature now supports additional options like :tsvector\_column, :highlight, :negation, and :any\_word, while Trigram supports :threshold and :word\_similarity. DMetaphone is introduced as a new feature for phonetic search.

_lib/pg\search/features · high confidence

Test coverage

Added integration tests for association search, pagination, STI, and deprecation warnings; Added test coverage for PgSearch module singleton methods; Added test coverage for PgSearch multisearch and normalizer components; Added test coverage for PgSearch::Multisearch::Rebuilder; Added unit tests for PgSearch configuration classes; Added unit tests for PgSearch search features; Initialize RSpec test suite with modern syntax and database schema definition; Refactored spec support helpers for database and model setup.

Dependencies

PgSearch now requires Ruby 3.3+ and Active Record 8.0

This update raises the minimum supported versions for the gem, requiring Ruby 3.3 or later and Active Record 8.0 (along with Active Support 8.0). The gemspec has been updated with correct author and license metadata, and the Gemfile now explicitly lists development dependencies such as \debug\, \irb\, \standard\, and \rspec\, while also adding a 7-day cooldown for RubyGems downloads.

(dependencies) · high confidence

Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

How this codebase got here

Baseline

  • First survey — no prior run to compare against. CAI 68.

Lenses

  • Code Health 100
  • Architecture 69
  • Maturity 52
  • Readiness 89
  • Security 92
  • Domain Modelling 100

Changes since last survey

  • 300 commits — 286 feature/other, 14 fixes

By area

  • (root) — 162 commits
  • lib/pg_search — 38 commits
  • spec/lib — 30 commits
  • (repo) — 26 commits
  • .github/workflows — 26 commits
  • spec/integration — 7 commits
  • lib/pg_search.rb — 4 commits
  • doc/plans — 2 commits
  • spec/support — 2 commits
  • .github/dependabot.yml — 1 commit
  • spec/.rubocop.yml — 1 commit
  • spec/spec_helper.rb — 1 commit

Notable commits

  • fix: Fix Style/ModuleMemberExistenceCheck offense
  • fix: Fix broken exclusions in .travis.yml
  • fix: Fix compatibility with ActiveRecord 7.2
  • fix: Fix exclusion rules for Travis CI and Ruby 2.4.9
  • fix: Fix rails dependency
  • fix: Fix sorting of development dependencies
  • fix: Merge Arel rank join fix with regression coverage
  • fix: Merge pull request #428 from elegran/rails-fixes
  • fix: Merge pull request #535 from fatkodima/fix-for-rails-7.2
  • fix: Merge pull request #570 from tagliala/chore/fix-standard-offense
  • fix: Require logger to fix Active Record 7.0 specs
  • fix: Revert "Add rubocop-rubycw"
  • fix: Revert "Prefer thread-safe accessors on PgSearch module"
  • fix: Syntax Fix: Missing , in the example for sort only
  • change: Add .editorconfig
  • change: Add Ruby 2.7.0 to CI
  • change: Add U+02BB/U+02BC to disallow tsquery characters
  • change: Add back missing expectation
  • change: Add composable Arel column expressions
  • change: Add empty line after guard clause.
  • …and 280 more

Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

Survey your own repository

Casecommons/pg_search was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.

About this page

  • The score is its most recent published measurement, taken on 19 September 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
  • Measured at commit e767fe32765b8c702b76f5bd420cf27896aa8abe — the exact code this score is about.
  • Scored under rubric-2026.09.15 — the same rubric and the same method as every other entry in this index.
  • Measured by watchdog.canine.dev using codehealth-analyzer preprod-b51f968c9b10.