Skip to content

Commit

Permalink
Make new aggregations searchable
Browse files Browse the repository at this point in the history
Why these changes are being introduced:

We added some more aggregations as part of the ongoing work, but

Relevant ticket(s):

* (GDT-128)[https://mitlibraries.atlassian.net/browse/GDT-128]

How this addresses that need:

This adds the new aggregations to the Enhancer and QueryBuilder models,
and adds them to the query in the TimdexSearch model.

Side effects of this change:

* VCR cassettes have been regenerated.
* In the filter partial, `to_sym` calls on the filter category have
been removed. These are no longer needed as all filter categories
are cast as symbols in the search controller.
* This is another instance of something that has come up recently:
the need to develop an E2E testing strategy for our Rails apps,
particularly those that are API consumers. We can test this using
our standard VCR process, but that is likely to break when
cassettes are regenerated and the search results change.
  • Loading branch information
jazairi committed Mar 7, 2024
1 parent dbd64b9 commit a22a8d1
Show file tree
Hide file tree
Showing 32 changed files with 470 additions and 421 deletions.
4 changes: 3 additions & 1 deletion app/models/enhancer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ class Enhancer
attr_accessor :enhanced_query

QUERY_PARAMS = %i[q citation contentType contributors fundingInformation identifiers locations subjects title].freeze
FILTER_PARAMS = %i[sourceFilter contentTypeFilter].freeze
FILTER_PARAMS = %i[contentTypeFilter contributorsFilter formatFilter languagesFilter literaryFormFilter sourceFilter
subjectsFilter].freeze

# accepts all params as each enhancer may require different data
def initialize(params)
@enhanced_query = {}
Expand Down
3 changes: 2 additions & 1 deletion app/models/query_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ class QueryBuilder

RESULTS_PER_PAGE = 20
QUERY_PARAMS = %w[q citation contributors fundingInformation identifiers locations subjects title].freeze
FILTER_PARAMS = %i[sourceFilter contentTypeFilter].freeze
FILTER_PARAMS = %i[contentTypeFilter contributorsFilter formatFilter languagesFilter literaryFormFilter sourceFilter
subjectsFilter].freeze

def initialize(enhanced_query)
@query = {}
Expand Down
14 changes: 12 additions & 2 deletions app/models/timdex_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ class TimdexSearch < TimdexBase
$locations: String
$subjects: String
$title: String
$sourceFilter: [String!]
$index: String
$from: String
$contentTypeFilter: [String!]
$contributorsFilter: [String!]
$formatFilter: [String!]
$languagesFilter: [String!]
$literaryFormFilter: String
$sourceFilter: [String!]
$subjectsFilter: [String!]
) {
search(
searchterm: $q
Expand All @@ -26,10 +31,15 @@ class TimdexSearch < TimdexBase
locations: $locations
subjects: $subjects
title: $title
sourceFilter: $sourceFilter
index: $index
from: $from
contentTypeFilter: $contentTypeFilter
contributorsFilter: $contributorsFilter
formatFilter: $formatFilter
languagesFilter: $languagesFilter
literaryFormFilter: $literaryFormFilter
sourceFilter: $sourceFilter
subjectsFilter: $subjectsFilter
) {
hits
records {
Expand Down
6 changes: 3 additions & 3 deletions app/views/search/_filter.html.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<% return if values.blank? %>

<div class="category">
<button class="filter-label <%= 'expanded' if @enhanced_query[category.to_sym].present? || first == true %>"
<button class="filter-label <%= 'expanded' if @enhanced_query[category].present? || first == true %>"
onclick="toggleFilter(this)"><%= nice_labels[category] || category %></button>
<div class="filter-options">
<ul class="category-terms list-unbulleted">
<% values.each do |term| %>
<li class="term">
<% if filter_applied?(@enhanced_query[category.to_sym], term['key']) %>
<a href="<%= results_path(remove_filter(@enhanced_query, category.to_sym, term['key'])) %>" class="applied">
<a href="<%= results_path(remove_filter(@enhanced_query, category, term['key'])) %>" class="applied">
<span class="sr">Remove applied filter?</span>
<% else %>
<a href="<%= results_path(add_filter(@enhanced_query, category.to_sym, term['key'])) %>">
<a href="<%= results_path(add_filter(@enhanced_query, category, term['key'])) %>">
<% end %>
<span class="name"><%= term['key'] %></span>
<span class="count"><%= term['docCount'] %> <span class="sr">records</span></span>
Expand Down
36 changes: 19 additions & 17 deletions test/vcr_cassettes/advanced.yml

Large diffs are not rendered by default.

42 changes: 23 additions & 19 deletions test/vcr_cassettes/advanced_all.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 16 additions & 14 deletions test/vcr_cassettes/advanced_all_spaces.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 16 additions & 14 deletions test/vcr_cassettes/advanced_citation_asdf.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a22a8d1

Please sign in to comment.