From 66c54aa82dc53c4778c28205250e2b3b6dd186c0 Mon Sep 17 00:00:00 2001 From: Francis Turmel <4009209+fturmel@users.noreply.github.com> Date: Wed, 11 Oct 2023 05:09:22 -0400 Subject: [PATCH] fix(plugin-match-highlight): `SearchResultWithHighlight` type improvement (#514) --- packages/plugin-match-highlight/src/index.ts | 23 +++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/packages/plugin-match-highlight/src/index.ts b/packages/plugin-match-highlight/src/index.ts index eec390019..582f99fde 100644 --- a/packages/plugin-match-highlight/src/index.ts +++ b/packages/plugin-match-highlight/src/index.ts @@ -1,14 +1,17 @@ import { - AnyDocument, AnyOrama, + AnyDocument, + AnyOrama, Language, RawData, - Result, Results, - SearchParams, TypedDocument, + Result, + Results, + SearchParams, + TypedDocument, load, save, search } from '@orama/orama' -import { boundedLevenshtein } from '@orama/orama/internals'; +import { boundedLevenshtein } from '@orama/orama/internals' export interface Position { start: number @@ -19,8 +22,12 @@ export type OramaWithHighlight = T & { data: { positions: Record>> } } -export type SearchResultWithHighlight = Results & { - hits: (Result & { positions: Record> })[] +export type ResultWithPositions = Result & { + positions: Record> +} + +export type SearchResultWithHighlight = Omit, 'hits'> & { + hits: ResultWithPositions[] } export type RawDataWithPositions = RawData & { @@ -138,6 +145,6 @@ export async function saveWithHighlight(orama: T): Promise(orama: T, raw: RawDataWithPositions): Promise { - await load(orama, raw); - (orama as OramaWithHighlight).data.positions = raw.positions + await load(orama, raw) + ;(orama as OramaWithHighlight).data.positions = raw.positions }