mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-23 11:31:57 +03:00
index all string attributes
Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
parent
736ee30dca
commit
5439f55397
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -44,6 +44,8 @@ export class TMessage extends TDoc implements Message {
|
||||
@Model(chunter.class.Comment, core.class.Doc, DOMAIN_COMMENT)
|
||||
export class TComment extends TDoc implements Comment {
|
||||
attachedTo!: Ref<Doc>
|
||||
@Prop(TypeString(), 'Message' as IntlString)
|
||||
@Index(IndexKind.FullText)
|
||||
message!: string
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
//
|
||||
import type { Plugin, StatusCode } from '@anticrm/platform'
|
||||
import { plugin } from '@anticrm/platform'
|
||||
import type { Account, Class, Doc, Obj, Ref, Space, AnyAttribute, State } from './classes'
|
||||
import type { Account, Class, Doc, Obj, Ref, Space, AnyAttribute, State, Type } from './classes'
|
||||
import type { Tx, TxCreateDoc, TxCUD, TxMixin, TxRemoveDoc, TxUpdateDoc } from './tx'
|
||||
|
||||
/**
|
||||
@ -36,7 +36,8 @@ export default plugin(coreId, {
|
||||
TxRemoveDoc: '' as Ref<Class<TxRemoveDoc<Doc>>>,
|
||||
Space: '' as Ref<Class<Space>>,
|
||||
Account: '' as Ref<Class<Account>>,
|
||||
State: '' as Ref<Class<State>>
|
||||
State: '' as Ref<Class<State>>,
|
||||
TypeString: '' as Ref<Class<Type<string>>>
|
||||
},
|
||||
space: {
|
||||
Tx: '' as Ref<Space>,
|
||||
|
@ -13,12 +13,10 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import type { Class, Ref, Type } from '@anticrm/core'
|
||||
import core, { coreId } from '@anticrm/core'
|
||||
import { mergeIds } from '@anticrm/platform'
|
||||
|
||||
export default mergeIds(coreId, core, {
|
||||
class: {
|
||||
TypeString: '' as Ref<Class<Type<string>>>
|
||||
}
|
||||
})
|
||||
|
@ -14,16 +14,28 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import { TxCreateDoc, Doc, Ref, Class, Obj, Hierarchy, AnyAttribute, Storage, DocumentQuery, FindOptions, FindResult, TxProcessor, IndexKind } from '@anticrm/core'
|
||||
import core, { TxCreateDoc, Doc, Ref, Class, Obj, Hierarchy, AnyAttribute, Storage, DocumentQuery, FindOptions, FindResult, TxProcessor } from '@anticrm/core'
|
||||
import type { AttachedDoc } from '@anticrm/core'
|
||||
|
||||
import type { IndexedDoc, FullTextAdapter, WithFind } from './types'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
const NO_INDEX = {} as AnyAttribute
|
||||
const NO_INDEX = [] as AnyAttribute[]
|
||||
|
||||
function buildContent (doc: any, attributes: AnyAttribute[]): string {
|
||||
let result = ''
|
||||
for (const attr of attributes) {
|
||||
const value = doc[attr.name]
|
||||
if (value !== undefined) {
|
||||
result += value as string
|
||||
result += ' '
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export class FullTextIndex extends TxProcessor implements Storage {
|
||||
private readonly indexes = new Map<Ref<Class<Obj>>, AnyAttribute>()
|
||||
private readonly indexes = new Map<Ref<Class<Obj>>, AnyAttribute[]>()
|
||||
|
||||
constructor (
|
||||
private readonly hierarchy: Hierarchy,
|
||||
@ -41,27 +53,32 @@ export class FullTextIndex extends TxProcessor implements Storage {
|
||||
return this.dbStorage.findAll(_class, { _id: { $in: ids as any } }, options) // TODO: remove `as any`
|
||||
}
|
||||
|
||||
private findFullTextAttribute (clazz: Ref<Class<Obj>>): AnyAttribute | undefined {
|
||||
const attribute = this.indexes.get(clazz)
|
||||
if (attribute === undefined) {
|
||||
const attributes = this.hierarchy.getAllAttributes(clazz)
|
||||
for (const [, attr] of attributes) {
|
||||
if (attr.index === IndexKind.FullText) {
|
||||
this.indexes.set(clazz, attr)
|
||||
return attr
|
||||
private getFullTextAttributes (clazz: Ref<Class<Obj>>): AnyAttribute[] | undefined {
|
||||
const attributes = this.indexes.get(clazz)
|
||||
if (attributes === undefined) {
|
||||
const allAttributes = this.hierarchy.getAllAttributes(clazz)
|
||||
const result: AnyAttribute[] = []
|
||||
for (const [, attr] of allAttributes) {
|
||||
if (attr.type._class === core.class.TypeString) {
|
||||
result.push(attr)
|
||||
}
|
||||
}
|
||||
this.indexes.set(clazz, NO_INDEX)
|
||||
} else if (attribute !== NO_INDEX) {
|
||||
return attribute
|
||||
if (result.length > 0) {
|
||||
this.indexes.set(clazz, result)
|
||||
return result
|
||||
} else {
|
||||
this.indexes.set(clazz, NO_INDEX)
|
||||
}
|
||||
} else if (attributes !== NO_INDEX) {
|
||||
return attributes
|
||||
}
|
||||
}
|
||||
|
||||
protected override async txCreateDoc (tx: TxCreateDoc<Doc>): Promise<void> {
|
||||
const attribute = this.findFullTextAttribute(tx.objectClass)
|
||||
if (attribute === undefined) return
|
||||
const attributes = this.getFullTextAttributes(tx.objectClass)
|
||||
if (attributes === undefined) return
|
||||
const doc = TxProcessor.createDoc2Doc(tx)
|
||||
const content = (doc as any)[attribute.name]
|
||||
const content = buildContent(doc, attributes) // (doc as any)[attribute.name]
|
||||
const indexedDoc: IndexedDoc = {
|
||||
id: doc._id,
|
||||
_class: doc._class,
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user