Sha256: ee255cd060eaf3c53dbee1ce4a752dd8509f52cc630607b5ae32d74930747c47

Contents?: true

Size: 1.15 KB

Versions: 7

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true
module Qa::Authorities
  class FindWorks < Qa::Authorities::Base
    class_attribute :search_builder_class
    self.search_builder_class = Hyrax::My::FindWorksSearchBuilder

    def search(_q, controller)
      # The My::FindWorksSearchBuilder expects a current_user
      return [] unless controller.current_user

      response, _docs = search_response(controller)
      docs = response.documents
      docs.map do |doc|
        id = doc.id
        title = doc.title
        { id: id, label: title, value: id }
      end
    end

    private

    def search_service(controller)
      @search_service ||= Hyrax::SearchService.new(
        config: controller.blacklight_config,
        user_params: controller.params,
        search_builder_class: search_builder_class,
        scope: controller,
        current_ability: controller.current_ability
      )
    end

    def search_response(controller)
      access = controller.params[:access] || 'read'

      search_service(controller).search_results do |builder|
        builder.where(controller.params[:q])
               .with_access(access)
               .rows(100)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hyrax-3.2.0 app/authorities/qa/authorities/find_works.rb
hyrax-3.1.0 app/authorities/qa/authorities/find_works.rb
hyrax-3.0.2 app/authorities/qa/authorities/find_works.rb
hyrax-3.0.1 app/authorities/qa/authorities/find_works.rb
hyrax-3.0.0 app/authorities/qa/authorities/find_works.rb
hyrax-3.0.0.pre.rc4 app/authorities/qa/authorities/find_works.rb
hyrax-3.0.0.pre.rc3 app/authorities/qa/authorities/find_works.rb