Skip to content

Commit

Permalink
New style replaces old filter models approach
Browse files Browse the repository at this point in the history
Search builder base is aware of `models` now.
  • Loading branch information
atz committed Nov 29, 2016
1 parent 61b8d5c commit 5ffbd9a
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions app/search_builders/curation_concerns/collection_search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,30 @@ module CurationConcerns
#
class CollectionSearchBuilder < ::SearchBuilder
include FilterByType

# Defines which search_params_logic should be used when searching for Collections
# @param [#blacklight_config, #current_ability] scope the object that has access to #blacklight_config
# From a controller, scope would be `self`. This argument is passed to ::SearchBuilder.new()
# @note permissions will otherwise be defaulted by inherited #discovery_permissions
# @see @discovery_permissions
def initialize(context)
@rows = 100
super(context)
end

# @return [String] class URI of the model, as indexed in Solr has_model_ssim field
def model_class_uri
::Collection.to_class_uri
# @!group Overrides
#
# @return [Class] ActiveFedora model(s) indexed in Solr has_model_ssim field
def models
[::Collection]
end

# @return [String] Solr field name indicating default sort order
def sort_field
Solrizer.solr_name('title', :sortable)
end

# @return [Hash{Symbol => Array[Symbol]}] bottom-up map of "what you need" to "what qualifies"
# @note i.e., requiring :read access is satisfied by either :read or :edit access
def access_levels
{ read: [:read, :edit], edit: [:edit] }
end
# @!endgroup

attr_writer :discovery_perms # TODO: remove this line
## Overrides
Expand All @@ -39,17 +42,19 @@ def discovery_permissions
@discovery_perms || super
end

# This overrides the filter_models in FilterByType
def filter_models(solr_parameters)
solr_parameters[:fq] ||= []
solr_parameters[:fq] << ActiveFedora::SolrQueryBuilder.construct_query_for_rel(has_model: model_class_uri)
end

# Sort results by title if no query was supplied.
# This overrides the default 'relevance' sort.
def add_sorting_to_solr(solr_parameters)
return if solr_parameters[:q]
solr_parameters[:sort] ||= "#{sort_field} asc"
end

private

# @return [Hash{Symbol => Array[Symbol]}] bottom-up map of "what you need" to "what qualifies"
# @note i.e., requiring :read access is satisfied by either :read or :edit access
def access_levels
{ read: [:read, :edit], edit: [:edit] }
end
end
end

0 comments on commit 5ffbd9a

Please sign in to comment.