From 9ecad98b17e2ce7243af3f029e9413178ce566a3 Mon Sep 17 00:00:00 2001 From: Justin DiRose Date: Tue, 10 Sep 2019 10:53:07 -0500 Subject: [PATCH] FIX: Bug with search --- plugin.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugin.rb b/plugin.rb index 3b35fc0..a66a505 100644 --- a/plugin.rb +++ b/plugin.rb @@ -16,10 +16,14 @@ after_initialize do if Search.respond_to? :advanced_filter Search.advanced_filter(/in:kb/) do |posts| selected_categories = SiteSetting.knowledge_explorer_categories.split("|") - categories = Category.where('id IN (?)', selected_categories).pluck(:id) + if selected_categories + categories = Category.where('id IN (?)', selected_categories).pluck(:id) + end selected_tags = SiteSetting.knowledge_explorer_tags.split("|") - tags = Tag.where('name IN (?)', selected_tags).pluck(:id) + if selected_tags + tags = Tag.where('name IN (?)', selected_tags).pluck(:id) + end 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