Skip to content

Commit 997ab5b

Browse files
committed
Updates logic to filter highlights
Why are these changes being introduced: * Showing highlights for fields that are already displayed in the main result view is redundant and clutters the interface. * We updated the displayed fields, but did not update the highlight filtering logic to match. Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/USE-300 How does this address that need: * Updates the list of displayed fields used to filter highlights to match the current set of displayed fields. * Updates tests to match the new logic. Document any side effects to this change: * We are filtering out `citation` even thought we don't display it for timdex results. This is intentional as citation data is often redundant with other displayed fields like title and contributors.
1 parent 104c809 commit 997ab5b

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

app/helpers/search_helper.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module SearchHelper
2+
# These fields are used to filter out highlights that are already displayed in the main result view. Keep in mind these values need to be the names of fields in TIMDEX, not the normalized record keys.
23
def displayed_fields
3-
['title', 'title.exact_value', 'content_type', 'dates.value', 'contributors.value']
4+
['title', 'title.exact_value', 'content_type', 'dates.value', 'contributors.value', 'summary', 'citation',
5+
'subjects.value']
46
end
57

68
def trim_highlights(result)

test/controllers/search_controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def mock_timdex_search_success
100100
'contributors' => [{ 'value' => 'Foo Barston', 'kind' => 'Creator' }],
101101
'highlight' => [
102102
{
103-
'matchedField' => 'summary',
103+
'matchedField' => 'notes',
104104
'matchedPhrases' => ['<span>sample</span> document']
105105
}
106106
],

test/helpers/search_helper_test.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ class SearchHelperTest < ActionView::TestCase
1313
end
1414

1515
test 'does not remove undisplayed fields from highlights' do
16-
result = { highlight: [{ 'matchedField' => 'summary', 'matchedPhrases' => 'Have some data' }] }
17-
assert_equal [{ 'matchedField' => 'summary', 'matchedPhrases' => 'Have some data' }], trim_highlights(result)
16+
result = { highlight: [{ 'matchedField' => 'notes', 'matchedPhrases' => 'Have some data' }] }
17+
assert_equal [{ 'matchedField' => 'notes', '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
2121
result = { highlight: [{ 'matchedField' => 'title', 'matchedPhrases' => 'Very important data' },
2222
{ 'matchedField' => 'content_type', 'matchedPhrases' => 'Dataset' },
23-
{ 'matchedField' => 'summary', 'matchedPhrases' => '2022' },
24-
{ 'matchedField' => 'citation', 'matchedPhrases' => 'Datascientist, Jane' }] }
25-
assert_equal [{ 'matchedField' => 'summary', 'matchedPhrases' => '2022' },
26-
{ 'matchedField' => 'citation', 'matchedPhrases' => 'Datascientist, Jane' }], trim_highlights(result)
23+
{ 'matchedField' => 'numbering', 'matchedPhrases' => '2022' },
24+
{ 'matchedField' => 'notes', 'matchedPhrases' => 'Datascientist, Jane' }] }
25+
assert_equal [{ 'matchedField' => 'numbering', 'matchedPhrases' => '2022' },
26+
{ 'matchedField' => 'notes', 'matchedPhrases' => 'Datascientist, Jane' }], trim_highlights(result)
2727
end
2828

2929
test 'parse_geo_dates returns issued over coverage' do

0 commit comments

Comments
 (0)