FEATURE: add support for tag group search

The behaviour of #TERM in search has been amended

1. We try category or subcategory slugs
2. We try tags
3. We try tag-groups

The term `hello #my-group` will search for all posts tagged with any of
the tags in the tag group `My Group`

Future work may be introducing a slug cache here or caching it in the table
but the assumption is that the number of tag groups will not be huge
This commit is contained in:
Sam Saffron
2019-06-27 17:53:26 +10:00
parent 9a2eb5c8cb
commit 8f7a387aa7
3 changed files with 70 additions and 28 deletions

View File

@@ -36,11 +36,18 @@ class TagGroup < ActiveRecord::Base
@permissions = TagGroup.resolve_permissions(permissions)
end
def self.resolve_permissions(permissions)
everyone_group_id = Group::AUTO_GROUPS[:everyone]
full = TagGroupPermission.permission_types[:full]
# TODO: long term we can cache this if TONs of tag groups exist
def self.find_id_by_slug(slug)
self.pluck(:id, :name).each do |id, name|
if Slug.for(name) == slug
return id
end
end
nil
end
mapped = permissions.map do |group, permission|
def self.resolve_permissions(permissions)
permissions.map do |group, permission|
group_id = Group.group_id_from_param(group)
permission = TagGroupPermission.permission_types[permission] unless permission.is_a?(Integer)
[group_id, permission]