Skip to content

Commit

Permalink
Fix termSearch return type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
jcuenod committed Jun 8, 2024
1 parent 80b9bc3 commit e54b97d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
17 changes: 12 additions & 5 deletions src/routes/termSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@ import { getVersificationSchemaIdFromModuleId } from "../helpers/moduleInfo.ts";
import { getTermSearchQuery } from "../helpers/termSearchQueryBuilder.ts";
import { getTextQuery } from "../helpers/parallelTextQueryBuilder.ts";
import { getWordQuery } from "../helpers/wordMapQueryBuilder.ts";
import { mapTextResult } from "../helpers/mapTextResult.ts";

const mapMatchingTextSearchResults = (
type MapToTermSearchResponseFunction = (
orderedResults: number[][],
matchingText: ParallelTextQueryResult,
moduleIds: number[],
) => TermSearchTextResponse;
const mapMatchingTextSearchResults: MapToTermSearchResponseFunction = (
orderedResults,
matchingText,
moduleIds,
) =>
orderedResults.map((parallelIds) =>
moduleIds.map((moduleId) =>
parallelIds.map((parallelId) =>
matchingText.find((row) =>
parallelIds.map((parallelId) => {
const row = matchingText.find((row) =>
row.parallelId === parallelId && row.moduleId === moduleId
)
)
);
return row ? mapTextResult(row) : null;
})
)
);

Expand Down
6 changes: 4 additions & 2 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ type WordResponse = {
value: string
}[]
}

type TermSearchResponse = {
count: number
matchingText: DisambiguatedTextResult[][]
matchingText: TermSearchTextResponse
matchingWords: {
wid: number
moduleId: number
Expand All @@ -46,7 +47,6 @@ type HighlightResponse = {
wid: number
}[]
}
type TextResponse = (DisambiguatedTextResult | null)[][]
type DisambiguatedTextResult = {
parallelId: number
moduleId: number
Expand All @@ -55,6 +55,8 @@ type DisambiguatedTextResult = {
wordArray: WordArray
html: string
}
type TextResponse = (DisambiguatedTextResult | null)[][]
type TermSearchTextResponse = (DisambiguatedTextResult | null)[][][]

type WordArray = {
wid: number
Expand Down

0 comments on commit e54b97d

Please sign in to comment.