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.4.27 app/queries/workarea/search/related_help.rb
workarea-core-3.5.4 app/queries/workarea/search/related_help.rb
workarea-core-3.4.26 app/queries/workarea/search/related_help.rb
workarea-core-3.5.3 app/queries/workarea/search/related_help.rb
workarea-core-3.4.25 app/queries/workarea/search/related_help.rb
workarea-core-3.5.2 app/queries/workarea/search/related_help.rb
workarea-core-3.4.24 app/queries/workarea/search/related_help.rb
workarea-core-3.5.1 app/queries/workarea/search/related_help.rb
workarea-core-3.4.23 app/queries/workarea/search/related_help.rb
workarea-core-3.4.22 app/queries/workarea/search/related_help.rb
workarea-core-3.5.0 app/queries/workarea/search/related_help.rb
workarea-core-3.4.21 app/queries/workarea/search/related_help.rb
workarea-core-3.5.0.beta.1 app/queries/workarea/search/related_help.rb
workarea-core-3.4.20 app/queries/workarea/search/related_help.rb
workarea-core-3.4.19 app/queries/workarea/search/related_help.rb
workarea-core-3.4.18 app/queries/workarea/search/related_help.rb
workarea-core-3.4.17 app/queries/workarea/search/related_help.rb
workarea-core-3.4.16 app/queries/workarea/search/related_help.rb
workarea-core-3.4.15 app/queries/workarea/search/related_help.rb
workarea-core-3.4.14 app/queries/workarea/search/related_help.rb