diff --git a/server/core/src/fulltext.ts b/server/core/src/fulltext.ts index 80516f01f4..54c26c25ba 100644 --- a/server/core/src/fulltext.ts +++ b/server/core/src/fulltext.ts @@ -116,6 +116,7 @@ export class FullTextIndex implements WithFind { ): Promise> { console.log('search', query) const { _id, $search, ...mainQuery } = query + if ($search === undefined) return [] const docs = await this.adapter.search($search) console.log(docs) const ids: Ref[] = [] diff --git a/server/core/src/storage.ts b/server/core/src/storage.ts index 1838e4bc61..3047132485 100644 --- a/server/core/src/storage.ts +++ b/server/core/src/storage.ts @@ -164,7 +164,7 @@ class TServerStorage implements ServerStorage { ): Promise> { return await ctx.with('find-all', {}, (ctx) => { const domain = this.hierarchy.getDomain(clazz) - if (Object.keys(query)[0] === '$search') { + if (query.$search !== undefined && query.$search.length > 0) { return ctx.with('full-text-find-all', {}, (ctx) => this.fulltext.findAll(ctx, clazz, query, options)) } return ctx.with('db-find-all', { _class: clazz, domain }, () => diff --git a/server/core/src/types.ts b/server/core/src/types.ts index a65a64f60b..74a6221782 100644 --- a/server/core/src/types.ts +++ b/server/core/src/types.ts @@ -58,18 +58,13 @@ export interface IndexedDoc { data?: string } -/** - * @public - */ -export type SearchQuery = any // TODO: replace with DocumentQuery - /** * @public */ export interface FullTextAdapter { index: (doc: IndexedDoc) => Promise update: (id: Ref, update: Record) => Promise - search: (query: SearchQuery) => Promise + search: (search: string) => Promise } /** diff --git a/server/elastic/src/__tests__/adapter.test.ts b/server/elastic/src/__tests__/adapter.test.ts index d72b9d7b57..eb31f9520d 100644 --- a/server/elastic/src/__tests__/adapter.test.ts +++ b/server/elastic/src/__tests__/adapter.test.ts @@ -30,7 +30,7 @@ describe('client', () => { content0: 'hey there!' } await adapter.index(doc) - const hits = await adapter.search({}) + const hits = await adapter.search('') console.log(hits) }) diff --git a/server/elastic/src/adapter.ts b/server/elastic/src/adapter.ts index e701e1092d..1a35c45eaf 100644 --- a/server/elastic/src/adapter.ts +++ b/server/elastic/src/adapter.ts @@ -15,7 +15,7 @@ // import type { Doc, Ref, TxResult } from '@anticrm/core' -import type { FullTextAdapter, IndexedDoc, SearchQuery } from '@anticrm/server-core' +import type { FullTextAdapter, IndexedDoc } from '@anticrm/server-core' import { Client } from '@elastic/elasticsearch' @@ -27,15 +27,16 @@ class ElasticAdapter implements FullTextAdapter { } async search ( - query: SearchQuery + search: string ): Promise { + const query = search.replace(/[\\/+\-=&>