support multiple text matching

This commit is contained in:
Salihu
2026-08-29 19:38:02 +01:00
parent 70c8c6cfda
commit 9797a3671f
7 changed files with 83 additions and 48 deletions
@@ -8,7 +8,7 @@ export class SearchResponseDto {
creatorId: string;
rank: number;
highlight: string;
matchedText?: string;
matchedText?: string[];
createdAt: Date;
updatedAt: Date;
space: Partial<Space>;
+13 -9
View File
@@ -140,16 +140,20 @@ export class SearchService {
//@ts-ignore
const searchResults = results.map((result: SearchResponseDto) => {
if (result.highlight) {
result.highlight = result.highlight
.replace(/\r\n|\r|\n/g, ' ')
.replace(/\s+/g, ' ');
const matchedText = result.highlight.match(/<b>([^<]*)<\/b>/i);
result.matchedText = matchedText?.[1] ?? null;
} else {
result.matchedText = null;
if (!result.highlight) {
result.matchedText = [];
return result;
}
result.highlight = result.highlight
.replace(/\r\n|\r|\n/g, ' ')
.replace(/\s+/g, ' ');
result.matchedText = Array.from(
result.highlight.matchAll(/<b>([^<]*)<\/b>/gi),
(match) => match[1],
);
return result;
});