Skip to content

Commit f5e9f43

Browse files
committed
Make new aggregations searchable
Why these changes are being introduced: We added some more aggregations as part of the ongoing work, but did not add them to the query string or corresponding models. 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.
1 parent dbd64b9 commit f5e9f43

32 files changed

+470
-421
lines changed

app/models/enhancer.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ class Enhancer
22
attr_accessor :enhanced_query
33

44
QUERY_PARAMS = %i[q citation contentType contributors fundingInformation identifiers locations subjects title].freeze
5-
FILTER_PARAMS = %i[sourceFilter contentTypeFilter].freeze
5+
FILTER_PARAMS = %i[contentTypeFilter contributorsFilter formatFilter languagesFilter literaryFormFilter sourceFilter
6+
subjectsFilter].freeze
7+
68
# accepts all params as each enhancer may require different data
79
def initialize(params)
810
@enhanced_query = {}

app/models/query_builder.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ class QueryBuilder
33

44
RESULTS_PER_PAGE = 20
55
QUERY_PARAMS = %w[q citation contributors fundingInformation identifiers locations subjects title].freeze
6-
FILTER_PARAMS = %i[sourceFilter contentTypeFilter].freeze
6+
FILTER_PARAMS = %i[contentTypeFilter contributorsFilter formatFilter languagesFilter literaryFormFilter sourceFilter
7+
subjectsFilter].freeze
78

89
def initialize(enhanced_query)
910
@query = {}

app/models/timdex_search.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ class TimdexSearch < TimdexBase
1212
$locations: String
1313
$subjects: String
1414
$title: String
15-
$sourceFilter: [String!]
1615
$index: String
1716
$from: String
1817
$contentTypeFilter: [String!]
18+
$contributorsFilter: [String!]
19+
$formatFilter: [String!]
20+
$languagesFilter: [String!]
21+
$literaryFormFilter: String
22+
$sourceFilter: [String!]
23+
$subjectsFilter: [String!]
1924
) {
2025
search(
2126
searchterm: $q
@@ -26,10 +31,15 @@ class TimdexSearch < TimdexBase
2631
locations: $locations
2732
subjects: $subjects
2833
title: $title
29-
sourceFilter: $sourceFilter
3034
index: $index
3135
from: $from
3236
contentTypeFilter: $contentTypeFilter
37+
contributorsFilter: $contributorsFilter
38+
formatFilter: $formatFilter
39+
languagesFilter: $languagesFilter
40+
literaryFormFilter: $literaryFormFilter
41+
sourceFilter: $sourceFilter
42+
subjectsFilter: $subjectsFilter
3343
) {
3444
hits
3545
records {

app/views/search/_filter.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<% return if values.blank? %>
22

33
<div class="category">
4-
<button class="filter-label <%= 'expanded' if @enhanced_query[category.to_sym].present? || first == true %>"
4+
<button class="filter-label <%= 'expanded' if @enhanced_query[category].present? || first == true %>"
55
onclick="toggleFilter(this)"><%= nice_labels[category] || category %></button>
66
<div class="filter-options">
77
<ul class="category-terms list-unbulleted">
88
<% values.each do |term| %>
99
<li class="term">
1010
<% if filter_applied?(@enhanced_query[category.to_sym], term['key']) %>
11-
<a href="<%= results_path(remove_filter(@enhanced_query, category.to_sym, term['key'])) %>" class="applied">
11+
<a href="<%= results_path(remove_filter(@enhanced_query, category, term['key'])) %>" class="applied">
1212
<span class="sr">Remove applied filter?</span>
1313
<% else %>
14-
<a href="<%= results_path(add_filter(@enhanced_query, category.to_sym, term['key'])) %>">
14+
<a href="<%= results_path(add_filter(@enhanced_query, category, term['key'])) %>">
1515
<% end %>
1616
<span class="name"><%= term['key'] %></span>
1717
<span class="count"><%= term['docCount'] %> <span class="sr">records</span></span>

test/vcr_cassettes/advanced.yml

Lines changed: 19 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/vcr_cassettes/advanced_all.yml

Lines changed: 23 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/vcr_cassettes/advanced_all_spaces.yml

Lines changed: 16 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/vcr_cassettes/advanced_citation_asdf.yml

Lines changed: 16 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)