Skip to content

Commit 9c08609

Browse files
authored
fix: search-result context text (#2545)
1 parent f018fa8 commit 9c08609

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

app/models/search-result.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@ import { languageFromLanguageCode } from 'osf-components/components/file-metadat
77

88
import IndexCardModel from './index-card';
99

10-
const textMatchEvidenceType = 'https://share.osf.io/vocab/2023/trove/TextMatchEvidence';
11-
1210
export interface IriMatchEvidence {
13-
'@type': [string];
1411
matchingIri: string;
1512
osfmapPropertyPath: string[];
13+
propertyPathKey: string;
1614
}
1715

1816
export interface TextMatchEvidence {
19-
'@type': [string];
2017
matchingHighlight: string;
2118
osfmapPropertyPath: string[];
19+
propertyPathKey: string;
2220
}
2321

2422
export const CardLabelTranslationKeys = {
@@ -50,9 +48,11 @@ export default class SearchResultModel extends Model {
5048
if (this.matchEvidence) {
5149
const matchEvidenceString = this.matchEvidence.reduce(
5250
(acc, current) => acc.concat(
53-
`${current.osfmapPropertyPath[0]}: ${current['@type'][0] === textMatchEvidenceType
54-
? (current as TextMatchEvidence).matchingHighlight
55-
: (current as IriMatchEvidence).matchingIri}; `,
51+
`${current.propertyPathKey}: ${
52+
('matchingHighlight' in current)
53+
? current.matchingHighlight
54+
: current.matchingIri
55+
}`,
5656
),
5757
'',
5858
);

mirage/views/search.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,9 @@ export function cardSearch(_: Schema, request: Request) {
339339
propertyPathKey: 'rights',
340340
matchEvidence: [
341341
{
342-
'@type': ['https://share.osf.io/vocab/2023/trove/IriMatchEvidence'],
343-
osfmapPropertyPath: 'resourceType',
342+
'@type': ['trove:IriMatchEvidence'],
343+
osfmapPropertyPath: ['resourceType'],
344+
propertyPathKey: 'resourceType',
344345
matchingIri: 'rdf:Property',
345346
},
346347
],
@@ -377,8 +378,9 @@ export function cardSearch(_: Schema, request: Request) {
377378
propertyPathKey: 'datePublished',
378379
matchEvidence: [
379380
{
380-
'@type': ['https://share.osf.io/vocab/2023/trove/IriMatchEvidence'],
381-
osfmapPropertyPath: 'resourceType',
381+
'@type': ['trove:IriMatchEvidence'],
382+
osfmapPropertyPath: ['resourceType'],
383+
propertyPathKey: 'resourceType',
382384
matchingIri: 'rdf:Property',
383385
},
384386
],
@@ -415,8 +417,9 @@ export function cardSearch(_: Schema, request: Request) {
415417
propertyPathKey: 'funder',
416418
matchEvidence: [
417419
{
418-
'@type': ['https://share.osf.io/vocab/2023/trove/IriMatchEvidence'],
419-
osfmapPropertyPath: 'resourceType',
420+
'@type': ['trove:IriMatchEvidence'],
421+
osfmapPropertyPath: ['resourceType'],
422+
propertyPathKey: 'resourceType',
420423
matchingIri: 'rdf:Property',
421424
},
422425
],
@@ -466,7 +469,7 @@ export function cardSearch(_: Schema, request: Request) {
466469
attributes: {
467470
matchEvidence: [
468471
{
469-
'@type': ['https://share.osf.io/vocab/2023/trove/TextMatchEvidence'],
472+
'@type': ['trove:TextMatchEvidence'],
470473
evidenceCardIdentifier: indexCardURL,
471474
matchingHighlight: [`...<em>${faker.lorem.word()}</em>...`],
472475
osfmapPropertyPath: ['description'],
@@ -576,8 +579,9 @@ export function valueSearch(_: Schema, __: Request) {
576579
attributes: {
577580
matchEvidence: [
578581
{
579-
'@type': ['https://share.osf.io/vocab/2023/trove/TextMatchEvidence'],
580-
osfmapPropertyPath: 'title',
582+
'@type': ['trove:TextMatchEvidence'],
583+
osfmapPropertyPath: ['title'],
584+
propertyPathKey: 'title',
581585
matchingHighlight: 'National <em>Institute of Health</em>',
582586
},
583587
],
@@ -596,8 +600,9 @@ export function valueSearch(_: Schema, __: Request) {
596600
attributes: {
597601
matchEvidence: [
598602
{
599-
'@type': ['https://share.osf.io/vocab/2023/trove/TextMatchEvidence'],
600-
osfmapPropertyPath: 'title',
603+
'@type': ['trove:TextMatchEvidence'],
604+
osfmapPropertyPath: ['title'],
605+
propertyPathKey: 'title',
601606
matchingHighlight: 'Virginia <em>Institute of Health</em>',
602607
},
603608
],

0 commit comments

Comments
 (0)