Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: pg_search_scope single column content support #497

Open
JensDebergh opened this issue Nov 27, 2022 · 0 comments
Open

Feature request: pg_search_scope single column content support #497

JensDebergh opened this issue Nov 27, 2022 · 0 comments

Comments

@JensDebergh
Copy link

JensDebergh commented Nov 27, 2022

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

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

No branches or pull requests

1 participant