Skip to content

Commit 535210d

Browse files
authored
Merge pull request #1141 from MITLibraries/timx-174-deprecated-timdex-fields
Update Bento to use TIMDEX V2 fields
2 parents 28df205 + 7cf2411 commit 535210d

File tree

9 files changed

+272
-300
lines changed

9 files changed

+272
-300
lines changed

app/models/normalize_timdex.rb

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def extract_results(results, norm)
2424
result_title = extract_title(record)
2525
result = Result.new(result_title, record['sourceLink'])
2626
result.blurb = extract_first_from_list(record['summary'])
27-
result.year = extract_field(record['publicationDate'])
27+
result.year = extract_dates(record['dates'])
2828
result.authors = extract_field(extract_list(record['contributors']))
2929
result.physical_description = extract_field(record['physicalDescription'])
3030
norm['results'] << result
@@ -33,10 +33,36 @@ def extract_results(results, norm)
3333

3434
def extract_title(record)
3535
title = record['title']
36-
title << (" (#{record['identifier'].to_s.gsub('MIT:archivespace:', '')})") if record['identifier'].present?
36+
title << extract_collection_id(record['identifiers']) if record['identifiers'].present?
3737
title
3838
end
3939

40+
def extract_dates(dates)
41+
# It is unlikely for a record to have more than one creation date, but just in case...
42+
relevant_dates = dates.select { |date| date['kind'] == 'creation' }
43+
44+
# If the record *does* have more than one creation date, it's probably not worth determining which to display.
45+
return if relevant_dates.count > 1
46+
47+
relevant_date = relevant_dates.first
48+
49+
# We are only concerned with creation dates that are ranges, since we harvest ASpace metadata at the collection
50+
# level.
51+
return unless relevant_date['kind'] == 'creation' && relevant_date['range'].present?
52+
53+
"#{relevant_date['range']['gte']}-#{relevant_date['range']['lte']}"
54+
end
55+
56+
def extract_collection_id(identifiers)
57+
relevant_ids = identifiers.map { |id| id['value'] if id['kind'] == 'Collection Identifier' }.compact
58+
59+
# In the highly unlikely event that there is more than one collection identifier, there's something weird going
60+
# on with the record and we should skip it.
61+
return if relevant_ids.count > 1
62+
63+
" (#{relevant_ids.first})"
64+
end
65+
4066
def extract_list(contributors)
4167
contributors&.map do |creator|
4268
[creator['value'], '&field[]=creators_text&q[]=' << URI.encode_www_form_component(creator['value'])]

app/models/search_timdex.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def initialize
2323
# @param term [string] The string we are searching for
2424
# @return [Hash] A Hash with search metadata and an Array of {Result}s
2525
def search(term)
26-
@query = '{"query":"{search(searchterm: \"' + clean_term(term) + '\", source: \"MIT ArchivesSpace\") {hits records {sourceLink title identifier publicationDate physicalDescription summary contributors { value } } } }"}'
26+
@query = '{ "query": "{ search(searchterm: \"' + clean_term(term) + '\", sourceFilter: \"MIT ArchivesSpace\") { hits records { sourceLink title identifiers { kind value } dates { kind value range { gte lte } } physicalDescription summary contributors { value } } } }"}'
2727
results = @timdex_http.timeout(http_timeout)
2828
.post(TIMDEX_URL, body: @query)
2929
json_result = JSON.parse(results.to_s)

config/environments/test.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require "active_support/core_ext/integer/time"
1+
require 'active_support/core_ext/integer/time'
22

