Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make new aggregations searchable #131

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 %>"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see us dropping the .to_sym method here, and I'm not sure why. I'm sure it makes sense - my first assumption is because the values aren't convertible to symbols now, but were before. I'm just not sure I'm following what changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I should've been clearer in the commit message. That to_sym call was there because SearchController#extract_filters didn't always cast the filter keys as symbols. I refactored that method to do so a while back, but noticed while debugging this that there were still a couple of to_sym calls. I removed them to make this less confusing for our future selves (hopefully), but it's unrelated to the additional/customizable filters changeset.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, gotcha - that makes sense. Thanks!

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
Loading