FEATURE: Add kb search helper

The naming of this is currently arbitrary and may need to be changed,
but currently works off the settings `knowledge explorer categories` and
`knowledge explorer tags`

Remove filter when plugin disabled
This commit is contained in:
Justin DiRose 2019-08-22 16:58:28 -05:00
parent 4586b1992f
commit 1999cd0825
1 changed files with 18 additions and 0 deletions

View File

@ -8,3 +8,21 @@ enabled_site_setting :knowledge_explorer_enabled
register_asset 'stylesheets/common/knowledge-explorer.scss'
load File.expand_path('../lib/knowledge_explorer/engine.rb', __FILE__)
after_initialize do
require_dependency 'search'
if SiteSetting.knowledge_explorer_enabled
if Search.respond_to? :advanced_filter
Search.advanced_filter(/in:kb/) do |posts|
selected_categories = SiteSetting.knowledge_explorer_categories.split("|")
categories = Category.where('slug IN (?)', selected_categories).pluck(:id)
selected_tags = SiteSetting.knowledge_explorer_tags.split("|")
tags = Tag.where('name IN (?)', selected_tags).pluck(:id)
posts.where('category_id IN (?) OR topics.id IN (SELECT DISTINCT(tt.topic_id) FROM topic_tags tt WHERE tt.tag_id IN (?))', categories, tags)
end
end
end
end