diff --git a/index.d.ts b/index.d.ts index 0aadfa3..a4e759b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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) => void): void; - search(query: string, options?: number | SearchOptions): Promise>; - search(options: SearchOptions & {query: string}, callback: (results: SearchResults) => void): void; - search(options: SearchOptions & {query: string}): Promise>; + + // Result without pagination -> T[] + search(query: string, options: number | SearchOptions, callback: (results: T[]) => void): void; + search(query: string, options?: number | SearchOptions): Promise; + search(options: SearchOptions & {query: string}, callback: (results: T[]) => void): void; + search(options: SearchOptions & {query: string}): Promise; + + // Result with pagination -> SearchResults + search(query: string, options: number | SearchOptions & { page?: boolean | Cursor}, callback: (results: SearchResults) => void): void; + search(query: string, options?: number | SearchOptions & { page?: boolean | Cursor}): Promise>; + search(options: SearchOptions & {query: string, page?: boolean | Cursor}, callback: (results: SearchResults) => void): void; + search(options: SearchOptions & {query: string, page?: boolean | Cursor}): Promise>; + + update(id: number, o: T); remove(id: number); clear(); destroy(); addMatcher(matcher: Matcher); - where(whereFn: (o: T) => boolean): SearchResult[]; + + 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 { - 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(options?: CreateOptions): Index; static registerMatcher(matcher: Matcher); static registerEncoder(name: string, encoder: EncoderFn); static registerLanguage(lang: string, options: { stemmer?: Stemmer; filter?: string[] });