Casecommons / pg_search

pg_search builds ActiveRecord named scopes that take advantage of PostgreSQL’s full text search
http://www.casebook.net
MIT License
1.3k stars 369 forks source link

Feature request: pg_search_scope single column content support #497

Open JensDebergh opened 1 year ago

JensDebergh commented 1 year ago

Hi!

I've been loving this library. I fully ditched elasticsearch in favor of pg_search, while switching I thought of a feature that might be easy to implement since 90% of the functionality is already there by the library.

I noticed there's 2 distinct ways of using this library which is the multisearch and search scopes.

Multisearch builts a content column based on the properties you provide on the against option to pg_search.

Is there a way to use this to populate arbitrary column like search_content on the record which can then be used with a search scope?

Example:

Table expenses
==================
name :string, default: ""
search_content :text, default: ""
==================

class Expense
   belongs_to :supplier

   delegate :name, to: :supplier, prefix: :supplier

   pg_search_scope :search, against: [
    :name,
    :supplier_name
  ],
  search_column: :search_content
end

When providing the search_column option it is going to store the search data indicated by the against option on a single column like it does with Multisearch

Pros:

Con:

The downside is when Supplier changes it's not going to reflect in the search content, but that's perfectly fine in some circumstances.

The above example can be easily implemented by myself using the existing library but I would have to write the activerecord callbacks myself and it adds a lot of boilerplate to every model.

Is this something you guys would be interested in if I open a pull request?

Kind regards Jens Debergh