cozy-dataproxy-lib
Version:
Library meant to be by Cozy Cloud's DataProxy apps for data manipulation
49 lines (48 loc) • 2.6 kB
TypeScript
import FlexSearch from 'flexsearch';
import CozyClient from 'cozy-client';
import type { PerformanceAPI } from 'cozy-client/types/performances/types';
import { SEARCH_SCHEMA, SearchedDoctype } from './consts';
import { CozyDoc, RawSearchResult, SearchIndex, SearchIndexes, SearchResult, SearchOptions, StorageInterface, EnrichedSearchResult } from './types';
interface FlexSearchResultWithDoctype extends FlexSearch.SimpleDocumentSearchResultSetUnit {
doctype: SearchedDoctype;
}
interface EngineOptions {
shouldInit?: boolean;
}
export declare class SearchEngine {
client: CozyClient;
searchIndexes: SearchIndexes;
debouncedReplication: () => void;
isLocalSearch: boolean;
storage: StorageInterface;
performanceApi: PerformanceAPI;
engineOptions: EngineOptions;
constructor(client: CozyClient, storage: StorageInterface, performanceApi?: PerformanceAPI, engineOptions?: EngineOptions);
afterLogin(): void;
indexDocumentsAtInit(): Promise<void>;
handleReplicationEvents(): void;
init(): Promise<void>;
subscribeDoctype(client: CozyClient, doctype: string): void;
handleUpdatedOrCreatedDoc(doc: CozyDoc): void;
handleDeletedDoc(doc: CozyDoc): void;
/**
* Initialize indexes by:
* - importing persisted indexes
* - Requesting remote changes if the indexes are stale
* - Query the local database to load the redux store
*/
initSearchWithIndexImport(): Promise<void>;
buildSearchIndex(doctype: keyof typeof SEARCH_SCHEMA, docs: CozyDoc[]): FlexSearch.Document<CozyDoc, false>;
getLocalLastSeq(doctype: keyof typeof SEARCH_SCHEMA): Promise<number>;
initialIndexation(doctype: keyof typeof SEARCH_SCHEMA): Promise<SearchIndex | null>;
incrementalIndexation(doctype: keyof typeof SEARCH_SCHEMA, searchIndex: SearchIndex): Promise<SearchIndex>;
indexDocsForSearch(doctype: keyof typeof SEARCH_SCHEMA): Promise<SearchIndex | null>;
search(query: string, options: SearchOptions | undefined): Promise<SearchResult[] | null>;
searchOnIndexes(query: string, searchOnDoctypes: string[] | undefined): FlexSearchResultWithDoctype[];
deduplicateAndFlatten(searchResults: FlexSearchResultWithDoctype[]): RawSearchResult[];
compareStrings(str1: string, str2: string): number;
sortSearchResults(searchResults: EnrichedSearchResult[], doctypesOrder: string[] | undefined): EnrichedSearchResult[];
sortFiles(aRes: EnrichedSearchResult, bRes: EnrichedSearchResult): number;
limitSearchResults(searchResults: EnrichedSearchResult[]): EnrichedSearchResult[];
}
export {};