Skip to content

Commit 952d7b6

Browse files
authored
Merge pull request #317 from MITLibraries/use-300-update-displayed-highlights
Updates logic to filter highlights
2 parents 104c809 + 997ab5b commit 952d7b6

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

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)