forked from nextapps-de/flexsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
108 lines (93 loc) · 3.74 KB
/
index.d.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
declare module "flexsearch" {
interface Index<T> {
//TODO: Chaining
readonly id: string;
readonly index: string;
readonly length: number;
init();
init(options: CreateOptions);
info();
add(o: T);
add(id: number, o: string);
// Result without pagination -> T[]
search(query: string, options: number | SearchOptions, callback: (results: T[]) => void): void;
search(query: string, options?: number | SearchOptions): Promise<T[]>;
search(options: SearchOptions & {query: string}, callback: (results: T[]) => void): void;
search(options: SearchOptions & {query: string}): Promise<T[]>;
// Result with pagination -> SearchResults<T>
search(query: string, options: number | SearchOptions & { page?: boolean | Cursor}, callback: (results: SearchResults<T>) => void): void;
search(query: string, options?: number | SearchOptions & { page?: boolean | Cursor}): Promise<SearchResults<T>>;
search(options: SearchOptions & {query: string, page?: boolean | Cursor}, callback: (results: SearchResults<T>) => void): void;
search(options: SearchOptions & {query: string, page?: boolean | Cursor}): Promise<SearchResults<T>>;
update(id: number, o: T);
remove(id: number);
clear();
destroy();
addMatcher(matcher: Matcher);
where(whereFn: (o: T) => boolean): T[];
where(whereObj: {[key: string]: string});
encode(str: string): string;
export(): string;
import(exported: string);
}
interface SearchOptions {
limit?: number,
suggest?: boolean,
where?: {[key: string]: string},
field?: string | string[],
bool?: "and" | "or" | "not"
//TODO: Sorting
}
interface SearchResults<T> {
page?: Cursor,
next?: Cursor,
result: T[]
}
interface Document {
id: string;
field: any;
}
export type CreateOptions = {
profile?: IndexProfile;
tokenize?: DefaultTokenizer | TokenizerFn;
split?: RegExp;
encode?: DefaultEncoder | EncoderFn | false;
cache?: boolean | number;
async?: boolean;
worker?: false | number;
depth?: false | number;
threshold?: false | number;
resolution?: number;
stemmer?: Stemmer | string | false;
filter?: FilterFn | string | false;
rtl?: boolean;
doc?: Document;
};
// limit number Sets the limit of results.
// suggest true, false Enables suggestions in results.
// where object Use a where-clause for non-indexed fields.
// field string, Array<string> Sets the document fields which should be searched. When no field is set, all fields will be searched. Custom options per field are also supported.
// bool "and", "or" Sets the used logical operator when searching through multiple fields.
// page true, false, cursor Enables paginated results.
type IndexProfile = "memory" | "speed" | "match" | "score" | "balance" | "fast";
type DefaultTokenizer = "strict" | "forward" | "reverse" | "full";
type TokenizerFn = (str: string) => string[];
type DefaultEncoder = "icase" | "simple" | "advanced" | "extra" | "balance";
type EncoderFn = (str: string) => string;
type Stemmer = {[key: string]: string};
type Matcher = {[key: string]: string};
type FilterFn = (str: string) => boolean;
type Cursor = string;
export default class FlexSearch {
static create<T>(options?: CreateOptions): Index<T>;
static registerMatcher(matcher: Matcher);
static registerEncoder(name: string, encoder: EncoderFn);
static registerLanguage(lang: string, options: { stemmer?: Stemmer; filter?: string[] });
static encode(name: string, str: string);
}
}
// FlexSearch.create(<options>)
// FlexSearch.registerMatcher({KEY: VALUE})
// FlexSearch.registerEncoder(name, encoder)
// FlexSearch.registerLanguage(lang, {stemmer:{}, filter:[]})
// FlexSearch.encode(name, string)