-
Notifications
You must be signed in to change notification settings - Fork 380
Description
If there were a way to add entries to PgSearch::ScopeOptions::FEATURE_CLASSES, then users could extend pg_search with their own custom features. For example, I created a Trigram (Feature) sub-class that adds some additional scoping which greatly improved the performance of the resulting queries.
I should also mention #542 would also probably allow me to solve the same problem. However, I think there's value in having both options available.
pg_search/lib/pg_search/scope_options.rb
Lines 136 to 140 in 08df66a
| FEATURE_CLASSES = { # standard:disable Lint/UselessConstantScoping | |
| dmetaphone: Features::DMetaphone, | |
| tsearch: Features::TSearch, | |
| trigram: Features::Trigram | |
| }.freeze |
Right now, I'm getting around the fact that FEATURE_CLASSES is frozen by doing this:
Rails.application.config.after_initialize do
feature_classes = PgSearch::ScopeOptions::FEATURE_CLASSES.dup.merge(
scoped_trigram: PgSearch::Features::ScopedTrigram,
).freeze
PgSearch::ScopeOptions.send(:remove_const, :FEATURE_CLASSES)
PgSearch::ScopeOptions.const_set(:FEATURE_CLASSES, feature_classes)
endIdeally, I could add a new feature like this:
PgSearch.add_feature(scoped_trigram: ScopedTrigram)If there is interest in this feature, I would be happy to make a pull request with tests. Please let me know!