diff --git a/app/assets/stylesheets/partials/_panels.scss b/app/assets/stylesheets/partials/_panels.scss index e40cb284..03ae2e7b 100644 --- a/app/assets/stylesheets/partials/_panels.scss +++ b/app/assets/stylesheets/partials/_panels.scss @@ -99,3 +99,36 @@ } } } + +.filter-summary { + color: $black; + background-color: $gray-l3; + margin-top: 0; + border: 0; + padding: 2rem; + padding-top: 1.5rem; + display: flex; + .hd-filter-summary { + margin-right: 2rem; + padding-top: 0.3rem; + } + a { + font-size: $fs-small; + text-decoration: none; + padding: .5rem; + &::before { + font-family: FontAwesome; + content: '\f00d'; + padding-right: .25rem; + } + &:hover, + &:focus { + color: $white; + background-color: $black; + } + margin-right: 2rem; + } + @media (max-width: $bp-screen-md) { + display: block; + } +} diff --git a/app/assets/stylesheets/partials/_search.scss b/app/assets/stylesheets/partials/_search.scss index f8768cd5..cfba3f46 100644 --- a/app/assets/stylesheets/partials/_search.scss +++ b/app/assets/stylesheets/partials/_search.scss @@ -5,7 +5,7 @@ /* basic search bar */ .basic-search { background-color: #989898; - margin-bottom: 1rem; + margin-bottom: 0rem; padding: 1.6rem 2rem; details { diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 82d5bd67..636eb2f9 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -33,7 +33,11 @@ def extract_filters(response) aggs = response&.data&.search&.to_h&.dig('aggregations') return if aggs.blank? - aggs.select { |_, agg_values| agg_values.present? } + # We use aggregations to determine which terms can be filtered. However, agg names do not include 'filter', whereas + # our filter fields do (e.g., 'source' vs 'sourceFilter'). Because of this mismatch, we need to modify the + # aggregation key names before collecting them as filters, so that when a filter is applied, it searches the + # correct field name. + aggs.select { |_, agg_values| agg_values.present? }.transform_keys { |key| (key.dup << 'Filter').to_sym } end def extract_results(response) diff --git a/app/helpers/filter_helper.rb b/app/helpers/filter_helper.rb index fe17874d..8a558d3e 100644 --- a/app/helpers/filter_helper.rb +++ b/app/helpers/filter_helper.rb @@ -9,7 +9,7 @@ def add_filter(query, filter, term) # seems like the best solution as each record only has a single source # in the data so there will never be a case to apply multiple in an AND # which is all we support in filter application. - if new_query[filter].present? && filter != 'source' + if new_query[filter].present? && filter != :sourceFilter new_query[filter] << term new_query[filter].uniq! else @@ -21,8 +21,8 @@ def add_filter(query, filter, term) def nice_labels { - 'contentType' => 'Content types', - 'source' => 'Sources' + contentTypeFilter: 'Content type', + sourceFilter: 'Source' } end @@ -44,4 +44,14 @@ def filter_applied?(terms, term) terms.include?(term) end + + def applied_filters + filters = [] + @enhanced_query.map do |param, values| + next unless param.to_s.include? 'Filter' + + values.each { |value| filters << { param => value } } + end + filters + end end diff --git a/app/helpers/form_helper.rb b/app/helpers/form_helper.rb index 0c65bf12..61b76822 100644 --- a/app/helpers/form_helper.rb +++ b/app/helpers/form_helper.rb @@ -2,9 +2,8 @@ module FormHelper def source_checkbox(source, params) "
".html_safe diff --git a/app/models/enhancer.rb b/app/models/enhancer.rb index a9907c27..8945af7f 100644 --- a/app/models/enhancer.rb +++ b/app/models/enhancer.rb @@ -2,7 +2,7 @@ class Enhancer attr_accessor :enhanced_query QUERY_PARAMS = %i[q citation contentType contributors fundingInformation identifiers locations subjects title].freeze - FILTER_PARAMS = [:source].freeze + FILTER_PARAMS = %i[sourceFilter contentTypeFilter].freeze # accepts all params as each enhancer may require different data def initialize(params) @enhanced_query = {} diff --git a/app/models/query_builder.rb b/app/models/query_builder.rb index 5b7cbcdc..afb69c88 100644 --- a/app/models/query_builder.rb +++ b/app/models/query_builder.rb @@ -3,7 +3,7 @@ class QueryBuilder RESULTS_PER_PAGE = 20 QUERY_PARAMS = %w[q citation contributors fundingInformation identifiers locations subjects title].freeze - FILTER_PARAMS = %i[source contentType].freeze + FILTER_PARAMS = %i[sourceFilter contentTypeFilter].freeze def initialize(enhanced_query) @query = {} @@ -29,8 +29,8 @@ def extract_query(enhanced_query) end def extract_filters(enhanced_query) - # NOTE: ui and backend naming are not aligned so we can't loop here. we should fix in UI - @query['sourceFilter'] = enhanced_query[:source] - @query['contentType'] = enhanced_query[:contentType] + FILTER_PARAMS.each do |qp| + @query[qp] = enhanced_query[qp] + end end end diff --git a/app/models/timdex_search.rb b/app/models/timdex_search.rb index e310c09d..45e18d66 100644 --- a/app/models/timdex_search.rb +++ b/app/models/timdex_search.rb @@ -15,7 +15,7 @@ class TimdexSearch < TimdexBase $sourceFilter: [String!] $index: String $from: String - $contentType: [String!] + $contentTypeFilter: [String!] ) { search( searchterm: $q @@ -29,7 +29,7 @@ class TimdexSearch < TimdexBase sourceFilter: $sourceFilter index: $index from: $from - contentTypeFilter: $contentType + contentTypeFilter: $contentTypeFilter ) { hits records { diff --git a/app/views/search/_filter.html.erb b/app/views/search/_filter.html.erb index 0cc9f833..0cb5a6dc 100644 --- a/app/views/search/_filter.html.erb +++ b/app/views/search/_filter.html.erb @@ -1,4 +1,4 @@ -<% return if values.empty? %> +<% return if values.blank? %>