Class: Hyrax::CatalogSearchBuilder

Inherits:
SearchBuilder show all
Defined in:
app/search_builders/hyrax/catalog_search_builder.rb

Overview

The default Blacklight catalog ‘search_builder_class` for Hyrax.

Use of this builder is configured in the ‘CatalogController` generated by Hyrax’s install task.

If you plan to customize the base catalog search builder behavior (e.g. by adding a mixin module provided by a blacklight extension gem), inheriting this

class, customizing behavior, and reconfiguring `CatalogController` is the

preferred mechanism.

Examples:

extending and customizing SearchBuilder

class MyApp::CustomCatalogSearchBuilder < Hyrax::CatalogSearchBuilder
  include BlacklightRangeLimit::RangeLimitBuilder
  # and/or other extensions
end

class CatalogController < ApplicationController
  # ...
  configure_blacklight do |config|
    config.search_builder_class = MyApp::CustomCatalogSearchBuilder
  # ...
  end
  # ...
end

See Also:

Instance Method Summary collapse

Instance Method Details

#filter_collection_facet_for_access(solr_parameters) ⇒ Object

only return facet counts for collections that this user has access to see



53
54
55
56
57
58
59
60
61
62
# File 'app/search_builders/hyrax/catalog_search_builder.rb', line 53

def filter_collection_facet_for_access(solr_parameters)
  return if current_ability.admin?

  collection_ids = Hyrax::Collections::PermissionsService.collection_ids_for_view(ability: current_ability).map { |id| "^#{id}$" }
  solr_parameters['f.member_of_collection_ids_ssim.facet.matches'] = if collection_ids.present?
                                                                       collection_ids.join('|')
                                                                     else
                                                                       "^$"
                                                                     end
end

#show_only_active_records(solr_parameters) ⇒ Object

show works that are in the active state.



47
48
49
50
# File 'app/search_builders/hyrax/catalog_search_builder.rb', line 47

def show_only_active_records(solr_parameters)
  solr_parameters[:fq] ||= []
  solr_parameters[:fq] << '-suppressed_bsi:true'
end

#show_works_or_works_that_contain_files(solr_parameters) ⇒ Object

show both works that match the query and works that contain files that match the query



39
40
41
42
43
44
# File 'app/search_builders/hyrax/catalog_search_builder.rb', line 39

def show_works_or_works_that_contain_files(solr_parameters)
  return if blacklight_params[:q].blank? || blacklight_params[:search_field] != 'all_fields'
  solr_parameters[:user_query] = blacklight_params[:q]
  solr_parameters[:q] = new_query
  solr_parameters[:defType] = 'lucene'
end