33
# The test environment is used exclusively to run your application's
44
# test suite. You never need to work with it otherwise. Remember that
@@ -14,6 +14,7 @@
1414
ENV['FLIPFLOP_KEY'] = 'yoyo'
1515
ENV['ALMA_OPENURL'] = 'https://na06.alma.exlibrisgroup.com/view/uresolver/01MIT_INST/openurl?'
1616
ENV['ALMA_SRU'] = 'https://mit.alma.exlibrisgroup.com/view/sru/01MIT_INST?version=1.2&operation=searchRetrieve&recordSchema=marcxml&query=alma.all_for_ui='
17+
ENV['ASPACE_SEARCH_URI'] = 'https://archivesspace.mit.edu/search?op[]=&field[]=creators_text&q[]='
1718
ENV['EXL_INST_ID'] = '01MIT_INST'
1819
ENV['PRIMO_SEARCH'] = 'true'
1920
ENV['PRIMO_API_URL'] = 'https://another_fake_server.example.com/v1'
@@ -26,7 +27,7 @@
2627
ENV['PRIMO_SPLASH_PAGE'] = 'https://libraries.mit.edu/news/library-platform-before/32066/'
2728
ENV['MIT_PRIMO_URL'] = 'https://mit.primo.exlibrisgroup.com'
2829
ENV['SYNDETICS_PRIMO_URL'] = 'https://syndetics.com/index.php?client=primo'
29-
ENV['TIMDEX_URL']='https://timdex.mit.edu/graphql'
30+
ENV['TIMDEX_URL'] = 'https://timdex.mit.edu/graphql'
3031

3132
# Turn false under Spring and add config.action_view.cache_template_loading = true.
3233
config.cache_classes = true

test/integration/search_test.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,13 @@ def teardown
7070
end
7171

7272
test 'timdex results are populated' do
73-
VCR.use_cassette('popcorn timdex',
73+
VCR.use_cassette('aspace timdex',
7474
allow_playback_repeats: true) do
75-
get '/search/search_boxed?q=popcorn&target=timdex'
75+
get '/search/search_boxed?q=archives&target=timdex'
7676
assert_response :success
77+
assert_select 'a.bento-link' do |value|
78+
assert value.text.include? 'Paul Earls'
79+
end
7780
end
7881
end
7982

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
require 'test_helper'
22

33
class NormalizeTimdexTest < ActiveSupport::TestCase
4-
def timdex_records
5-
VCR.use_cassette('popcorn timdex',
6-
allow_playback_repeats: true) do
7-
raw_query = SearchTimdex.new.search('popcorn')
8-
NormalizeTimdex.new.to_result(raw_query, 'popcorn')
9-
end
10-
end
11-
124
def aspace_records
135
VCR.use_cassette('aspace timdex',
146
allow_playback_repeats: true) do
@@ -17,30 +9,9 @@ def aspace_records
179
end
1810
end
1911

20-
test 'normalized timdex records have expected title' do
21-
assert_equal(
22-
'Popcorn Venus /',
23-
timdex_records['results'][0].title
24-
)
25-
end
26-
27-
test 'normalized timdex records have expected url' do
28-
assert_equal(
29-
'https://library.mit.edu/item/000346597',
30-
timdex_records['results'][0].url
31-
)
32-
end
33-
34-
test 'normalized timdex records have expected record count' do
35-
assert_equal(
36-
115,
37-
timdex_records['total']
38-
)
39-
end
40-
4112
test 'normalized aspace records have an identifier in the title' do
4213
assert_match(
43-
'AC.0129',
14+
'MC.0552',
4415
aspace_records['results'][0].title
4516
)
4617
end
@@ -51,4 +22,18 @@ def aspace_records
5122
aspace_records['results'][0].physical_description
5223
)
5324
end
25+
26+
test 'normalized aspace records have a creation date range' do
27+
assert_equal '1914-1998', aspace_records['results'][0].year
28+
end
29+
30+
test 'normalized aspace records have an array of contributors' do
31+
assert aspace_records['results'][0].authors.is_a? Array
32+
assert_equal 'Earls, Paul, 1934-1998', aspace_records['results'][0].authors[0][0]
33+
end
34+
35+
test 'normalized aspace records have a summary' do
36+
assert_match 'The Paul Earls archives contains a large number of music manuscript',
37+
aspace_records['results'][0].blurb
38+
end
5439
end

test/models/search_timdex_test.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ def after
1010
end
1111

1212
test 'can search timdex' do
13-
VCR.use_cassette('popcorn timdex',
13+
VCR.use_cassette('aspace timdex',
1414
allow_playback_repeats: true) do
15-
query = SearchTimdex.new.search('popcorn')
16-
assert_equal(Hash, query.class)
15+
response = SearchTimdex.new.search('archives')
16+
assert_equal Hash, response.class
17+
assert response['data']['search']['hits'] > 0
1718
end
1819
end
1920

0 commit comments

Comments
 (0)