Skip to content

Commit c8138cb

Browse files
committed
TIMDEX highlight to sym
1 parent cf25329 commit c8138cb

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

app/helpers/search_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ def displayed_fields
44
end
55

66
def trim_highlights(result)
7-
return unless result['highlight']&.any?
7+
return unless result[:highlight]&.any?
88

9-
result['highlight'].reject { |h| displayed_fields.include? h['matchedField'] }
9+
result[:highlight].reject { |h| displayed_fields.include? h['matchedField'] }
1010
end
1111

1212
def format_highlight_label(field_name)

app/models/normalize_timdex_record.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def normalize
2424
content_type:,
2525
dates:,
2626
contributors:,
27-
'highlight' => highlight,
27+
highlight:,
2828
'source_link' => source_link
2929
}
3030
end

app/views/search/_result_geo.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
</p>
2626
<% end %>
2727

28-
<% if result_geo['highlight'] %>
28+
<% if result_geo[:highlight] %>
2929
<div class="result-highlights">
30-
<%= render partial: 'search/highlights', locals: { result: { 'highlight' => result_geo['highlight'] } } %>
30+
<%= render partial: 'search/highlights', locals: { result: { highlight: result_geo[:highlight] } } %>
3131
</div>
3232
<% end %>
3333

test/helpers/search_helper_test.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ class SearchHelperTest < ActionView::TestCase
44
include SearchHelper
55

66
test 'removes displayed fields from highlights' do
7-
result = { 'highlight' => [{ 'matchedField' => 'title', 'matchedPhrases' => 'Very important data' },
8-
{ 'matchedField' => 'title.exact_value', 'matchedPhrases' => 'Very important data' },
9-
{ 'matchedField' => 'content_type', 'matchedPhrases' => 'Dataset' },
10-
{ 'matchedField' => 'dates.value', 'matchedPhrases' => '2022' },
11-
{ 'matchedField' => 'contributors.value', 'matchedPhrases' => 'Jane Datascientist' }] }
7+
result = { highlight: [{ 'matchedField' => 'title', 'matchedPhrases' => 'Very important data' },
8+
{ 'matchedField' => 'title.exact_value', 'matchedPhrases' => 'Very important data' },
9+
{ 'matchedField' => 'content_type', 'matchedPhrases' => 'Dataset' },
10+
{ 'matchedField' => 'dates.value', 'matchedPhrases' => '2022' },
11+
{ 'matchedField' => 'contributors.value', 'matchedPhrases' => 'Jane Datascientist' }] }
1212
assert_empty trim_highlights(result)
1313
end
1414

1515
test 'does not remove undisplayed fields from highlights' do
16-
result = { 'highlight' => [{ 'matchedField' => 'summary', 'matchedPhrases' => 'Have some data' }] }
16+
result = { highlight: [{ 'matchedField' => 'summary', 'matchedPhrases' => 'Have some data' }] }
1717
assert_equal [{ 'matchedField' => 'summary', 'matchedPhrases' => 'Have some data' }], trim_highlights(result)
1818
end
1919

2020
test 'returns correct set of highlights when result includes displayed and undisplayed fields' do
21-
result = { 'highlight' => [{ 'matchedField' => 'title', 'matchedPhrases' => 'Very important data' },
22-
{ 'matchedField' => 'content_type', 'matchedPhrases' => 'Dataset' },
23-
{ 'matchedField' => 'summary', 'matchedPhrases' => '2022' },
24-
{ 'matchedField' => 'citation', 'matchedPhrases' => 'Datascientist, Jane' }] }
21+
result = { highlight: [{ 'matchedField' => 'title', 'matchedPhrases' => 'Very important data' },
22+
{ 'matchedField' => 'content_type', 'matchedPhrases' => 'Dataset' },
23+
{ 'matchedField' => 'summary', 'matchedPhrases' => '2022' },
24+
{ 'matchedField' => 'citation', 'matchedPhrases' => 'Datascientist, Jane' }] }
2525
assert_equal [{ 'matchedField' => 'summary', 'matchedPhrases' => '2022' },
2626
{ 'matchedField' => 'citation', 'matchedPhrases' => 'Datascientist, Jane' }], trim_highlights(result)
2727
end

test/models/normalize_timdex_record_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def minimal_record
199199
'title' => ['Sample <em>TIMDEX</em> Record'],
200200
'summary' => ['comprehensive <em>test</em> record']
201201
}
202-
assert_equal expected_highlight, normalized['highlight']
202+
assert_equal expected_highlight, normalized[:highlight]
203203
end
204204

205205
test 'includes TIMDEX-specific source_link field' do

test/models/normalize_timdex_results_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def empty_timdex_response
3030
assert_includes first_result.keys, :content_type
3131
assert_includes first_result.keys, :dates
3232
assert_includes first_result.keys, :contributors
33-
assert_includes first_result.keys, 'highlight'
33+
assert_includes first_result.keys, :highlight
3434
assert_includes first_result.keys, 'source_link'
3535

3636
# Check second record (minimal record)

0 commit comments

Comments
 (0)