1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-08-27 07:44:35 +02:00

add further generics to index.d.ts

This commit is contained in:
Thomas Wilkerling
2025-05-07 17:15:40 +02:00
parent 2d53d5e556
commit 1a0bd73002

574
index.d.ts vendored
View File

@@ -75,7 +75,7 @@ declare module "flexsearch" {
* **Document:** * **Document:**
* * Search options: https://github.com/nextapps-de/flexsearch#search-options * * Search options: https://github.com/nextapps-de/flexsearch#search-options
*/ */
type SearchOptions<R extends boolean = false> = { type SearchOptions<R extends boolean = true> = {
query?: string; query?: string;
limit?: number; limit?: number;
offset?: number; offset?: number;
@@ -85,36 +85,7 @@ declare module "flexsearch" {
resolve?: R; resolve?: R;
}; };
/**
* **Document:**
* * The document descriptor: https://github.com/nextapps-de/flexsearch#the-document-descriptor
*/
type DocumentDescriptor<D extends DocumentData = DocumentData> = {
id?: string | "id";
field?: FieldName<D> | FieldName<D>[] | FieldOptions<D> | Array<FieldOptions<D>>;
index?: FieldName<D> | FieldName<D>[] | FieldOptions<D> | Array<FieldOptions<D>>;
tag?: FieldName<D> | FieldName<D>[] | TagOptions<D> | Array<TagOptions<D>>;
store?: FieldName<D> | FieldName<D>[] | StoreOptions | Array<StoreOptions> | boolean;
};
type WorkerURL = string;
type WorkerPath = string;
type WorkerConfigURL = string;
type WorkerConfigPath = string;
type SerializedFunctionString = string; type SerializedFunctionString = string;
type FieldName<D = DocumentData> = D extends object
? {
[K in keyof D]: K extends string
? D[K] extends Array<infer U>
? `${ K }` | `${ K }[]:${ FieldName<U> & string }`
: K | `${ K }:${ FieldName<D[K]> & string }`
: never
}[keyof D]
: never
/**
* The template to be applied on matches (e.g. <code>"\<b>$1\</b>"</code>), where <code>\$1</code> is a placeholder for the matched partial
*/
type TemplateResultHighlighting = string;
/** /**
* **Document:** * **Document:**
@@ -183,7 +154,10 @@ declare module "flexsearch" {
* * Right-To-Left: https://github.com/nextapps-de/flexsearch/doc/encoder.md#right-to-left-support * * Right-To-Left: https://github.com/nextapps-de/flexsearch/doc/encoder.md#right-to-left-support
* * Language: https://github.com/nextapps-de/flexsearch/doc/encoder.md#built-in-language-packs * * Language: https://github.com/nextapps-de/flexsearch/doc/encoder.md#built-in-language-packs
*/ */
type IndexOptions<D extends StorageInterface = undefined> = { type IndexOptions<
S extends StorageInterface = undefined,
R extends boolean = true
> = {
preset?: Preset; preset?: Preset;
tokenize?: Tokenizer; tokenize?: Tokenizer;
cache?: boolean | number; cache?: boolean | number;
@@ -199,9 +173,10 @@ declare module "flexsearch" {
partial: string, partial: string,
partial_index: number, partial_index: number,
) => number; ) => number;
resolve?: R;
// Persistent-specific options // Persistent-specific options
db?: D; db?: S;
commit?: boolean; commit?: boolean;
// Language-specific Options and Encoding // Language-specific Options and Encoding
@@ -210,42 +185,36 @@ declare module "flexsearch" {
rtl?: boolean; rtl?: boolean;
}; };
type WorkerIndexOptions = IndexOptions & {
config?: WorkerConfigURL | WorkerConfigPath,
export?: () => Promise<void>;
import?: () => Promise<void>;
// no persistent supported
db?: null;
commit?: null;
};
/************************************/ /************************************/
/* Index Search */ /* Index Search */
/************************************/ /************************************/
type DefaultSearchResults = Id[]; type DefaultSearchResults = Id[];
type IntermediateSearchResults = Array<Id[]>; type IntermediateSearchResults = Array<Id[]>;
type SearchResults<R extends boolean = false> = R extends true ? Resolver : DefaultSearchResults; type SearchResults<R extends boolean = true> = R extends true ? DefaultSearchResults : Resolver;
/** /**
* **Document:** * Basic usage and variants: https://github.com/nextapps-de/flexsearch#basic-usage-and-variants \
* * Basic usage and variants: https://github.com/nextapps-de/flexsearch#basic-usage-and-variants * API overview: https://github.com/nextapps-de/flexsearch#api-overview \
* * API overview: https://github.com/nextapps-de/flexsearch#api-overview * Usage: https://github.com/nextapps-de/flexsearch#usage
* * Usage: https://github.com/nextapps-de/flexsearch#usage
*/ */
type IndexSearchResultsWrapper< type IndexSearchResultsWrapper<
W extends boolean = false, W extends boolean = false,
D extends StorageInterface = undefined, S extends StorageInterface = undefined,
R extends boolean = false R extends boolean = true
> = W extends false > = W extends false
? D extends undefined ? S extends undefined
? SearchResults<R> ? SearchResults<R>
: Promise<SearchResults<R>> : Promise<SearchResults<R>>
: Promise<SearchResults<R>> : Promise<SearchResults<R>>
export class Index<W extends boolean = false, D extends StorageInterface = undefined> { export class Index<
constructor(options?: Preset | IndexOptions<D>); W extends boolean = false,
S extends StorageInterface = undefined,
r extends boolean = true
> {
constructor(options?: Preset | IndexOptions<S, r>);
add(id: Id, content: string): this | Promise<this>; add(id: Id, content: string): this | Promise<this>;
@@ -258,15 +227,20 @@ declare module "flexsearch" {
remove(id: Id): this | Promise<this>; remove(id: Id): this | Promise<this>;
search(query: string, limit?: Limit): IndexSearchResultsWrapper<W, D>; /** @deprecated Pass "limit" within options */
search<R extends boolean = false>(query: string, options?: SearchOptions<R>): IndexSearchResultsWrapper<W, D, R>; search(query: string, limit?: Limit): IndexSearchResultsWrapper<W, S>;
search<R extends boolean = false>(query: string, limit: Limit, options: SearchOptions<R>): IndexSearchResultsWrapper<W, D, R>; /** @deprecated Pass "limit" within options */
search<R extends boolean = false>(options: SearchOptions<R>): IndexSearchResultsWrapper<W, D, R>; search<R extends boolean = r>(query: string, options?: SearchOptions<R>): IndexSearchResultsWrapper<W, S, R>;
/** @deprecated Pass "limit" within options */
search<R extends boolean = r>(query: string, limit: Limit, options: SearchOptions<R>): IndexSearchResultsWrapper<W, S, R>;
search<R extends boolean = r>(options: SearchOptions<R>): IndexSearchResultsWrapper<W, S, R>;
/** @deprecated Pass "limit" within options */
searchCache(query: string, limit?: Limit): W extends false ? SearchResults : Promise<SearchResults>; searchCache(query: string, limit?: Limit): W extends false ? SearchResults : Promise<SearchResults>;
searchCache<R extends boolean = false>(query: string, options?: Limit | SearchOptions<R>): IndexSearchResultsWrapper<W, D, R>; searchCache(query: string, options?: SearchOptions): IndexSearchResultsWrapper<W, S>;
searchCache<R extends boolean = false>(query: string, limit: Limit, options: SearchOptions<R>): IndexSearchResultsWrapper<W, D, R>; /** @deprecated Pass "limit" within options */
searchCache<R extends boolean = false>(options: SearchOptions<R>): IndexSearchResultsWrapper<W, D, R>; searchCache(query: string, limit: Limit, options: SearchOptions): IndexSearchResultsWrapper<W, S>;
searchCache(options: SearchOptions): IndexSearchResultsWrapper<W, S>;
// https://github.com/nextapps-de/flexsearch#check-existence-of-already-indexed-ids // https://github.com/nextapps-de/flexsearch#check-existence-of-already-indexed-ids
contain(id: Id): boolean | Promise<boolean>; contain(id: Id): boolean | Promise<boolean>;
@@ -315,34 +289,52 @@ declare module "flexsearch" {
callback?: AsyncCallback<void>, callback?: AsyncCallback<void>,
): Promise<this>; ): Promise<this>;
searchAsync(
query: string,
callback?: AsyncCallback<SearchResults>,
): Promise<SearchResults>
/** @deprecated Pass "limit" within options */
searchAsync( searchAsync(
query: string, query: string,
limit?: Limit, limit?: Limit,
callback?: AsyncCallback<SearchResults>, callback?: AsyncCallback<SearchResults>,
): Promise<SearchResults> ): Promise<SearchResults>
searchAsync<R extends boolean = false>( searchAsync<R extends boolean = r>(
query: string, query: string,
options?: SearchOptions<R>, options?: SearchOptions<R>,
callback?: AsyncCallback<SearchResults<R>>, callback?: AsyncCallback<SearchResults<R>>,
): Promise<SearchResults<R>> ): Promise<SearchResults<R>>
searchAsync<R extends boolean = false>( /** @deprecated Pass "limit" within options */
searchAsync<R extends boolean = r>(
query: string, query: string,
limit: Limit, limit: Limit,
options?: SearchOptions<R>, options?: SearchOptions<R>,
callback?: AsyncCallback<SearchResults<R>>, callback?: AsyncCallback<SearchResults<R>>,
): Promise<SearchResults<R>>; ): Promise<SearchResults<R>>;
searchAsync<R extends boolean = false>( searchAsync<R extends boolean = r>(
options: SearchOptions<R>, options: SearchOptions<R>,
callback?: AsyncCallback<SearchResults<R>>, callback?: AsyncCallback<SearchResults<R>>,
): Promise<SearchResults<R>>; ): Promise<SearchResults<R>>;
} }
/** /************************************/
* **Document:** /* Worker Index */
* * Basic usage and variants: https://github.com/nextapps-de/flexsearch#basic-usage-and-variants /************************************/
* * API overview: https://github.com/nextapps-de/flexsearch#api-overview
* * Worker index: https://github.com/nextapps-de/flexsearch#worker-index type WorkerURL = string;
*/ type WorkerPath = string;
type WorkerConfigURL = string;
type WorkerConfigPath = string;
type WorkerType = boolean | WorkerURL | WorkerPath;
type WorkerIndexOptions = IndexOptions & {
config?: WorkerConfigURL | WorkerConfigPath,
export?: () => Promise<void>;
import?: () => Promise<void>;
// no persistent supported
db?: null;
commit?: null;
};
export class Worker extends Index<true> { export class Worker extends Index<true> {
constructor(options?: Preset | WorkerIndexOptions); constructor(options?: Preset | WorkerIndexOptions);
@@ -356,81 +348,43 @@ declare module "flexsearch" {
/* Document Search */ /* Document Search */
/************************************/ /************************************/
/**
* The template to be applied on matches (e.g. <code>"\<b>$1\</b>"</code>), where <code>\$1</code> is a placeholder for the matched partial
*/
type TemplateResultHighlighting = string;
type TagName = string;
type FieldName<D = DocumentData> = D extends object
? {
[K in keyof D]: K extends string
? D[K] extends Array<infer U>
? `${ K }` | `${ K }[]:${ FieldName<U> & string }`
: K | `${ K }:${ FieldName<D[K]> & string }`
: never
}[keyof D]
: never;
type FieldOptions<D extends DocumentData = DocumentData> = IndexOptions & { type FieldOptions<D extends DocumentData = DocumentData> = IndexOptions & {
field: FieldName<D>, field: FieldName<D>,
filter?: (content: string) => boolean; filter?: (content: string) => boolean;
custom?: (content: string) => string; custom?: (content: string) => string | boolean;
config?: WorkerConfigURL | WorkerConfigPath; config?: WorkerConfigURL | WorkerConfigPath;
db?: StorageInterface;
}; };
type TagOptions<D extends DocumentData> = { type TagOptions<D extends DocumentData> = {
field: FieldName<D>; field: FieldName<D>;
filter?: (content: string) => boolean; filter?: (content: string) => boolean;
custom?: (content: string) => string; custom?: (content: string) => string | boolean;
db?: StorageInterface; db?: StorageInterface;
}; };
type StoreOptions = { type StoreOptions = {
field: FieldName; field: FieldName;
filter?: (content: string) => boolean; filter?: (content: string) => boolean;
custom?: (content: string) => string; custom?: (content: string) => string | boolean;
db?: StorageInterface; db?: StorageInterface;
}; };
/*
* **Document:**
* * Document options: https://github.com/nextapps-de/flexsearch#document-options
*/
type WorkerType = boolean | WorkerURL | WorkerPath;
type DocumentOptions<
D extends DocumentData = DocumentData,
W extends WorkerType = false,
B extends StorageInterface = undefined
> = IndexOptions<B> & DocumentDescriptor<D> & {
worker?: W;
doc?: DocumentDescriptor<D>;
document?: DocumentDescriptor<D>;
};
type DefaultDocumentSearchResults<D extends DocumentData = DocumentData> = Array<{
field?: FieldName<D>;
tag?: FieldName<D>;
result: DefaultSearchResults;
}>;
type EnrichedDocumentSearchResults<D extends DocumentData = DocumentData> = Array<{
field?: FieldName<D>;
tag?: FieldName<D>;
result: Array<{
id: Id;
doc: D | null;
highlight?: string;
}>;
}>;
type MergedDocumentSearchResults<D extends DocumentData = DocumentData> = Array<{
id: Id;
doc: D | null;
field?: FieldName[];
tag?: FieldName[];
highlight?: {[field: FieldName]: string};
}>;
type DocumentSearchResults<
D extends DocumentData = DocumentData,
R extends boolean = false,
E extends boolean = false,
M extends boolean = false
> = R extends true
? Resolver
: M extends true
? MergedDocumentSearchResults<D>
: E extends true
? EnrichedDocumentSearchResults<D>
: DefaultDocumentSearchResults
/** /**
* # Document Search Result * # Document Search Result
* *
@@ -441,22 +395,104 @@ declare module "flexsearch" {
* If neither of these conditions is met, then the returned result will be a `ISimpleDocumentSearchResult`. * If neither of these conditions is met, then the returned result will be a `ISimpleDocumentSearchResult`.
*/ */
/*
* **Document:**
* * Document options: https://github.com/nextapps-de/flexsearch#document-options
*/
type DocumentOptions<
D extends DocumentData = DocumentData,
W extends WorkerType = false,
S extends StorageInterface = undefined
> = IndexOptions<S> & DocumentDescriptor<D> & {
worker?: W;
doc?: DocumentDescriptor<D>;
document?: DocumentDescriptor<D>;
};
/**
* **Document:**
* * The document descriptor: https://github.com/nextapps-de/flexsearch#the-document-descriptor
*/
type DocumentDescriptor<D extends DocumentData = DocumentData> = {
id?: string | "id";
field?: FieldName<D> | FieldName<D>[] | FieldOptions<D> | Array<FieldOptions<D>>;
index?: FieldName<D> | FieldName<D>[] | FieldOptions<D> | Array<FieldOptions<D>>;
tag?: FieldName<D> | FieldName<D>[] | TagOptions<D> | Array<TagOptions<D>>;
store?: FieldName<D> | FieldName<D>[] | StoreOptions | Array<StoreOptions> | boolean;
};
type DefaultDocumentSearchResults<D extends DocumentData = DocumentData> = Array<{
field?: FieldName<D>;
tag?: FieldName<D>;
result: DefaultSearchResults;
}>;
type EnrichedResults<D extends DocumentData = DocumentData> = Array<{
id: Id;
doc: D | null;
highlight?: string;
}>;
type EnrichedDocumentSearchResults<D extends DocumentData = DocumentData> = Array<{
field?: FieldName<D>;
tag?: FieldName<D>;
result: EnrichedResults<D>;
}>;
type MergedDocumentSearchResults<D extends DocumentData = DocumentData> = Array<{
id: Id;
doc?: D | null;
field?: FieldName[];
tag?: FieldName[];
highlight?: {[field: FieldName]: string};
}>;
type DocumentSearchResults<
D extends DocumentData = DocumentData,
H extends HighlightOptions = undefined,
P extends PluckOptions = undefined,
R extends boolean = true,
E extends boolean = false,
M extends boolean = false
> = R extends true
? P extends PluckOptions
? E extends true
? EnrichedResults<D>
: DefaultSearchResults
: M extends true
? MergedDocumentSearchResults<D>
: E extends true
? EnrichedDocumentSearchResults<D>
: H extends HighlightOptions
? EnrichedDocumentSearchResults<D>
: DefaultDocumentSearchResults
: Resolver;
type PluckOptions<
D extends DocumentData = DocumentData,
H extends HighlightOptions = undefined,
R extends boolean = true,
E extends boolean = false
> = FieldName | DocumentSearchOptions<D, H, undefined, R, E>;
/** /**
* **Document:** * **Document:**
* * Document search options: https://github.com/nextapps-de/flexsearch#document-search-options * * Document search options: https://github.com/nextapps-de/flexsearch#document-search-options
*/ */
type DocumentSearchOptions< type DocumentSearchOptions<
D extends DocumentData = DocumentData, D extends DocumentData = DocumentData,
R extends boolean = false, H extends HighlightOptions = undefined,
P extends PluckOptions = undefined,
R extends boolean = true,
E extends boolean = false, E extends boolean = false,
M extends boolean = false M extends boolean = false,
> = SearchOptions<R> & { > = SearchOptions<R> & {
tag?: {[field: FieldName]: string} | Array<{[field: FieldName]: string}>; tag?: {[field: FieldName]: TagName} | Array<{[field: FieldName]: TagName}>;
field?: Array<DocumentSearchOptions<D, R, E, M>> | DocumentSearchOptions<D, R, E, M> | FieldName[] | FieldName; field?: Array<DocumentSearchOptions<D, H, P, R, E, M>> | DocumentSearchOptions<D, H, P, R, E, M> | FieldName[] | FieldName;
index?: Array<DocumentSearchOptions<D, R, E, M>> | DocumentSearchOptions<D, R, E, M> | FieldName[] | FieldName; index?: Array<DocumentSearchOptions<D, H, P, R, E, M>> | DocumentSearchOptions<D, H, P, R, E, M> | FieldName[] | FieldName;
pluck?: FieldName | DocumentSearchOptions<D, R, E, false>; pluck?: P;
highlight?: HighlightOptions | TemplateResultHighlighting; highlight?: H;
enrich?: E; enrich?: E;
merge?: M; merge?: M;
}; };
@@ -475,79 +511,148 @@ declare module "flexsearch" {
type DocumentSearchResultsWrapper< type DocumentSearchResultsWrapper<
D extends DocumentData = DocumentData, D extends DocumentData = DocumentData,
W extends WorkerType = false, W extends WorkerType = false,
B extends StorageInterface = undefined, S extends StorageInterface = undefined,
R extends boolean = false, H extends HighlightOptions = undefined,
P extends PluckOptions = undefined,
R extends boolean = true,
E extends boolean = false, E extends boolean = false,
M extends boolean = false, M extends boolean = false
> = W extends false > = W extends false
? B extends undefined ? S extends undefined
? DocumentSearchResults<D, R, E, M> ? DocumentSearchResults<D, H, P, R, E, M>
: Promise<DocumentSearchResults<D, R, E, M>> : Promise<DocumentSearchResults<D, H, P, R, E, M>>
: Promise<DocumentSearchResults<D, R, E, M>> : Promise<DocumentSearchResults<D, H, P, R, E, M>>
/** /**
* **Document:** * Basic usage and variants: https://github.com/nextapps-de/flexsearch#basic-usage-and-variants \
* * Basic usage and variants: https://github.com/nextapps-de/flexsearch#basic-usage-and-variants * API overview: https://github.com/nextapps-de/flexsearch#api-overview \
* * API overview: https://github.com/nextapps-de/flexsearch#api-overview * Document store: https://github.com/nextapps-de/flexsearch#document-store
* * Document store: https://github.com/nextapps-de/flexsearch#document-store
*/ */
export class Document< export class Document<
D extends DocumentData = DocumentData, D extends DocumentData = DocumentData,
W extends WorkerType = false, W extends WorkerType = false,
B extends StorageInterface = undefined S extends StorageInterface = undefined
> { > {
constructor(options: DocumentOptions<D, W, B>); constructor(options: DocumentOptions<D, W, S>);
add(id: Id, document: D): this | Promise<this>; add(id: Id, document: D): W extends WorkerType
add(document: D): this | Promise<this>; ? Promise<this>
: this;
add(document: D): W extends WorkerType
? Promise<this>
: this;
/** @deprecated The method "append" will be removed in an upcoming release, just use "add" instead */ /** @deprecated The method "append" will be removed in an upcoming release, just use "add" instead */
append(id: Id, document: D): this | Promise<this>; append(id: Id, document: D): W extends WorkerType
? Promise<this>
: this;
/** @deprecated The method "append" will be removed in an upcoming release, just use "add" instead */ /** @deprecated The method "append" will be removed in an upcoming release, just use "add" instead */
append(document: D): this | Promise<this>; append(document: D): W extends WorkerType
? Promise<this>
: this;
update(id: Id, document: D): this | Promise<this>; update(id: Id, document: D): W extends WorkerType
update(document: D): this | Promise<this>; ? Promise<this>
: this;
update(document: D): W extends WorkerType
? Promise<this>
: this;
remove(id: Id): this | Promise<this>; remove(id: Id): W extends WorkerType
remove(document: D): this | Promise<this>; ? Promise<this>
: this;
remove(document: D): W extends WorkerType
? Promise<this>
: this;
// https://github.com/nextapps-de/flexsearch#field-search // https://github.com/nextapps-de/flexsearch#field-search
search(query: string, limit: Limit): DocumentSearchResultsWrapper<D, W, B>; /** @deprecated Pass "limit" within options */
search<R extends boolean = false, E extends boolean = false, M extends boolean = false>( search(query: string, limit: Limit): DocumentSearchResultsWrapper<D, W, S>;
/** @deprecated Pass "limit" within options */
searchCache(query: string, limit: Limit): DocumentSearchResultsWrapper<D, W, S>;
search<
H extends HighlightOptions = undefined,
P extends PluckOptions = undefined,
R extends boolean = true,
E extends boolean = false,
M extends boolean = false
>(
query: string, query: string,
options?: DocumentSearchOptions<D, R, E, M>, options?: DocumentSearchOptions<D, H, P, R, E, M>,
): DocumentSearchResultsWrapper<D, W, B, R, E, M>; ): DocumentSearchResultsWrapper<D, W, S, H, P, R, E, M>;
search<R extends boolean = false, E extends boolean = false, M extends boolean = false>( searchCache<
H extends HighlightOptions = undefined,
P extends PluckOptions = undefined,
R extends boolean = true,
E extends boolean = false,
M extends boolean = false
>(
query: string,
options?: DocumentSearchOptions<D, H, P, R, E, M>,
): DocumentSearchResultsWrapper<D, W, S, H, P, R, E, M>;
/** @deprecated Pass "limit" within options */
search<
H extends HighlightOptions = undefined,
P extends PluckOptions = undefined,
R extends boolean = true,
E extends boolean = false,
M extends boolean = false
>(
query: string, query: string,
limit: Limit, limit: Limit,
options: DocumentSearchOptions<D, R, E, M>, options: DocumentSearchOptions<D, H, P, R, E, M>,
): DocumentSearchResultsWrapper<D, W, B, R, E, M>; ): DocumentSearchResultsWrapper<D, W, S, H, P, R, E, M>;
search<R extends boolean = false, E extends boolean = false, M extends boolean = false>( /** @deprecated Pass "limit" within options */
options: DocumentSearchOptions<D, R, E, M>, searchCache<
): DocumentSearchResultsWrapper<D, W, B, R, E, M>; H extends HighlightOptions = undefined,
P extends PluckOptions = undefined,
R extends boolean = true,
E extends boolean = false,
M extends boolean = false
>(
query: string,
limit: Limit,
options: DocumentSearchOptions<D, H, P, R, E, M>,
): DocumentSearchResultsWrapper<D, W, S, H, P, R, E, M>;
search<
H extends HighlightOptions = undefined,
P extends PluckOptions = undefined,
R extends boolean = true,
E extends boolean = false,
M extends boolean = false
>(
options: DocumentSearchOptions<D, H, P, R, E, M>,
): DocumentSearchResultsWrapper<D, W, S, H, P, R, E, M>;
searchCache<
H extends HighlightOptions = undefined,
P extends PluckOptions = undefined,
R extends boolean = true,
E extends boolean = false,
M extends boolean = false
>(
options: DocumentSearchOptions<D, H, P, R, E, M>,
): DocumentSearchResultsWrapper<D, W, S, H, P, R, E, M>;
searchCache(query: string, limit: Limit): W extends false ? DocumentSearchResults<D> : Promise<DocumentSearchResults<D>>;
searchCache<R extends boolean = false, E extends boolean = false, M extends boolean = false>(
query: string,
options?: DocumentSearchOptions<D, R, E, M>,
): DocumentSearchResultsWrapper<D, W, B, R, E, M>;
searchCache<R extends boolean = false, E extends boolean = false, M extends boolean = false>(
query: string,
limit: Limit, options: DocumentSearchOptions<D, R, E, M>,
): DocumentSearchResultsWrapper<D, W, B, R, E, M>;
searchCache<R extends boolean = false, E extends boolean = false, M extends boolean = false>(
options: DocumentSearchOptions<D, R, E, M>,
): DocumentSearchResultsWrapper<D, W, B, R, E, M>;
// https://github.com/nextapps-de/flexsearch#check-existence-of-already-indexed-ids // https://github.com/nextapps-de/flexsearch#check-existence-of-already-indexed-ids
contain(id: Id): boolean | Promise<boolean>; contain(id: Id): D extends StorageInterface
? Promise<boolean>
: boolean;
clear(): void | Promise<void>; clear(): D extends StorageInterface
? Promise<void>
: W extends WorkerType
? Promise<void>
: void;
cleanup(): void | Promise<void>; cleanup(): void;
get(id: Id): Promise<D> | D | null; get(id: Id): D extends StorageInterface
? Promise<D>
: D | null;
set(id: Id, document: D): this; set(id: Id, document: D): this;
set(document: D): this; set(document: D): this;
@@ -607,22 +712,56 @@ declare module "flexsearch" {
callback?: AsyncCallback<void>, callback?: AsyncCallback<void>,
): Promise<this>; ): Promise<this>;
searchAsync(query: string, limit?: Limit): Promise<DocumentSearchResults<D>> /** @deprecated Pass "limit" within options */
searchAsync<R extends boolean = false, E extends boolean = false, M extends boolean = false>( searchAsync(query: string, limit?: Limit): Promise<DocumentSearchResultsWrapper<D, W, S>>
searchAsync<
H extends HighlightOptions = undefined,
P extends PluckOptions = undefined,
R extends boolean = true,
E extends boolean = false,
M extends boolean = false
>(
query: string, query: string,
options?: DocumentSearchOptions<D, R, E, M>, callback?: AsyncCallback<DocumentSearchResults<D, H, P, R, E, M>>,
callback?: AsyncCallback<DocumentSearchResults<D, R, E, M>>, ): Promise<DocumentSearchResults<D, H, P, R, E, M>>
): Promise<DocumentSearchResults<D, R, E, M>>
searchAsync<R extends boolean = false, E extends boolean = false, M extends boolean = false>( searchAsync<
H extends HighlightOptions = undefined,
P extends PluckOptions = undefined,
R extends boolean = true,
E extends boolean = false,
M extends boolean = false
>(
query: string,
options?: DocumentSearchOptions<D, H, P, R, E, M>,
callback?: AsyncCallback<DocumentSearchResults<D, H, P, R, E, M>>,
): Promise<DocumentSearchResults<D, H, P, R, E, M>>
/** @deprecated Pass "limit" within options */
searchAsync<
H extends HighlightOptions = undefined,
P extends PluckOptions = undefined,
R extends boolean = true,
E extends boolean = false,
M extends boolean = false
>(
query: string, query: string,
limit: Limit, limit: Limit,
options?: DocumentSearchOptions<D, R, E, M>, options?: DocumentSearchOptions<D, H, P, R, E, M>,
callback?: AsyncCallback<DocumentSearchResults<D, R, E, M>>, callback?: AsyncCallback<DocumentSearchResults<D, H, P, R, E, M>>,
): Promise<DocumentSearchResults<D, R, E, M>>; ): Promise<DocumentSearchResults<D, H, P, R, E, M>>;
searchAsync<R extends boolean = false, E extends boolean = false, M extends boolean = false>(
options: DocumentSearchOptions<D, R, E, M>, searchAsync<
callback?: AsyncCallback<DocumentSearchResults<D, R, E, M>>, H extends HighlightOptions = undefined,
): Promise<DocumentSearchResults<D, R, E, M>>; P extends PluckOptions = undefined,
R extends boolean = true,
E extends boolean = false,
M extends boolean = false
>(
options: DocumentSearchOptions<D, H, P, R, E, M>,
callback?: AsyncCallback<DocumentSearchResults<D, H, P, R, E, M>>,
): Promise<DocumentSearchResults<D, H, P, R, E, M>>;
} }
type IdType = type IdType =
@@ -653,28 +792,39 @@ declare module "flexsearch" {
db?: any; db?: any;
}; };
type DefaultResolve = { type DefaultResolve<
query?: string; D extends DocumentData = DocumentData,
limit?: number; H extends HighlightOptions = undefined,
offset?: number; E extends boolean = false
enrich?: boolean; > = {
};
type ResolverOptions = DefaultResolve & {
index?: Index | Document;
pluck?: FieldName;
field?: FieldName;
and?: ResolverOptions | Array<ResolverOptions>;
or?: ResolverOptions | Array<ResolverOptions>;
xor?: ResolverOptions | Array<ResolverOptions>;
not?: ResolverOptions | Array<ResolverOptions>;
boost?: number;
suggest?: boolean;
resolve?: boolean;
limit?: number; limit?: number;
offset?: number; offset?: number;
/** only usable when "resolve" was not set to false */ /** only usable when "resolve" was not set to false */
enrich?: boolean; enrich?: D extends DocumentData ? E : undefined;
/** only usable when "resolve" was not set to false */
highlight?: D extends DocumentData ? H : undefined;
};
type ResolverOptions<
D extends DocumentData = DocumentData,
W extends WorkerType = false,
S extends StorageInterface = undefined,
H extends HighlightOptions = undefined,
R extends boolean = true,
E extends boolean = false
> = DefaultResolve<D, H, E> & {
query?: string;
index?: Index | Document;
pluck?: FieldName;
field?: FieldName;
tag?: {[field: FieldName]: TagName} | Array<{[field: FieldName]: TagName}>;
and?: ResolverOptions<D, W, S, H, R, E> | Array<ResolverOptions<D, W, S, H, R, E>>;
or?: ResolverOptions<D, W, S, H, R, E> | Array<ResolverOptions<D, W, S, H, R, E>>;
xor?: ResolverOptions<D, W, S, H, R, E> | Array<ResolverOptions<D, W, S, H, R, E>>;
not?: ResolverOptions<D, W, S, H, R, E> | Array<ResolverOptions<D, W, S, H, R, E>>;
boost?: number;
suggest?: boolean;
resolve?: R;
}; };
type HighlightBoundaryOptions = { type HighlightBoundaryOptions = {
@@ -688,7 +838,7 @@ declare module "flexsearch" {
pattern?: string | boolean; pattern?: string | boolean;
}; };
type HighlightOptions = { type HighlightOptions = TemplateResultHighlighting | {
template?: TemplateResultHighlighting; template?: TemplateResultHighlighting;
boundary?: HighlightBoundaryOptions | number; boundary?: HighlightBoundaryOptions | number;
ellipsis?: HighlightEllipsisOptions | string | boolean; ellipsis?: HighlightEllipsisOptions | string | boolean;