Sha256: 5b81251c1464e0a95d37c6140baad1417efa16cfaa9815e6502f8f83eb749ec0

Contents?: true

Size: 1.31 KB

Versions: 62

Compression:

Stored size: 1.31 KB

Contents

module Workarea
  module Search
    # TODO remove related help in v4
    class RelatedHelp
      include Query
      include Pagination

      document Search::Help

      def query
        {
          more_like_this: {
            min_term_freq: 1,
            min_doc_freq: 1,
            fields: %w(name facets.category body),
            ids: Array(params[:ids]),
            like_text: params[:like_text]
          }
        }
      end

      def size
        Workarea.config.max_admin_related_help
      end

      def results
        @_results ||=
          if results_with_url_matching.blank?
             use_more_like_this? ? super : []
          elsif use_more_like_this?
            combine_url_matching_with(super)
          else
            []
          end
      end

      def results_with_url_matching
        return [] unless params[:for_url].present?
        Workarea::Help::Article.find_matching_url(params[:for_url])
      end

      def use_more_like_this?
        params[:like_text].present? || params[:ids].present?
      end

      private

      def combine_url_matching_with(results)
        max = Workarea.config.max_admin_related_help

        items = results_with_url_matching.first(max) + results.items
        items.uniq!

        PagedArray.from(items.first(max), 1, max, max)
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.15 app/queries/workarea/search/related_help.rb
workarea-core-3.4.36 app/queries/workarea/search/related_help.rb
workarea-core-3.5.14 app/queries/workarea/search/related_help.rb
workarea-core-3.4.35 app/queries/workarea/search/related_help.rb
workarea-core-3.5.13 app/queries/workarea/search/related_help.rb
workarea-core-3.4.34 app/queries/workarea/search/related_help.rb
workarea-core-3.5.12 app/queries/workarea/search/related_help.rb
workarea-core-3.4.33 app/queries/workarea/search/related_help.rb
workarea-core-3.5.11 app/queries/workarea/search/related_help.rb
workarea-core-3.5.10 app/queries/workarea/search/related_help.rb
workarea-core-3.4.32 app/queries/workarea/search/related_help.rb
workarea-core-3.5.9 app/queries/workarea/search/related_help.rb
workarea-core-3.4.31 app/queries/workarea/search/related_help.rb
workarea-core-3.5.8 app/queries/workarea/search/related_help.rb
workarea-core-3.4.30 app/queries/workarea/search/related_help.rb
workarea-core-3.5.7 app/queries/workarea/search/related_help.rb
workarea-core-3.4.29 app/queries/workarea/search/related_help.rb
workarea-core-3.5.6 app/queries/workarea/search/related_help.rb
workarea-core-3.4.28 app/queries/workarea/search/related_help.rb
workarea-core-3.5.5 app/queries/workarea/search/related_help.rb