Class: Hyrax::Dashboard::NestedCollectionsSearchBuilder

Inherits:
CollectionSearchBuilder show all
Defined in:
app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb

Overview

Responsible for searching for collections of the same type that are not the given collection

Instance Attribute Summary collapse

Attributes inherited from CollectionSearchBuilder

#access

Instance Method Summary collapse

Methods inherited from CollectionSearchBuilder

#add_sorting_to_solr, #gated_discovery_filters, #models, #sort_field, #with_access

Methods included from FilterByType

#filter_models

Constructor Details

#initialize(access:, collection:, scope:, nest_direction:) ⇒ NestedCollectionsSearchBuilder

Returns a new instance of NestedCollectionsSearchBuilder.

Parameters:

  • access (Symbol)

    :edit, :read, :discover - With the given :access what all can

  • collection (::Collection)
  • scope (Object)

    Typically a controller that responds to #current_ability, #blackligh_config

  • nest_direction (Symbol)

    (:as_parent or :as_child) the direction we are adding nesting to this collection



10
11
12
13
14
15
# File 'app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb', line 10

def initialize(access:, collection:, scope:, nest_direction:)
  super(scope)
  @collection = collection
  @discovery_permissions = extract_discovery_permissions(access)
  @nest_direction = nest_direction
end

Instance Attribute Details

#discovery_permissionsObject (readonly)

Override for Hydra::AccessControlsEnforcement



18
19
20
# File 'app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb', line 18

def discovery_permissions
  @discovery_permissions
end

Instance Method Details

#show_only_other_collections_of_the_same_collection_type(solr_parameters) ⇒ Object

Solr can do graph traversal without the need of special indexing with the Graph query parser so use this to compute both the parents and children of the current collection then exclude them See solr.apache.org/guide/solr/latest/query-guide/other-parsers.html#graph-query-parser



28
29
30
31
32
33
34
35
# File 'app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb', line 28

def show_only_other_collections_of_the_same_collection_type(solr_parameters)
  solr_parameters[:fq] ||= []
  solr_parameters[:fq] += [
    Hyrax::SolrQueryBuilderService.construct_query(Hyrax.config.collection_type_index_field => @collection.collection_type_gid),
    "-{!graph from=id to=member_of_collection_ids_ssim#{' maxDepth=1' if @nest_direction == :as_parent}}id:#{@collection.id}",
    "-{!graph to=id from=member_of_collection_ids_ssim#{' maxDepth=1' if @nest_direction == :as_child}}id:#{@collection.id}"
  ]
end

#with_pagination(solr_parameters) ⇒ Object



21
22
23
# File 'app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb', line 21

def with_pagination(solr_parameters)
  solr_parameters[:rows] = 1000
end