-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.ts
35 lines (31 loc) · 1.13 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { xLuceneTypeConfig, xLuceneVariables } from '@terascope/types';
import geoBoxFn from './geo/box';
import geoDistanceFn from './geo/distance';
import geoPolygonFn from './geo/polygon';
import geoContainsPointFn from './geo/contains-point';
import { FunctionDefinition, FunctionMethods, FunctionNode } from '../interfaces';
export enum xLuceneFunction {
geoDistance = 'geoDistance',
geoBox = 'geoBox',
geoPolygon = 'geoPolygon',
geoContainsPoint = 'geoContainsPoint',
}
export const xLuceneFunctions: Record<xLuceneFunction, FunctionDefinition> = {
geoDistance: geoDistanceFn,
geoBox: geoBoxFn,
geoPolygon: geoPolygonFn,
geoContainsPoint: geoContainsPointFn
};
export function initFunction({ node, variables, type_config }: {
node: FunctionNode,
variables?: xLuceneVariables,
type_config: xLuceneTypeConfig,
}): FunctionMethods {
const fnType = xLuceneFunctions[node.name] as FunctionDefinition|undefined;
if (fnType == null) {
throw new TypeError(`Unknown xLucene function "${node.name}"`);
}
return fnType.create({
type_config, node, variables: variables ?? {}
});
}