Open esb opened 6 years ago
Improved version
scope :"with_#{tag_name}_like", ->(pattern) { subquery = unscoped.select("id, unnest(#{table_name}.#{tag_name}) AS subquery_tag"); where(:id => select('id').from(subquery).where('subquery_tag ~* ?', pattern)) }
@esb do you actually use this? Hard to imagine big use for tags matching.
This is massively useful for finding items in categories/sub-categories.
To use a D&D analogy, I might have an item tagged with 'weapon-small' and another with 'weapon-medium'. With tag matching I can find all the items that match 'weapon' and also refine that by searching for just small weapons with 'weapon-small'.
You want to try to commit this as a pull request? @tmiyamon still merges them from time to time.
I contacted him if he would like to have another maintainer for this gem (I'd be happy to, since i use it heavily in my own project) - hopefully he will answer positively to my offer ;-)
Would love to see this feature. I've been digging for a neat way to use the % operator from pg_trgm as an alternative to complete matching. If others are interested, I would be happy to give it a shot and submit a pull request.
I don't have a personal need for this feature, but now I can accept pull requests and release new gems.
If you can cover all bases with your PR (documentation, tests, feature) - I'll be happy to review/merge it.
As a quick exercise, I have added the ability to search the array values with a regular expression.
The following scope was added to taggable.rb
This allows you to get tags as follows: