mirror of
https://github.com/nextapps-de/flexsearch.git
synced 2025-09-03 02:42:53 +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();
|
||||||
init(options: CreateOptions);
|
init(options: CreateOptions);
|
||||||
|
info();
|
||||||
|
add(o: T);
|
||||||
add(id: number, 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>>;
|
// Result without pagination -> T[]
|
||||||
search(options: SearchOptions & {query: string}, callback: (results: SearchResults<T>) => void): void;
|
search(query: string, options: number | SearchOptions, callback: (results: T[]) => void): void;
|
||||||
search(options: SearchOptions & {query: string}): Promise<SearchResults<T>>;
|
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);
|
update(id: number, o: T);
|
||||||
remove(id: number);
|
remove(id: number);
|
||||||
clear();
|
clear();
|
||||||
destroy();
|
destroy();
|
||||||
addMatcher(matcher: Matcher);
|
addMatcher(matcher: Matcher);
|
||||||
where(whereFn: (o: T) => boolean): SearchResult<T>[];
|
|
||||||
|
where(whereFn: (o: T) => boolean): T[];
|
||||||
where(whereObj: {[key: string]: string});
|
where(whereObj: {[key: string]: string});
|
||||||
encode(str: string): string;
|
encode(str: string): string;
|
||||||
export(): string;
|
export(): string;
|
||||||
@@ -25,22 +38,20 @@ declare module "flexsearch" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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"
|
||||||
page?: boolean | Cursor;
|
//TODO: Sorting
|
||||||
//TODO: Sorting
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SearchResults<T> {
|
interface SearchResults<T> {
|
||||||
page?: Cursor,
|
page?: Cursor,
|
||||||
next?: Cursor,
|
next?: Cursor,
|
||||||
result: SearchResult[]
|
result: T[]
|
||||||
}
|
}
|
||||||
|
|
||||||
type SearchResult = number;
|
|
||||||
|
|
||||||
export type CreateOptions = {
|
export type CreateOptions = {
|
||||||
profile?: IndexProfile;
|
profile?: IndexProfile;
|
||||||
@@ -76,7 +87,7 @@ declare module "flexsearch" {
|
|||||||
type Cursor = string;
|
type Cursor = string;
|
||||||
|
|
||||||
export default class FlexSearch {
|
export default class FlexSearch {
|
||||||
static create(options?: CreateOptions): Index;
|
static create<T>(options?: CreateOptions): Index<T>;
|
||||||
static registerMatcher(matcher: Matcher);
|
static registerMatcher(matcher: Matcher);
|
||||||
static registerEncoder(name: string, encoder: EncoderFn);
|
static registerEncoder(name: string, encoder: EncoderFn);
|
||||||
static registerLanguage(lang: string, options: { stemmer?: Stemmer; filter?: string[] });
|
static registerLanguage(lang: string, options: { stemmer?: Stemmer; filter?: string[] });
|
||||||
|
Reference in New Issue
Block a user