"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var FlexSearchIndex = /** @class */ (function () {
    function FlexSearchIndex(customConfig) {
        if (customConfig === void 0) { customConfig = {}; }
        var config = Object.assign({
            encode: "advanced",
            tokenize: "reverse",
            suggest: true,
            cache: true,
            doc: {
                id: "text",
                field: ["text"]
            }
        }, customConfig);
        var flexsearch = require('flexsearch');
        this.flexSearch = flexsearch.create(config);
    }
    FlexSearchIndex.prototype.add = function (element) {
        this.flexSearch.add({ text: element });
    };
    FlexSearchIndex.prototype.search = function (query, limit) {
        var _this = this;
        if (limit === void 0) { limit = 10; }
        return new Promise(function (resolve, reject) {
            return _this.flexSearch.search({
                query: query,
                field: "text",
                limit: limit
            }, function (result) { return resolve(result); });
        })
            .then(function (result) { return result.map(function (element) { return element.text; }); });
    };
    FlexSearchIndex.prototype.clear = function () {
        this.flexSearch.clear();
    };
    return FlexSearchIndex;
}());
exports.FlexSearchIndex = FlexSearchIndex;
//# sourceMappingURL=FlexSearchIndex.js.map