Skip to content

Commit

Permalink
Merge pull request #179 from MITLibraries/gdt-309-implement-and-boole…
Browse files Browse the repository at this point in the history
…antype

Gdt 309 implement and booleantype
  • Loading branch information
JPrevost authored Apr 29, 2024
2 parents 30d6676 + 7dc46c0 commit eac446a
Show file tree
Hide file tree
Showing 67 changed files with 1,123 additions and 1,047 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ feature flag enabled, and do not when it is disabled.
- `ABOUT_APP`: If populated, an 'about' partial containing the contents of this variable will render on
`basic_search#index`.
- `ACTIVE_FILTERS`: If populated, this list of strings defines which filters are shown to the user, and the order in which they appear. Values are case sensitive, and must match the corresponding aggregations used in the TIMDEX GraphQL query. Extraneous values will be ignored. If not populated, all filters will be shown.
- `BOOLEAN_OPTIONS`: comma separated list of values to present to testers on instances where `BOOLEAN_PICKER` feature is enabled.
- `BOOLEAN_PICKER`: feature to allow users to select their preferred boolean type. If set, feature is enabled. This feature is only intended for internal team
testing and should never be enabled in production (mostly because the UI is a mess more than it would cause harm).
- `FILTER_ACCESS_TO_FILES`: The name to use instead of "Access to files" for that filter / aggregation.
- `FILTER_CONTENT_TYPE`: The name to use instead of "Content type" for that filter / aggregation.
- `FILTER_CONTRIBUTOR`: The name to use instead of "Contributor" for that filter / aggregation.
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class SearchController < ApplicationController
end

def results
# inject session preference for boolean type if it is present
params[:booleanType] = cookies[:boolean_type] || 'AND'

# hand off to Enhancer chain
@enhanced_query = Enhancer.new(params).enhanced_query

Expand Down
10 changes: 10 additions & 0 deletions app/controllers/static_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
class StaticController < ApplicationController
def style_guide; end

def boolpref
if params[:boolean_type].present?
cookies[:boolean_type] = params[:boolean_type]
else
cookies.delete :boolean_type
end

redirect_back_or_to root_path
end
end
1 change: 1 addition & 0 deletions app/models/enhancer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def initialize(params)
@enhanced_query = {}
@enhanced_query[:page] = calculate_page(params[:page].to_i)
@enhanced_query[:advanced] = 'true' if params[:advanced].present?
@enhanced_query[:booleanType] = params[:booleanType] || 'AND'

if Flipflop.enabled?(:gdt)
@enhanced_query[:geobox] = 'true' if params[:geobox] == 'true'
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 @@ -2,7 +2,7 @@ class QueryBuilder
attr_reader :query

