-
Notifications
You must be signed in to change notification settings - Fork 359
/
ItemSearchProvider.ts
85 lines (73 loc) · 2.34 KB
/
ItemSearchProvider.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { SearchParameterTraits } from "../../Traits/TraitsClasses/SearchableItemTraits";
export type ItemSearchParameter =
| NumericItemSearchParameter
| EnumItemSearchParameter
| TextItemSearchParameter;
export type ItemSearchParameterType = ItemSearchParameter["type"];
export type BaseParameter = {
id: string;
name: string;
queryOptions?: any;
};
export interface NumericItemSearchParameter extends BaseParameter {
type: "numeric";
range: { min: number; max: number };
}
export interface EnumItemSearchParameter extends BaseParameter {
type: "enum";
values: { id: string; count: number }[];
}
export interface TextItemSearchParameter extends BaseParameter {
type: "text";
}
export type ItemSearchResult = {
id: string | number;
idPropertyName: string;
featureCoordinate: {
latitudeDegrees: number;
longitudeDegrees: number;
featureHeight: number;
};
properties: Record<string, string | number>;
};
/**
* An ItemSearchProvider provides an API for searching within an item.
*
*/
export default abstract class ItemSearchProvider {
constructor(
readonly options: any,
readonly parameterOptions: SearchParameterTraits[]
) {}
/**
* Called once on start to initialize the item search provider.
*
* @return A promise that resolves when the initialization is complete.
*/
abstract initialize(): Promise<void>;
/**
* Returns a list of parameters that can be searched.
*
* @return A promise that resolves to an array of ItemSearchParameter.
*/
abstract describeParameters(): Promise<ItemSearchParameter[]>;
/**
* Perform a search.
*
* @param parameterValues A map from parameter ID to its value.
* @return A promise that resolves to an array of ItemSearchResult.
*/
abstract search(
parameterValues: Map<string, any>
): Promise<ItemSearchResult[]>;
/**
* An optional hook to receive a hint that the user might search the parameter with `parameterId`.
*
* If indexes for parameters takes too long to load, implementing this method can
* improve search time by pre-emptively loading the index. This hook is called
* while the user is inputing value for the parameter. It can be called
* multiple times, so the implementation must take care not to make
* duplicate requests.
*/
loadParameterHint?: (parameterId: string, valueHint: any) => void;
}