suggestions.rb 911 B

1234567891011121314151617181920212223242526
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Queries
  3. class KnowledgeBase::Answer::Suggestions < BaseQuery
  4. description 'Suggestions for insertable knowledge base answers in a new ticket article'
  5. argument :query, String, description: 'Answers to search for'
  6. type [Gql::Types::KnowledgeBase::Answer::TranslationType], null: true
  7. def self.authorize(_obj, ctx)
  8. ctx.current_user.permissions?('ticket.agent')
  9. end
  10. def resolve(query:)
  11. SearchKnowledgeBaseBackend.new(
  12. knowledge_base: nil,
  13. locale: nil,
  14. scope: nil,
  15. flavor: 'agent',
  16. index: 'KnowledgeBase::Answer::Translation',
  17. highlight_enabled: false,
  18. ).search(query, user: context.current_user).map { |meta| ::KnowledgeBase::Answer::Translation.find(meta[:id]) }
  19. end
  20. end
  21. end