// // Copyright © 2020, 2021 Anticrm Platform Contributors. // Copyright © 2021 Hardcore Engineering Inc. // // Licensed under the Eclipse Public License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. You may // obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // // See the License for the specific language governing permissions and // limitations under the License. // import type { Class, Doc, DocumentQuery, Ref, TxResult } from '@anticrm/core' import type { FullTextAdapter, IndexedDoc } from '@anticrm/server-core' import { Client } from '@elastic/elasticsearch' class ElasticAdapter implements FullTextAdapter { constructor (private readonly client: Client, private readonly db: string) {} async close (): Promise { await this.client.close() } async search (_class: Ref>, query: DocumentQuery, size: number | undefined): Promise { if (query.$search === undefined) return [] const search = query.$search.replace(/[\\/+\-=&> hit._source) } catch (err) { console.error(JSON.stringify(err, null, 2)) return [] } } async index (doc: IndexedDoc): Promise { if (doc.data === undefined) { await this.client.index({ index: this.db, id: doc.id, type: '_doc', body: doc }) } else { await this.client.index({ index: this.db, id: doc.id, type: '_doc', pipeline: 'attachment', body: doc }) } return {} } async update (id: Ref, update: Record): Promise { await this.client.update({ index: this.db, id, body: { doc: update } }) return {} } } /** * @public */ export async function createElasticAdapter ( url: string, dbName: string ): Promise Promise }> { const client = new Client({ node: url }) return new ElasticAdapter(client, dbName) }