UNPKG

@meilisearch/meili-api

Version:

The MeiliSearch JS client for Node.js and the browser.

247 lines 7.11 kB
/* * Bundle: Meili / Indexes * Project: Meili - Javascript API * Author: Quentin de Quelen <quentin@meilisearch.com> * Copyright: 2019, Meili */ 'use strict'; import { __assign } from "tslib"; import axios from 'axios'; var Indexes = /** @class */ (function () { function Indexes(instance, indexUid) { this.instance = instance; this.indexUid = indexUid; this.cancelTokenSource = axios.CancelToken.source(); } /// /// UPDATES /// /** * Get the informations about on update * @memberof Indexes * @method getUpdate */ Indexes.prototype.getUpdate = function (updateId) { var url = "/indexes/" + this.indexUid + "/updates/" + updateId; return this.instance.get(url); }; /** * Get the list of all updates * @memberof Indexes * @method getAllUpdates */ Indexes.prototype.getAllUpdates = function () { var url = "/indexes/" + this.indexUid + "/updates"; return this.instance.get(url); }; /// /// SEARCH /// /** * Search for documents into an index * @memberof Meili * @method search */ Indexes.prototype.search = function (options) { var url = "/indexes/" + this.indexUid + "/search"; var params = { q: options.q, }; if (options.offset) { params.offset = options.offset; } if (options.limit) { params.limit = options.limit; } if (options.attributesToRetrieve) { params.attributesToRetrieve = options.attributesToRetrieve.join(); } if (options.attributesToSearchIn) { params.attributesToSearchIn = options.attributesToSearchIn.join(); } if (options.attributesToCrop) { params.attributesToCrop = options.attributesToCrop.join(); } if (options.cropLength) { params.cropLength = options.cropLength; } if (options.attributesToHighlight) { params.attributesToHighlight = options.attributesToHighlight.join(); } if (options.filters) { params.filters = options.filters; } if (options.timeoutMs) { params.timeoutMs = options.timeoutMs; } if (options.matches) { params.matches = options.matches; } return this.instance.get(url, { params: params, cancelToken: this.cancelTokenSource.token, }); }; /// /// INDEX /// Indexes.prototype.getIndex = function () { var url = "/indexes/" + this.indexUid; return this.instance.get(url); }; Indexes.prototype.updateIndex = function (data) { var url = "/indexes/" + this.indexUid; return this.instance.put(url, data); }; Indexes.prototype.deleteIndex = function () { var url = "/indexes/" + this.indexUid; return this.instance.delete(url); }; /// /// SCHEMA /// Indexes.prototype.getSchema = function (raw) { var url = "/indexes/" + this.indexUid + "/schema"; if (raw) { return this.instance.get(url, { params: { raw: true, }, }); } else { return this.instance.get(url); } }; Indexes.prototype.updateSchema = function (schema) { var url = "/indexes/" + this.indexUid + "/schema"; if (schema.identifier) { return this.instance.put(url, schema, { params: { raw: true, }, }); } else { return this.instance.put(url, schema); } }; /// /// STATS /// /** * get stats of an index * @memberof Indexes * @method getStats */ Indexes.prototype.getStats = function () { var url = "/stats/" + this.indexUid; return this.instance.get(url); }; /// /// DOCUMENTS /// /** * get documents of an index * @memberof Indexes * @method getDocuments */ Indexes.prototype.getDocuments = function (params) { var url = "/indexes/" + this.indexUid + "/documents"; var attr; if (params && Array.isArray(params.attributesToRetrieve)) { attr = params.attributesToRetrieve.join(','); } return this.instance.get(url, { params: __assign(__assign({}, params), (attr ? { attributesToRetrieve: attr } : {})), }); }; /** * Get one document * @memberof Documents * @method getDocument */ Indexes.prototype.getDocument = function (documentId) { var url = "/indexes/" + this.indexUid + "/documents/" + documentId; return this.instance.get(url); }; /** * Add or update multiples documents to an index * @memberof Documents * @method addDocuments */ Indexes.prototype.addDocuments = function (documents) { var url = "/indexes/" + this.indexUid + "/documents"; return this.instance.post(url, documents); }; /** * Delete one document * @memberof Documents * @method deleteDocument */ Indexes.prototype.deleteDocument = function (documentId) { var url = "/indexes/" + this.indexUid + "/documents/" + documentId; return this.instance.delete(url); }; /** * Delete multiples documents to an index * @memberof Documents * @method deleteDocuments */ Indexes.prototype.deleteDocuments = function (documentsIds) { var url = "/indexes/" + this.indexUid + "/documents/delete"; return this.instance.post(url, documentsIds); }; Indexes.prototype.deleteAllDocuments = function () { var url = "/indexes/" + this.indexUid + "/documents"; return this.instance.delete(url); }; /// /// SETTINGS /// /** * Retrieve all settings * @memberof Settings * @method get */ Indexes.prototype.getSettings = function () { var url = '/settings'; return this.instance.get(url); }; /** * Update all settings * @memberof Settings * @method set */ Indexes.prototype.updateSettings = function (settings) { var url = '/settings'; return this.instance.post(url, settings); }; /// /// SYNONYMS /// /** * Get the list of all synonyms * @memberof Synonyms * @method list */ Indexes.prototype.listSynonyms = function () { var url = '/synonym'; return this.instance.get(url); }; /** * Add a new relation between an input and equivalents synonyms * @memberof Synonyms * @method create */ Indexes.prototype.createSynonym = function (input, synonyms) { var url = '/synonym'; return this.instance.post(url, { input: input, synonyms: synonyms, }); }; return Indexes; }()); export { Indexes }; //# sourceMappingURL=indexes.js.map