Skip to content

Adds support for tsvector_column in associated_against (pg_search_scope) - #580

Open
mhenrixon wants to merge 1 commit into
Casecommons:masterfrom
hldesign:2.3.8/tsvector-column
Open

Adds support for tsvector_column in associated_against (pg_search_scope)#580
mhenrixon wants to merge 1 commit into
Casecommons:masterfrom
hldesign:2.3.8/tsvector-column

Conversation

@mhenrixon

Copy link
Copy Markdown

Adds alternative option syntax for tsvector_column. Adds migration for tsvector aggregation.
Adds support for tsvector columns in associated models.

Closes #499 in favor of this

pg_search_scope :full_text_search, (lambda do |query, locale = "swedish"|
    {
      query: query,
      associated_against: {
        taggings: { name: "B" },
        editables: {
          content_tsvector: { tsvector_column: true },
        },
      },
      order_within_rank: "articles.id DESC",
      using: {
        tsearch: {
          dictionary: SearchDocument.dictionary(locale),
          prefix: true,
        },
      },
    }
  end)

Supersedes #504 (same change, rebased onto current master as a single commit; standardrb clean, suite green on Ruby 4.0 / Active Record 8.1).

Lets a pg_search_scope search associated models through a precomputed
tsvector column instead of building to_tsvector(...) at query time:

    pg_search_scope :search, associated_against: {
      comments: { body_tsvector: { tsvector_column: true } }
    }

- Column accepts `{ tsvector_column: true, weight: ... }` in place of a bare
  weight and emits `coalesce(col::tsvector, '')` for such columns.
- Association selects cast to tsvector (singular) or aggregate with a new
  `tsvector_agg` (plural) instead of string_agg(...::text).
- Tsearch skips the to_tsvector() wrap for tsvector columns.
- `pg_search:migration:associated_against_tsvector` generator installs the
  `tsvector_agg` aggregate (sql/tsvector_agg.sql).

Rebased onto master (was PR Casecommons#504's 2.3.6-based branch), standardrb clean,
suite green on Ruby 4.0 / Active Record 8.1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant