Module: Spotlight::BrowseCategorySearchBuilder

Extended by:
ActiveSupport::Concern
Included in:
SearchBuilder
Defined in:
app/models/concerns/spotlight/browse_category_search_builder.rb

Overview

Enforce exhibit visibility for index queries

Instance Method Summary collapse

Instance Method Details

#apply_browse_category_defaults(solr_params) ⇒ Object

Adds a filter that excludes resources that have been marked as not-visible



15
16
17
18
19
# File 'app/models/concerns/spotlight/browse_category_search_builder.rb', line 15

def apply_browse_category_defaults(solr_params)
  return unless current_browse_category

  solr_params.merge!(browse_category_search_builder.to_hash.except(:q))
end

#fix_up_browse_category_defaults(solr_params) ⇒ Object



21
22
23
24
25
# File 'app/models/concerns/spotlight/browse_category_search_builder.rb', line 21

def fix_up_browse_category_defaults(solr_params)
  return if current_browse_category.nil? || search_state.send(:sort_field_key).present?

  solr_params[:sort] = browse_category_search_builder.sort
end

#fix_up_browse_category_queries(solr_params) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/concerns/spotlight/browse_category_search_builder.rb', line 27

def fix_up_browse_category_queries(solr_params)
  return unless current_browse_category

  query = browse_category_search_builder.to_hash[:q]

  solr_params.append_query(query) if query.present?

  # for a browse category formed from a saved search, the query syntax reads as two "must" values
  # e.g.  "json"=>{"query"=>{"bool"=>{"must"=>["savedsearchterm", "browsecategorysearchterm"]}}}}
  must_values = solr_params.dig(:json, :query, :bool, :must)

  return unless must_values&.any?

  # this type of query must be parsed by lucene to function
  solr_params[:defType] = 'lucene'

  # This replicates existing spotlight 2.x search behavior, more or less. It
  # doesn't take into account the possibility that the browse category query
  # could use a different search field (which.. doesn't have an existing UI
  # control.. and may require additional upstream work to properly encapsulate
  # the two query parameters)
  must_values.map! do |q|
    q.is_a?(String) ? { edismax: { query: q } } : q
  end
end