"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: all[name]
    });
}
_export(exports, {
    BaseIndex: function() {
        return BaseIndex;
    },
    KeywordTable: function() {
        return KeywordTable;
    }
});
const _Settings = require("../Settings.js");
const _IngestionPipeline = require("../ingestion/IngestionPipeline.js");
const _IndexStruct = require("./IndexStruct.js");
const _jsontoindexstruct = require("./json-to-index-struct.js");
class KeywordTable extends _IndexStruct.IndexStruct {
    table = new Map();
    type = _jsontoindexstruct.IndexStructType.KEYWORD_TABLE;
    addNode(keywords, nodeId) {
        keywords.forEach((keyword)=>{
            if (!this.table.has(keyword)) {
                this.table.set(keyword, new Set());
            }
            this.table.get(keyword).add(nodeId);
        });
    }
    deleteNode(keywords, nodeId) {
        keywords.forEach((keyword)=>{
            if (this.table.has(keyword)) {
                this.table.get(keyword).delete(nodeId);
            }
        });
    }
    toJson() {
        return {
            ...super.toJson(),
            table: this.table,
            type: this.type
        };
    }
}
class BaseIndex {
    serviceContext;
    storageContext;
    docStore;
    indexStore;
    indexStruct;
    constructor(init){
        this.serviceContext = init.serviceContext;
        this.storageContext = init.storageContext;
        this.docStore = init.docStore;
        this.indexStore = init.indexStore;
        this.indexStruct = init.indexStruct;
    }
    /**
   * Insert a document into the index.
   * @param document
   */ async insert(document) {
        const nodes = await (0, _IngestionPipeline.runTransformations)([
            document
        ], [
            (0, _Settings.nodeParserFromSettingsOrContext)(this.serviceContext)
        ]);
        await this.insertNodes(nodes);
        await this.docStore.setDocumentHash(document.id_, document.hash);
    }
}
