mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-20 07:10:02 +00: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)
|
@Model(chunter.class.Comment, core.class.Doc, DOMAIN_COMMENT)
|
||||||
export class TComment extends TDoc implements Comment {
|
export class TComment extends TDoc implements Comment {
|
||||||
attachedTo!: Ref<Doc>
|
attachedTo!: Ref<Doc>
|
||||||
|
@Prop(TypeString(), 'Message' as IntlString)
|
||||||
|
@Index(IndexKind.FullText)
|
||||||
message!: string
|
message!: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
//
|
//
|
||||||
import type { Plugin, StatusCode } from '@anticrm/platform'
|
import type { Plugin, StatusCode } from '@anticrm/platform'
|
||||||
import { plugin } 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'
|
import type { Tx, TxCreateDoc, TxCUD, TxMixin, TxRemoveDoc, TxUpdateDoc } from './tx'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,7 +36,8 @@ export default plugin(coreId, {
|
|||||||
TxRemoveDoc: '' as Ref<Class<TxRemoveDoc<Doc>>>,
|
TxRemoveDoc: '' as Ref<Class<TxRemoveDoc<Doc>>>,
|
||||||
Space: '' as Ref<Class<Space>>,
|
Space: '' as Ref<Class<Space>>,
|
||||||
Account: '' as Ref<Class<Account>>,
|
Account: '' as Ref<Class<Account>>,
|
||||||
State: '' as Ref<Class<State>>
|
State: '' as Ref<Class<State>>,
|
||||||
|
TypeString: '' as Ref<Class<Type<string>>>
|
||||||
},
|
},
|
||||||
space: {
|
space: {
|
||||||
Tx: '' as Ref<Space>,
|
Tx: '' as Ref<Space>,
|
||||||
|
@ -13,12 +13,10 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
|
|
||||||
import type { Class, Ref, Type } from '@anticrm/core'
|
|
||||||
import core, { coreId } from '@anticrm/core'
|
import core, { coreId } from '@anticrm/core'
|
||||||
import { mergeIds } from '@anticrm/platform'
|
import { mergeIds } from '@anticrm/platform'
|
||||||
|
|
||||||
export default mergeIds(coreId, core, {
|
export default mergeIds(coreId, core, {
|
||||||
class: {
|
class: {
|
||||||
TypeString: '' as Ref<Class<Type<string>>>
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -14,16 +14,28 @@
|
|||||||
// limitations under the License.
|
// 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 { AttachedDoc } from '@anticrm/core'
|
||||||
|
|
||||||
import type { IndexedDoc, FullTextAdapter, WithFind } from './types'
|
import type { IndexedDoc, FullTextAdapter, WithFind } from './types'
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
// 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 {
|
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 (
|
constructor (
|
||||||
private readonly hierarchy: Hierarchy,
|
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`
|
return this.dbStorage.findAll(_class, { _id: { $in: ids as any } }, options) // TODO: remove `as any`
|
||||||
}
|
}
|
||||||
|
|
||||||
private findFullTextAttribute (clazz: Ref<Class<Obj>>): AnyAttribute | undefined {
|
private getFullTextAttributes (clazz: Ref<Class<Obj>>): AnyAttribute[] | undefined {
|
||||||
const attribute = this.indexes.get(clazz)
|
const attributes = this.indexes.get(clazz)
|
||||||
if (attribute === undefined) {
|
if (attributes === undefined) {
|
||||||
const attributes = this.hierarchy.getAllAttributes(clazz)
|
const allAttributes = this.hierarchy.getAllAttributes(clazz)
|
||||||
for (const [, attr] of attributes) {
|
const result: AnyAttribute[] = []
|
||||||
if (attr.index === IndexKind.FullText) {
|
for (const [, attr] of allAttributes) {
|
||||||
this.indexes.set(clazz, attr)
|
if (attr.type._class === core.class.TypeString) {
|
||||||
return attr
|
result.push(attr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.indexes.set(clazz, NO_INDEX)
|
if (result.length > 0) {
|
||||||
} else if (attribute !== NO_INDEX) {
|
this.indexes.set(clazz, result)
|
||||||
return attribute
|
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> {
|
protected override async txCreateDoc (tx: TxCreateDoc<Doc>): Promise<void> {
|
||||||
const attribute = this.findFullTextAttribute(tx.objectClass)
|
const attributes = this.getFullTextAttributes(tx.objectClass)
|
||||||
if (attribute === undefined) return
|
if (attributes === undefined) return
|
||||||
const doc = TxProcessor.createDoc2Doc(tx)
|
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 = {
|
const indexedDoc: IndexedDoc = {
|
||||||
id: doc._id,
|
id: doc._id,
|
||||||
_class: doc._class,
|
_class: doc._class,
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user