Skip to content

Instantly share code, notes, and snippets.

@cfitz
Created November 1, 2016 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfitz/67f21316f5cb7a91ec30fc38ffafd157 to your computer and use it in GitHub Desktop.
Save cfitz/67f21316f5cb7a91ec30fc38ffafd157 to your computer and use it in GitHub Desktop.
# plugins/local/public/plugin_init.rb
Rails.application.config.after_initialize do
SearchController.class_eval do
private
def set_search_criteria
@criteria = params.select{|k,v|
["page", "q", "type", "sort",
"filter_term", "root_record", "format"].include?(k) and not v.blank?
}
@criteria["page"] ||= 1
@criteria["sort"] = "title_sort asc" unless @criteria["sort"] or @criteria["q"] or params["advanced"].present?
if @criteria["filter_term"]
@criteria["filter_term[]"] = Array(@criteria["filter_term"]).reject{|v| v.blank?}.map { |ft| ActionController::Base.helpers.sanitize(ft) }
@criteria.delete("filter_term")
end
if params[:type].blank?
@criteria['type[]'] = SearchController::DETAIL_TYPES
else
@criteria['type[]'] = Array(params[:type]).keep_if {|t| SearchController::VIEWABLE_TYPES.include?(t)}
@criteria.delete("type")
end
@criteria['exclude[]'] = params[:exclude] if not params[:exclude].blank?
@criteria['facet[]'] = SearchController::FACETS
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment