From 5d70d74a89da6c1ca522b6b66c4fb0b11b3ad82c Mon Sep 17 00:00:00 2001 From: operramon <52449656+operramon@users.noreply.github.com> Date: Wed, 8 Feb 2023 16:41:28 +0100 Subject: [PATCH] [sc-3929] Show resources that only have title paragraphs in search results (#569) --- .../src/core/stores/search.store.ts | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/libs/search-widget/src/core/stores/search.store.ts b/libs/search-widget/src/core/stores/search.store.ts index 3de17e39b..0d6dff203 100644 --- a/libs/search-widget/src/core/stores/search.store.ts +++ b/libs/search-widget/src/core/stores/search.store.ts @@ -154,15 +154,15 @@ export const smartResults = searchState.reader((state) => } }); - // for resources without paragraphs, create a fake one using summary if it exists (else, remove the resource) + // for resources without paragraphs, create a fake one using summary or title if they exist (else, remove the resource) smartResults = smartResults .map((resource) => { if (resource.paragraphs && resource.paragraphs.length > 0) { return resource; } else { - const summaryParagraph = generateFakeParagraphForSummary(resource); - if (summaryParagraph) { - return { ...resource, paragraphs: [summaryParagraph] }; + const fakeParagraph = generateFakeParagraphForSummaryOrTitle(resource, state.results.paragraphs?.results || []); + if (fakeParagraph) { + return { ...resource, paragraphs: [fakeParagraph] }; } else { return undefined; } @@ -266,14 +266,21 @@ function generateFakeParagraphForSentence( : undefined; } -function generateFakeParagraphForSummary(resource: IResource): Search.SmartParagraph | undefined { - return resource.summary +function generateFakeParagraphForSummaryOrTitle( + resource: IResource, + paragraphs: Search.Paragraph[], +): Search.SmartParagraph | undefined { + const title = paragraphs.find( + (paragraph) => paragraph.rid === resource.id && paragraph.field_type === SHORT_FIELD_TYPE.generic, + )?.text; + const text = resource.summary || title; + return text ? { score: 0, rid: resource.id, field_type: SHORT_FIELD_TYPE.generic, field: '', - text: resource.summary, + text: text, labels: [], } : undefined;