UNPKG

ioredisearch

Version:

Client library for RediSearch Redis Module, designed to work in conjunction with ioredis

65 lines (64 loc) 3.15 kB
/// <reference types="ioredis" /> import { Redis } from 'ioredis'; import { Field } from './field'; import { Query } from './query'; import { Result } from './result'; import { BatchIndexer } from './batch-indexer'; export interface SchemaDictionary { [key: string]: any; } export interface NumericDictionary { [key: string]: number; } export declare type SearchDictionary = NumericDictionary; export declare type SnippetsDictionary = NumericDictionary; export declare type DocumentScore = 0.0 | 0.1 | 0.2 | 0.3 | 0.4 | 0.5 | 0.6 | 0.7 | 0.8 | 0.9 | 1.0; /** * A client for the RediSearch module. * It abstracts the API of the module and lets you just use the engine */ export declare class Client<C extends Redis = Redis> { readonly redis: C; private indexName; constructor(indexName: string, conn: C); /** * Create the search index. Creating an existing index juts updates its properties * @param fields a list of TextField or NumericField objects */ createIndex(fields: Field[]): Promise<'OK'>; /** * Drop the index if it exists */ dropIndex(): Promise<'OK'>; /** * Add a single document to the index. * @param docId the id of the saved document. * @param fields object of the document fields to be saved and/or indexed. * NOTE: Geo points should be encoded as strings of "lon,lat" * @param score the document ranking, between 0.0 and 1.0 * @param payload optional inner-index payload we can save for fast access in scoring functions * @param noSave if set to true, we just index the document, and don't save a copy of it. This means that searches will just return ids. * @param replace if true, and the document already is in the index, we perform an update and reindex the document * @param partial if true, the fields specified will be added to the existing document. * This has the added benefit that any fields specified with `no_index` * will not be reindexed again. Implies `replace` */ addDocument<T extends SchemaDictionary>(docId: string, fields: T, score?: DocumentScore, payload?: Object, noSave?: boolean, replace?: boolean, partial?: boolean): Promise<'OK'>; /** * Search the index for a given query, and return a result of documents * @param queryOrString the search query. * Either a text for simple queries * with default parameters, * or a Query object for complex queries. * See RediSearch's documentation on query format * @param snippetSizes A dictionary of {field: snippet_size} * used to trim and format the result. e.g. {'body': 500} */ search<T = SchemaDictionary, S = NumericDictionary>(queryOrString: Query | string, snippetSizes?: S): Promise<Result<T, S>>; /** * Create a new batch indexer from the client with a given chunk size */ batchIndexer(chunkSize?: number): BatchIndexer; _addDocument<T extends SchemaDictionary>(conn: Redis | null, docId: string, fields: T, score?: DocumentScore, payload?: Object, noSave?: boolean, replace?: boolean, partial?: boolean): Promise<'OK'>; private toQuery(query); }