RESULTS_PER_PAGE = 20
QUERY_PARAMS = %w[q citation contributors fundingInformation identifiers locations subjects title].freeze
QUERY_PARAMS = %w[q citation contributors fundingInformation identifiers locations subjects title booleanType].freeze
FILTER_PARAMS = %i[accessToFilesFilter contentTypeFilter contributorsFilter formatFilter languagesFilter
literaryFormFilter placesFilter sourceFilter subjectsFilter].freeze
GEO_PARAMS = %w[geoboxMinLongitude geoboxMinLatitude geoboxMaxLongitude geoboxMaxLatitude geodistanceLatitude
Expand All @@ -21,6 +21,7 @@ def initialize(enhanced_query)
extract_geosearch(enhanced_query)
extract_filters(enhanced_query)
@query['index'] = ENV.fetch('TIMDEX_INDEX', nil)
@query['booleanType'] = enhanced_query[:booleanType]
@query.compact!
end

Expand Down
16 changes: 12 additions & 4 deletions app/models/timdex_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'graphql/client/http'

class TimdexSearch < TimdexBase
BaseQuery = TimdexBase::Client.parse <<-'GRAPHQL'
BaseQuery = TimdexBase::Client.parse <<-GRAPHQL
query(
$q: String
$citation: String
Expand All @@ -14,6 +14,7 @@ class TimdexSearch < TimdexBase
$title: String
$index: String
$from: String
$booleanType: String
$accessToFilesFilter: [String!]
$contentTypeFilter: [String!]
$contributorsFilter: [String!]
Expand All @@ -35,6 +36,7 @@ class TimdexSearch < TimdexBase
title: $title
index: $index
from: $from
booleanType: $booleanType
accessToFilesFilter: $accessToFilesFilter
contentTypeFilter: $contentTypeFilter
contributorsFilter: $contributorsFilter
Expand Down Expand Up @@ -124,7 +126,7 @@ class TimdexSearch < TimdexBase
}
GRAPHQL

GeoboxQuery = TimdexBase::Client.parse <<-'GRAPHQL'
GeoboxQuery = TimdexBase::Client.parse <<-GRAPHQL
query(
$q: String
$citation: String
Expand All @@ -136,6 +138,7 @@ class TimdexSearch < TimdexBase
$title: String
$index: String
$from: String
$booleanType: String
$geoboxMinLatitude: Float!
$geoboxMinLongitude: Float!
$geoboxMaxLatitude: Float!
Expand All @@ -160,6 +163,7 @@ class TimdexSearch < TimdexBase
title: $title
index: $index
from: $from
booleanType: $booleanType
geobox: {
minLongitude: $geoboxMinLongitude,
minLatitude: $geoboxMinLatitude,
Expand Down Expand Up @@ -250,7 +254,7 @@ class TimdexSearch < TimdexBase
}
GRAPHQL

GeodistanceQuery = TimdexBase::Client.parse <<-'GRAPHQL'
GeodistanceQuery = TimdexBase::Client.parse <<-GRAPHQL
query(
$q: String
$citation: String
Expand All @@ -262,6 +266,7 @@ class TimdexSearch < TimdexBase
$title: String
$index: String
$from: String
$booleanType: String
$accessToFilesFilter: [String!]
$geodistanceDistance: String!
$geodistanceLatitude: Float!
Expand All @@ -285,6 +290,7 @@ class TimdexSearch < TimdexBase
title: $title
index: $index
from: $from
booleanType: $booleanType
geodistance: {
distance: $geodistanceDistance,
latitude: $geodistanceLatitude,
Expand Down Expand Up @@ -374,7 +380,7 @@ class TimdexSearch < TimdexBase
}
GRAPHQL

AllQuery = TimdexBase::Client.parse <<-'GRAPHQL'
AllQuery = TimdexBase::Client.parse <<-GRAPHQL
query(
$q: String
$citation: String
Expand All @@ -386,6 +392,7 @@ class TimdexSearch < TimdexBase
$title: String
$index: String
$from: String
$booleanType: String
$accessToFilesFilter: [String!]
$geodistanceDistance: String!
$geodistanceLatitude: Float!
Expand Down Expand Up @@ -413,6 +420,7 @@ class TimdexSearch < TimdexBase
title: $title
index: $index
from: $from
booleanType: $booleanType
geodistance: {
distance: $geodistanceDistance,
latitude: $geodistanceLatitude,
Expand Down
21 changes: 21 additions & 0 deletions app/views/search/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,25 @@ end
</div>
</form>

<% if Flipflop.enabled?(:boolean_picker) %>
<aside class="panel panel-info">
<div class="panel-heading">
<% if cookies[:boolean_type].present? %>
<p>Your boolean preference for this session is: <%= cookies[:boolean_type] %></p>
<% else %>
<p>No preference is set. Default boolean preference (`AND`) is enabled.</p>
<% end %>
</div>
<div class="panel-body">
<p>Change to:</p>
<ul>
<% ENV.fetch('BOOLEAN_OPTIONS', 'AND,OR').split(',').each do |opt| %>
<li><%= link_to(opt, boolpref_path(boolean_type: opt)) %></li>
<% end %>
<li><%= link_to('Clear preference', boolpref_path()) %></li>
</ul>
</div>
</aside>
<% end %>
<%= javascript_include_tag "search_form" %>
4 changes: 4 additions & 0 deletions config/features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
feature :gdt,
default: ENV.fetch('GDT', false),
description: "Enable geodata discovery features."

feature :boolean_picker,
default: ENV.fetch('BOOLEAN_PICKER', false),
description: "Enable user configurable boolean type selection."
end
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@
:constraints => { :id => /[0-z\.\-\_~\(\)]+/ }
get 'results', to: 'search#results'
get 'style-guide', to: 'static#style_guide'

get 'boolpref', to: 'static#boolpref'
end
10 changes: 10 additions & 0 deletions config/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,16 @@
},
"defaultValue": "null"
},
{
"name": "booleanType",
"description": "How to join multiword queries. Defaults to \"OR\" which means any of the words much match. Options include: \"OR\", \"AND\", \"minimum_a\"",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": "\"OR\""
},
{
"name": "accessToFilesFilter",
"description": "Filter results by access type. Use the `AccessToFiles` aggregation for a list of possible values. Multiple values are ORed.",
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/application_helper_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class FilterHelperTest < ActionView::TestCase
class ApplicationHelperTest < ActionView::TestCase
include ApplicationHelper

test 'index_page_title renders as expected' do
Expand Down
42 changes: 21 additions & 21 deletions test/vcr_cassettes/advanced.yml

Large diffs are not rendered by default.

36 changes: 18 additions & 18 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.

36 changes: 18 additions & 18 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 eac446a

Please sign in to comment.