mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-17 05:47:32 +00:00
EZQMS-106: add elastic search by refs support (#3629)
Signed-off-by: Anna No <anna.no@xored.com>
This commit is contained in:
parent
2235310f91
commit
98a43a98bc
@ -94,7 +94,15 @@ export interface Type<T extends PropertyType> extends UXObject {}
|
|||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export enum IndexKind {
|
export enum IndexKind {
|
||||||
|
/**
|
||||||
|
* Attribute with this index annotation should be added to elastic for search
|
||||||
|
* Could be added to string or Ref attribute
|
||||||
|
* TODO: rename properly for better code readability
|
||||||
|
*/
|
||||||
FullText,
|
FullText,
|
||||||
|
/**
|
||||||
|
* For attribute with this annotation should be created an index in mongo database
|
||||||
|
*/
|
||||||
Indexed
|
Indexed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,12 +14,15 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import core, {
|
import core, {
|
||||||
|
AnyAttribute,
|
||||||
|
ArrOf,
|
||||||
Class,
|
Class,
|
||||||
Doc,
|
Doc,
|
||||||
DocIndexState,
|
DocIndexState,
|
||||||
DocumentQuery,
|
DocumentQuery,
|
||||||
DocumentUpdate,
|
DocumentUpdate,
|
||||||
extractDocKey,
|
extractDocKey,
|
||||||
|
IndexKind,
|
||||||
MeasureContext,
|
MeasureContext,
|
||||||
Ref,
|
Ref,
|
||||||
ServerStorage,
|
ServerStorage,
|
||||||
@ -95,6 +98,43 @@ export class FullTextPushStage implements FullTextPipelineStage {
|
|||||||
return { docs: [], pass: true }
|
return { docs: [], pass: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async indexRefAttributes (
|
||||||
|
attributes: Map<string, AnyAttribute>,
|
||||||
|
doc: DocIndexState,
|
||||||
|
elasticDoc: IndexedDoc,
|
||||||
|
metrics: MeasureContext
|
||||||
|
): Promise<void> {
|
||||||
|
for (const attribute in doc.attributes) {
|
||||||
|
const { attr } = extractDocKey(attribute)
|
||||||
|
const attrObj = attributes.get(attr)
|
||||||
|
if (
|
||||||
|
attrObj !== null &&
|
||||||
|
attrObj !== undefined &&
|
||||||
|
attrObj.index === IndexKind.FullText &&
|
||||||
|
(attrObj.type._class === core.class.RefTo ||
|
||||||
|
(attrObj.type._class === core.class.ArrOf && (attrObj.type as ArrOf<any>).of._class === core.class.RefTo))
|
||||||
|
) {
|
||||||
|
const attrStringValue = doc.attributes[attribute]
|
||||||
|
if (attrStringValue !== undefined && attrStringValue !== null && attrStringValue !== '') {
|
||||||
|
const refs = attrStringValue.split(',')
|
||||||
|
const refDocs = await metrics.with(
|
||||||
|
'ref-docs',
|
||||||
|
{},
|
||||||
|
async (ctx) =>
|
||||||
|
await this.dbStorage.findAll(ctx, core.class.DocIndexState, {
|
||||||
|
_id: { $in: refs }
|
||||||
|
})
|
||||||
|
)
|
||||||
|
if (refDocs.length > 0) {
|
||||||
|
refDocs.forEach((c) => {
|
||||||
|
updateDoc2Elastic(c.attributes, elasticDoc, c._id)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async collect (toIndex: DocIndexState[], pipeline: FullTextPipeline, metrics: MeasureContext): Promise<void> {
|
async collect (toIndex: DocIndexState[], pipeline: FullTextPipeline, metrics: MeasureContext): Promise<void> {
|
||||||
const bulk: IndexedDoc[] = []
|
const bulk: IndexedDoc[] = []
|
||||||
|
|
||||||
@ -162,6 +202,11 @@ export class FullTextPushStage implements FullTextPipelineStage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const allAttributes = pipeline.hierarchy.getAllAttributes(elasticDoc._class)
|
||||||
|
|
||||||
|
// Include child ref attributes
|
||||||
|
await this.indexRefAttributes(allAttributes, doc, elasticDoc, metrics)
|
||||||
|
|
||||||
this.checkIntegrity(elasticDoc)
|
this.checkIntegrity(elasticDoc)
|
||||||
bulk.push(elasticDoc)
|
bulk.push(elasticDoc)
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
|
@ -534,7 +534,7 @@ export class FullTextIndexPipeline implements FullTextPipeline {
|
|||||||
|
|
||||||
async checkIndexConsistency (dbStorage: ServerStorage): Promise<void> {
|
async checkIndexConsistency (dbStorage: ServerStorage): Promise<void> {
|
||||||
if (process.env.MODEL_VERSION !== undefined) {
|
if (process.env.MODEL_VERSION !== undefined) {
|
||||||
const modelVersion = await (await this.model.findAll(core.class.Version, {})).shift()
|
const modelVersion = (await this.model.findAll(core.class.Version, {})).shift()
|
||||||
if (modelVersion !== undefined) {
|
if (modelVersion !== undefined) {
|
||||||
const modelVersionString = versionToString(modelVersion)
|
const modelVersionString = versionToString(modelVersion)
|
||||||
if (modelVersionString !== process.env.MODEL_VERSION) {
|
if (modelVersionString !== process.env.MODEL_VERSION) {
|
||||||
|
@ -107,4 +107,4 @@ export const fieldStateId = 'fld-v5'
|
|||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export const fullTextPushStageId = 'fts-v4'
|
export const fullTextPushStageId = 'fts-v5'
|
||||||
|
Loading…
Reference in New Issue
Block a user