Browse Source

Fixes #3070 - KB search bar doesn't find indexed attachments

Mantas 4 years ago
parent
commit
27b3fb4546

+ 1 - 1
lib/search_knowledge_base_backend.rb

@@ -165,7 +165,7 @@ class SearchKnowledgeBaseBackend
 
     if @params.fetch(:highlight_enabled, true)
       output[:highlight_fields_by_indexes] = {
-        'KnowledgeBase::Answer::Translation':   %w[title content.body],
+        'KnowledgeBase::Answer::Translation':   %w[title content.body attachment.content],
         'KnowledgeBase::Category::Translation': %w[title],
         'KnowledgeBase::Translation':           %w[title]
       }

+ 32 - 0
spec/lib/search_knowledge_base_backend_spec.rb

@@ -0,0 +1,32 @@
+require 'rails_helper'
+
+RSpec.describe SearchKnowledgeBaseBackend, searchindex: true do
+  include_context 'basic Knowledge Base'
+
+  before do
+    configure_elasticsearch(required: true, rebuild: true) do
+      published_answer
+    end
+  end
+
+  describe '#search' do
+    let(:instance) { described_class.new options }
+    let(:user)     { create(:admin) }
+
+    context 'when highlight enabled' do
+      let(:options) do
+        {
+          knowledge_base:    knowledge_base,
+          locale:            primary_locale,
+          scope:             nil,
+          highlight_enabled: true
+        }
+      end
+
+      # https://github.com/zammad/zammad/issues/3070
+      it 'lists item with an attachment' do
+        expect(instance.search('Hello World', user: user)).to be_present
+      end
+    end
+  end
+end