mirror of
https://github.com/docmost/docmost.git
synced 2026-09-01 03:15:32 +08:00
support multiple text matching
This commit is contained in:
@@ -8,7 +8,7 @@ export class SearchResponseDto {
|
||||
creatorId: string;
|
||||
rank: number;
|
||||
highlight: string;
|
||||
matchedText?: string;
|
||||
matchedText?: string[];
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
space: Partial<Space>;
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user