checkpoint

Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
Andrey Platov 2021-09-13 23:21:39 +02:00
parent 5f9e68c500
commit 3beb5160be
No known key found for this signature in database
GPG Key ID: C8787EFEB4B64AF0
4 changed files with 21 additions and 11 deletions

View File

@ -16,7 +16,7 @@
import { TxCreateDoc, Doc, Ref, Class, Obj, Hierarchy, AnyAttribute, Storage, DocumentQuery, FindOptions, FindResult, TxProcessor, IndexKind } from '@anticrm/core'
import type { IndexedContent, FullTextAdapter } from './types'
import type { IndexedContent, FullTextAdapter, WithFind } from './types'
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const NO_INDEX = {} as AnyAttribute
@ -26,7 +26,8 @@ export class FullTextIndex extends TxProcessor implements Storage {
constructor (
private readonly hierarchy: Hierarchy,
private readonly adapter: FullTextAdapter
private readonly adapter: FullTextAdapter,
private readonly dbStorage: WithFind
) {
super()
}
@ -34,8 +35,8 @@ export class FullTextIndex extends TxProcessor implements Storage {
async findAll<T extends Doc> (_class: Ref<Class<T>>, query: DocumentQuery<T>, options?: FindOptions<T>): Promise<FindResult<T>> {
console.log('search', query)
const docs = await this.adapter.search(query)
console.log('indexed docs', docs)
return []
const ids = docs.map(doc => doc.id as Ref<T>)
return this.dbStorage.findAll(_class, { _id: { $in: ids as any } }, options)
}
private findFullTextAttribute (clazz: Ref<Class<Obj>>): AnyAttribute | undefined {

View File

@ -16,7 +16,7 @@
import type { ServerStorage, Domain, Tx, TxCUD, Doc, Ref, Class, DocumentQuery, FindResult, FindOptions, Storage } from '@anticrm/core'
import core, { Hierarchy, DOMAIN_TX } from '@anticrm/core'
import type { FullTextAdapterFactory } from './types'
import type { FullTextAdapterFactory, FullTextAdapter } from './types'
import { FullTextIndex } from './fulltext'
import { Triggers } from './triggers'
@ -65,14 +65,17 @@ export interface DbConfiguration {
}
class TServerStorage implements ServerStorage {
private readonly fulltext: FullTextIndex
constructor (
private readonly domains: Record<string, string>,
private readonly defaultAdapter: string,
private readonly adapters: Map<string, DbAdapter>,
private readonly hierarchy: Hierarchy,
private readonly triggers: Triggers,
private readonly fulltext: FullTextIndex
fulltextAdapter: FullTextAdapter
) {
this.fulltext = new FullTextIndex(hierarchy, fulltextAdapter, this)
}
private getAdapter (domain: Domain): DbAdapter {
@ -166,7 +169,6 @@ export async function createServerStorage (conf: DbConfiguration): Promise<Serve
}
const fulltextAdapter = await conf.fulltextAdapter.factory(conf.fulltextAdapter.url, conf.workspace)
const fulltext = new FullTextIndex(hierarchy, fulltextAdapter)
return new TServerStorage(conf.domains, conf.defaultAdapter, adapters, hierarchy, triggers, fulltext)
return new TServerStorage(conf.domains, conf.defaultAdapter, adapters, hierarchy, triggers, fulltextAdapter)
}

View File

@ -14,7 +14,7 @@
// limitations under the License.
//
import type { Tx, Ref, Doc, Class, Space, Timestamp, Account } from '@anticrm/core'
import type { Tx, Ref, Doc, Class, Space, Timestamp, Account, FindResult, DocumentQuery, FindOptions } from '@anticrm/core'
import { TxFactory } from '@anticrm/core'
import type { Resource } from '@anticrm/platform'
@ -79,3 +79,10 @@ export type FullTextAdapterFactory = (url: string, workspace: string) => Promise
export interface Token {
workspace: string
}
/**
* @public
*/
export interface WithFind {
findAll: <T extends Doc> (clazz: Ref<Class<T>>, query: DocumentQuery<T>, options?: FindOptions<T>) => Promise<FindResult<T>>
}

View File

@ -33,8 +33,8 @@ class ElasticAdapter implements FullTextAdapter {
body: {
query: {
match: {
// content: query.$search,
'attachment.content': query.$search
content: query.$search
// 'attachment.content': query.$search
}
}
}