Debian Codegraph @

packages/search/lib/commands/SUGGET_WITHSCORES_WITHPAYLOADS.ts

raw
1 import { SugGetOptions, transformArguments as transformSugGetArguments } from './SUGGET';
2 import { SuggestionWithPayload } from './SUGGET_WITHPAYLOADS';
3 import { SuggestionWithScores } from './SUGGET_WITHSCORES';
4
5 export { IS_READ_ONLY } from './SUGGET';
6
7 export function transformArguments(key: string, prefix: string, options?: SugGetOptions): Array<string> {
8 return [
9 ...transformSugGetArguments(key, prefix, options),
10 'WITHSCORES',
11 'WITHPAYLOADS'
12 ];
13 }
14
15 type SuggestionWithScoresAndPayloads = SuggestionWithScores & SuggestionWithPayload;
16
17 export function transformReply(rawReply: Array<string | null> | null): Array<SuggestionWithScoresAndPayloads> | null {
18 if (rawReply === null) return null;
19
20 const transformedReply = [];
21 for (let i = 0; i < rawReply.length; i += 3) {
22 transformedReply.push({
23 suggestion: rawReply[i]!,
24 score: Number(rawReply[i + 1]!),
25 payload: rawReply[i + 2]
26 });
27 }
28
29 return transformedReply;
30 }