mirror of
https://github.com/nextapps-de/flexsearch.git
synced 2025-09-25 12:58:59 +02:00
Add return type annotations in index.d.ts
This commit is contained in:
129
index.d.ts
vendored
129
index.d.ts
vendored
@@ -1,63 +1,87 @@
|
|||||||
declare module "flexsearch" {
|
declare module "flexsearch" {
|
||||||
interface Index<T> {
|
export interface Index<T> {
|
||||||
//TODO: Chaining
|
|
||||||
readonly id: string;
|
readonly id: string;
|
||||||
readonly index: string;
|
readonly index: string;
|
||||||
readonly length: number;
|
readonly length: number;
|
||||||
|
|
||||||
init();
|
init(options?: CreateOptions): this;
|
||||||
init(options: CreateOptions);
|
info(): {
|
||||||
info();
|
id: any;
|
||||||
add(o: T);
|
items: any;
|
||||||
add(id: number, o: string);
|
cache: any;
|
||||||
|
matcher: number;
|
||||||
|
worker: any;
|
||||||
|
threshold: any;
|
||||||
|
depth: any;
|
||||||
|
resolution: any;
|
||||||
|
contextual: boolean;
|
||||||
|
};
|
||||||
|
add(o: T): this;
|
||||||
|
add(id: number, o: string): this;
|
||||||
|
|
||||||
// Result without pagination -> T[]
|
// Result without pagination -> T[]
|
||||||
search(query: string, options: number | SearchOptions, callback: (results: T[]) => void): void;
|
search(
|
||||||
|
query: string,
|
||||||
|
options: number | SearchOptions,
|
||||||
|
callback: (results: T[]) => void
|
||||||
|
): void;
|
||||||
search(query: string, options?: number | SearchOptions): Promise<T[]>;
|
search(query: string, options?: number | SearchOptions): Promise<T[]>;
|
||||||
search(options: SearchOptions & {query: string}, callback: (results: T[]) => void): void;
|
search(
|
||||||
search(options: SearchOptions & {query: string}): Promise<T[]>;
|
options: SearchOptions & { query: string },
|
||||||
|
callback: (results: T[]) => void
|
||||||
|
): void;
|
||||||
|
search(options: SearchOptions & { query: string }): Promise<T[]>;
|
||||||
|
|
||||||
// Result with pagination -> SearchResults<T>
|
// Result with pagination -> SearchResults<T>
|
||||||
search(query: string, options: number | SearchOptions & { page?: boolean | Cursor}, callback: (results: SearchResults<T>) => void): void;
|
search(
|
||||||
search(query: string, options?: number | SearchOptions & { page?: boolean | Cursor}): Promise<SearchResults<T>>;
|
query: string,
|
||||||
search(options: SearchOptions & {query: string, page?: boolean | Cursor}, callback: (results: SearchResults<T>) => void): void;
|
options: number | (SearchOptions & { page?: boolean | Cursor }),
|
||||||
search(options: SearchOptions & {query: string, page?: boolean | Cursor}): Promise<SearchResults<T>>;
|
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): this;
|
||||||
|
remove(id: number): this;
|
||||||
|
clear(): this;
|
||||||
|
destroy(): this;
|
||||||
|
addMatcher(matcher: Matcher): this;
|
||||||
|
|
||||||
update(id: number, o: T);
|
where(whereObj: { [key: string]: string } | ((o: T) => boolean)): T[];
|
||||||
remove(id: number);
|
|
||||||
clear();
|
|
||||||
destroy();
|
|
||||||
addMatcher(matcher: Matcher);
|
|
||||||
|
|
||||||
where(whereFn: (o: T) => boolean): T[];
|
|
||||||
where(whereObj: {[key: string]: string});
|
|
||||||
encode(str: string): string;
|
encode(str: string): string;
|
||||||
export(): string;
|
export(): string;
|
||||||
import(exported: string);
|
import(exported: string): this;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SearchOptions {
|
interface SearchOptions {
|
||||||
limit?: number,
|
limit?: number;
|
||||||
suggest?: boolean,
|
suggest?: boolean;
|
||||||
where?: {[key: string]: string},
|
where?: { [key: string]: string };
|
||||||
field?: string | string[],
|
field?: string | string[];
|
||||||
bool?: "and" | "or" | "not"
|
bool?: "and" | "or" | "not";
|
||||||
//TODO: Sorting
|
//TODO: Sorting
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SearchResults<T> {
|
interface SearchResults<T> {
|
||||||
page?: Cursor,
|
page?: Cursor;
|
||||||
next?: Cursor,
|
next?: Cursor;
|
||||||
result: T[]
|
result: T[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Document {
|
interface Document {
|
||||||
id: string;
|
id: string;
|
||||||
field: any;
|
field: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export type CreateOptions = {
|
export type CreateOptions = {
|
||||||
profile?: IndexProfile;
|
profile?: IndexProfile;
|
||||||
tokenize?: DefaultTokenizer | TokenizerFn;
|
tokenize?: DefaultTokenizer | TokenizerFn;
|
||||||
@@ -70,34 +94,43 @@ declare module "flexsearch" {
|
|||||||
threshold?: false | number;
|
threshold?: false | number;
|
||||||
resolution?: number;
|
resolution?: number;
|
||||||
stemmer?: Stemmer | string | false;
|
stemmer?: Stemmer | string | false;
|
||||||
filter?: FilterFn | string | false;
|
filter?: FilterFn | string | false;
|
||||||
rtl?: boolean;
|
rtl?: boolean;
|
||||||
doc?: Document;
|
doc?: Document;
|
||||||
};
|
};
|
||||||
|
|
||||||
// limit number Sets the limit of results.
|
// limit number Sets the limit of results.
|
||||||
// suggest true, false Enables suggestions in results.
|
// suggest true, false Enables suggestions in results.
|
||||||
// where object Use a where-clause for non-indexed fields.
|
// 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.
|
// 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.
|
// bool "and", "or" Sets the used logical operator when searching through multiple fields.
|
||||||
// page true, false, cursor Enables paginated results.
|
// page true, false, cursor Enables paginated results.
|
||||||
|
|
||||||
type IndexProfile = "memory" | "speed" | "match" | "score" | "balance" | "fast";
|
type IndexProfile =
|
||||||
|
| "memory"
|
||||||
|
| "speed"
|
||||||
|
| "match"
|
||||||
|
| "score"
|
||||||
|
| "balance"
|
||||||
|
| "fast";
|
||||||
type DefaultTokenizer = "strict" | "forward" | "reverse" | "full";
|
type DefaultTokenizer = "strict" | "forward" | "reverse" | "full";
|
||||||
type TokenizerFn = (str: string) => string[];
|
type TokenizerFn = (str: string) => string[];
|
||||||
type DefaultEncoder = "icase" | "simple" | "advanced" | "extra" | "balance";
|
type DefaultEncoder = "icase" | "simple" | "advanced" | "extra" | "balance";
|
||||||
type EncoderFn = (str: string) => string;
|
type EncoderFn = (str: string) => string;
|
||||||
type Stemmer = {[key: string]: string};
|
type Stemmer = { [key: string]: string };
|
||||||
type Matcher = {[key: string]: string};
|
type Matcher = { [key: string]: string };
|
||||||
type FilterFn = (str: string) => boolean;
|
type FilterFn = (str: string) => boolean;
|
||||||
type Cursor = string;
|
type Cursor = string;
|
||||||
|
|
||||||
export default class FlexSearch {
|
export default class FlexSearch {
|
||||||
static create<T>(options?: CreateOptions): Index<T>;
|
static create<T>(options?: CreateOptions): Index<T>;
|
||||||
static registerMatcher(matcher: Matcher);
|
static registerMatcher(matcher: Matcher): typeof FlexSearch;
|
||||||
static registerEncoder(name: string, encoder: EncoderFn);
|
static registerEncoder(name: string, encoder: EncoderFn): typeof FlexSearch;
|
||||||
static registerLanguage(lang: string, options: { stemmer?: Stemmer; filter?: string[] });
|
static registerLanguage(
|
||||||
static encode(name: string, str: string);
|
lang: string,
|
||||||
|
options: { stemmer?: Stemmer; filter?: string[] }
|
||||||
|
): typeof FlexSearch;
|
||||||
|
static encode(name: string, str: string): string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
},
|
},
|
||||||
"main": "dist/flexsearch.node.js",
|
"main": "dist/flexsearch.node.js",
|
||||||
"browser": "dist/flexsearch.min.js",
|
"browser": "dist/flexsearch.min.js",
|
||||||
|
"types": "index.d.ts",
|
||||||
"preferGlobal": false,
|
"preferGlobal": false,
|
||||||
"bin": {},
|
"bin": {},
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -75,6 +76,5 @@
|
|||||||
"mocha-phantomjs": "^4.1.0",
|
"mocha-phantomjs": "^4.1.0",
|
||||||
"nyc": "^14.1.1",
|
"nyc": "^14.1.1",
|
||||||
"phantomjs-prebuilt": "^2.1.16"
|
"phantomjs-prebuilt": "^2.1.16"
|
||||||
},
|
}
|
||||||
"types": "index.d.ts"
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user