mirror of
https://github.com/nextapps-de/flexsearch.git
synced 2025-08-29 08:40:45 +02:00
added some tests for index.d.ts
This commit is contained in:
71
index.d.ts
vendored
71
index.d.ts
vendored
@@ -198,7 +198,7 @@ declare module "flexsearch" {
|
|||||||
D extends DocumentData = undefined
|
D extends DocumentData = undefined
|
||||||
> = R extends true
|
> = R extends true
|
||||||
? DefaultSearchResults
|
? DefaultSearchResults
|
||||||
: Resolver<D, W, S>;
|
: Resolver<D, W, S>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 \
|
||||||
@@ -209,12 +209,13 @@ declare module "flexsearch" {
|
|||||||
export type IndexSearchResultsWrapper<
|
export type IndexSearchResultsWrapper<
|
||||||
W extends WorkerType = false,
|
W extends WorkerType = false,
|
||||||
S extends StorageInterface | boolean = false,
|
S extends StorageInterface | boolean = false,
|
||||||
R extends boolean = true
|
R extends boolean = true,
|
||||||
|
D extends DocumentData = undefined
|
||||||
> = W extends false
|
> = W extends false
|
||||||
? S extends false
|
? S extends false
|
||||||
? SearchResults<W, S, R>
|
? SearchResults<W, S, R, D>
|
||||||
: Promise<SearchResults<W, S, R>>
|
: Promise<SearchResults<W, S, R, D>>
|
||||||
: Promise<SearchResults<W, S, R>>
|
: Promise<SearchResults<W, S, R, D>>
|
||||||
|
|
||||||
export class Index<
|
export class Index<
|
||||||
W extends WorkerType = false,
|
W extends WorkerType = false,
|
||||||
@@ -364,8 +365,8 @@ declare module "flexsearch" {
|
|||||||
type WorkerConfigPath = string;
|
type WorkerConfigPath = string;
|
||||||
type WorkerType = boolean | WorkerURL | WorkerPath;
|
type WorkerType = boolean | WorkerURL | WorkerPath;
|
||||||
|
|
||||||
export type WorkerIndexOptions = IndexOptions & {
|
export type WorkerIndexOptions = IndexOptions & IndexWorkerConfig & {
|
||||||
config?: WorkerConfigURL | WorkerConfigPath,
|
//config?: WorkerConfigURL | WorkerConfigPath,
|
||||||
export?: () => Promise<void>;
|
export?: () => Promise<void>;
|
||||||
import?: () => Promise<void>;
|
import?: () => Promise<void>;
|
||||||
// no persistent supported
|
// no persistent supported
|
||||||
@@ -373,6 +374,10 @@ declare module "flexsearch" {
|
|||||||
commit?: null;
|
commit?: null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export interface IndexWorkerConfig {
|
||||||
|
config?: WorkerConfigURL | WorkerConfigPath;
|
||||||
|
}
|
||||||
|
|
||||||
export class Worker extends Index<true> {
|
export class Worker extends Index<true> {
|
||||||
constructor(options?: Preset | WorkerIndexOptions);
|
constructor(options?: Preset | WorkerIndexOptions);
|
||||||
|
|
||||||
@@ -402,33 +407,31 @@ declare module "flexsearch" {
|
|||||||
}[keyof D]
|
}[keyof D]
|
||||||
: never;
|
: never;
|
||||||
|
|
||||||
export type DefaultFieldOptions<
|
export type DefaultFieldOptions<D = DocumentData> =
|
||||||
D = DocumentData,
|
IndexOptions & {
|
||||||
> = IndexOptions & {
|
field: FieldName<D>;
|
||||||
field: FieldName<D>;
|
filter?: (doc: D) => boolean;
|
||||||
filter?: (doc: D) => boolean;
|
db?: StorageInterface;
|
||||||
db?: StorageInterface;
|
};
|
||||||
};
|
|
||||||
|
|
||||||
export type DefaultCustomFieldOptions<
|
export type DefaultCustomFieldOptions<D = DocumentData> =
|
||||||
D = DocumentData,
|
IndexOptions & {
|
||||||
> = IndexOptions & {
|
custom: CustomFN<D>;
|
||||||
custom: CustomFN<D>;
|
field: FieldName;
|
||||||
field: FieldName;
|
filter?: (doc: D) => boolean;
|
||||||
filter?: (doc: D) => boolean;
|
db?: StorageInterface;
|
||||||
db?: StorageInterface;
|
};
|
||||||
};
|
|
||||||
|
|
||||||
export type TagOptions<D = DocumentData> = DefaultFieldOptions<D> | DefaultCustomFieldOptions<D>;
|
export type TagOptions<D = DocumentData> =
|
||||||
|
| DefaultFieldOptions<D>
|
||||||
|
| DefaultCustomFieldOptions<D>;
|
||||||
|
|
||||||
export type StoreOptions<D = DocumentData> = DefaultFieldOptions<D> | DefaultCustomFieldOptions<D>;
|
export type StoreOptions<D = DocumentData> =
|
||||||
|
| DefaultFieldOptions<D>
|
||||||
export interface IndexWorkerConfig {
|
| DefaultCustomFieldOptions<D>;
|
||||||
config?: WorkerConfigURL | WorkerConfigPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type FieldOptions<D extends DocumentData> =
|
export type FieldOptions<D extends DocumentData> =
|
||||||
(DefaultFieldOptions<D> & IndexWorkerConfig)
|
| (DefaultFieldOptions<D> & IndexWorkerConfig)
|
||||||
| (DefaultCustomFieldOptions<D> & IndexWorkerConfig)
|
| (DefaultCustomFieldOptions<D> & IndexWorkerConfig)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -992,16 +995,16 @@ declare module "flexsearch" {
|
|||||||
constructor(options?: ResolverOptions<D, W, S> | IntermediateSearchResults);
|
constructor(options?: ResolverOptions<D, W, S> | IntermediateSearchResults);
|
||||||
|
|
||||||
and<R extends boolean = false>(...args: ResolverOptions<D, W, S, unknown, R>[]):
|
and<R extends boolean = false>(...args: ResolverOptions<D, W, S, unknown, R>[]):
|
||||||
SearchResults<W, S, R, D>;
|
IndexSearchResultsWrapper<W, S, R, D>;
|
||||||
|
|
||||||
or<R extends boolean = false>(...args: ResolverOptions<D, W, S, unknown, R>[]):
|
or<R extends boolean = false>(...args: ResolverOptions<D, W, S, unknown, R>[]):
|
||||||
SearchResults<W, S, R, D>;
|
IndexSearchResultsWrapper<W, S, R, D>;
|
||||||
|
|
||||||
xor<R extends boolean = false>(...args: ResolverOptions<D, W, S, unknown, R>[]):
|
xor<R extends boolean = false>(...args: ResolverOptions<D, W, S, unknown, R>[]):
|
||||||
SearchResults<W, S, R, D>;
|
IndexSearchResultsWrapper<W, S, R, D>;
|
||||||
|
|
||||||
not<R extends boolean = false>(...args: ResolverOptions<D, W, S, unknown, R>[]):
|
not<R extends boolean = false>(...args: ResolverOptions<D, W, S, unknown, R>[]):
|
||||||
SearchResults<W, S, R, D>;
|
IndexSearchResultsWrapper<W, S, R, D>;
|
||||||
|
|
||||||
limit(limit: number): Resolver<D, W, S>;
|
limit(limit: number): Resolver<D, W, S>;
|
||||||
|
|
||||||
@@ -1009,7 +1012,7 @@ declare module "flexsearch" {
|
|||||||
|
|
||||||
boost(boost: number): Resolver<D, W, S>;
|
boost(boost: number): Resolver<D, W, S>;
|
||||||
|
|
||||||
resolve(options?: DefaultResolve<D>): SearchResults<W, S, true, D>;
|
resolve(options?: DefaultResolve<D>): IndexSearchResultsWrapper<W, S, true, D>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class StorageInterface {
|
export class StorageInterface {
|
||||||
|
@@ -3,7 +3,7 @@ import {
|
|||||||
Index,
|
Index,
|
||||||
Worker,
|
Worker,
|
||||||
Resolver,
|
Resolver,
|
||||||
IndexedDB
|
IndexedDB, EnrichedResults
|
||||||
} from "flexsearch";
|
} from "flexsearch";
|
||||||
import {
|
import {
|
||||||
DefaultDocumentSearchResults,
|
DefaultDocumentSearchResults,
|
||||||
@@ -44,9 +44,14 @@ async function test_index() {
|
|||||||
const idx19: Promise<Resolver> = index2.searchCacheAsync({});
|
const idx19: Promise<Resolver> = index2.searchCacheAsync({});
|
||||||
|
|
||||||
const res1: Resolver = new Resolver({ index });
|
const res1: Resolver = new Resolver({ index });
|
||||||
const res2: Resolver = res1.and({ index }).limit(100);
|
const res2: Resolver = res1.and({}, { index }).limit(100);
|
||||||
const res3: DefaultSearchResults = res2.resolve();
|
const res3: DefaultSearchResults = res2.resolve();
|
||||||
|
|
||||||
|
const res4: Resolver<undefined, false, IndexedDB> = new Resolver({ index: index3 });
|
||||||
|
const res5: Promise<Resolver<undefined, false, IndexedDB>> = res4.and();
|
||||||
|
const res6: Promise<Resolver<undefined, false, IndexedDB>> = res4.and({ index: index3 });
|
||||||
|
const res7: Promise<DefaultSearchResults> = (await res6).limit(100).resolve();
|
||||||
|
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
const idx_err1 = index.search({ highlight: true });
|
const idx_err1 = index.search({ highlight: true });
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
@@ -78,6 +83,8 @@ async function test_index() {
|
|||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
const idx_err12: Promise<Resolver> = index3.searchAsync({ resolve: false, cache: true });
|
const idx_err12: Promise<Resolver> = index3.searchAsync({ resolve: false, cache: true });
|
||||||
|
|
||||||
|
// @ts-expect-deprecation
|
||||||
|
const idx_err13: DefaultSearchResults = index.search("query", 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function test_document() {
|
async function test_document() {
|
||||||
@@ -168,12 +175,22 @@ async function test_document() {
|
|||||||
const doc10: Promise<DefaultDocumentSearchResults> = document.searchAsync({ cache: true });
|
const doc10: Promise<DefaultDocumentSearchResults> = document.searchAsync({ cache: true });
|
||||||
const doc11: Promise<DefaultDocumentSearchResults> = document.searchCacheAsync({});
|
const doc11: Promise<DefaultDocumentSearchResults> = document.searchCacheAsync({});
|
||||||
const doc13: DefaultDocumentSearchResults = document.search({ resolve: true });
|
const doc13: DefaultDocumentSearchResults = document.search({ resolve: true });
|
||||||
|
|
||||||
const doc14: Resolver = document.search({ resolve: false });
|
const doc14: Resolver = document.search({ resolve: false });
|
||||||
const doc15: DefaultSearchResults = doc14.resolve({});
|
const doc15: DefaultSearchResults = doc14.resolve({});
|
||||||
const doc16: DefaultSearchResults = doc14.and({ resolve: true });
|
const doc16: DefaultSearchResults = doc14.and({ resolve: true });
|
||||||
|
const doc17: EnrichedResults = doc14.resolve({ enrich: true });
|
||||||
|
const doc18: EnrichedResults = doc14.and({ resolve: true, enrich: true });
|
||||||
|
const doc19: Resolver = doc14.and({ index: document, field: "title" });
|
||||||
|
const doc20: Resolver = doc19.or({ index: document2, field: "meta:title" });
|
||||||
|
const doc21: DefaultDocumentSearchResults = doc20.resolve();
|
||||||
|
const doc22: EnrichedResults = doc20.resolve({ enrich: true });
|
||||||
|
const doc23: EnrichedResults = doc20.resolve({ highlight: true });
|
||||||
|
|
||||||
const res1: Resolver = doc14.and({ index: document, field: "meta:title" });
|
const doc24: Resolver = new Resolver({ index: document });
|
||||||
const res2: DefaultDocumentSearchResults = doc14.resolve();
|
const doc25: EnrichedResults = doc24.and({}, { index: document2, resolve: true, enrich: true });
|
||||||
|
const doc26: EnrichedResults = doc24.and({}, { index: document2 }).resolve({ enrich: true });
|
||||||
|
const doc27: EnrichedResults = doc24.and({}, { index: document2 }).resolve({ highlight: true });
|
||||||
|
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
let tmp1: DocumentData = doc1[0].result[0].doc;
|
let tmp1: DocumentData = doc1[0].result[0].doc;
|
||||||
|
Reference in New Issue
Block a user