mirror of
https://github.com/nextapps-de/flexsearch.git
synced 2025-09-02 18:33:17 +02:00
fix generics on SearchResults, add info method and add without 'id'
This commit is contained in:
45
index.d.ts
vendored
45
index.d.ts
vendored
@@ -7,17 +7,30 @@ declare module "flexsearch" {
|
||||
|
||||
init();
|
||||
init(options: CreateOptions);
|
||||
info();
|
||||
add(o: T);
|
||||
add(id: number, o: T);
|
||||
search(query: string, options: number | SearchOptions, callback: (results: SearchResults<T>) => void): void;
|
||||
search(query: string, options?: number | SearchOptions): Promise<SearchResults<T>>;
|
||||
search(options: SearchOptions & {query: string}, callback: (results: SearchResults<T>) => void): void;
|
||||
search(options: SearchOptions & {query: string}): Promise<SearchResults<T>>;
|
||||
|
||||
// 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): SearchResult<T>[];
|
||||
|
||||
where(whereFn: (o: T) => boolean): T[];
|
||||
where(whereObj: {[key: string]: string});
|
||||
encode(str: string): string;
|
||||
export(): string;
|
||||
@@ -25,22 +38,20 @@ declare module "flexsearch" {
|
||||
}
|
||||
|
||||
interface SearchOptions {
|
||||
limit?: number,
|
||||
suggest?: boolean,
|
||||
where?: {[key: string]: string},
|
||||
field?: string | string[],
|
||||
bool?: "and" | "or" | "not"
|
||||
page?: boolean | Cursor;
|
||||
//TODO: Sorting
|
||||
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: SearchResult[]
|
||||
page?: Cursor,
|
||||
next?: Cursor,
|
||||
result: T[]
|
||||
}
|
||||
|
||||
type SearchResult = number;
|
||||
|
||||
export type CreateOptions = {
|
||||
profile?: IndexProfile;
|
||||
@@ -76,7 +87,7 @@ declare module "flexsearch" {
|
||||
type Cursor = string;
|
||||
|
||||
export default class FlexSearch {
|
||||
static create(options?: CreateOptions): Index;
|
||||
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[] });
|
||||
|
Reference in New Issue
Block a user