Casecommons/pg_search

Feature request: pg_search_scope single column content support

JensDebergh opened this issue · 0 comments

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:

  • Works similar to multisearch.
  • This has the extra benefit that you can cache values from associations aswel like the supplier_name in this example.

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