diff --git a/packages/query/src/index.ts b/packages/query/src/index.ts index e9ed78f6b4..f11d1b91e3 100644 --- a/packages/query/src/index.ts +++ b/packages/query/src/index.ts @@ -228,15 +228,25 @@ export class LiveQuery extends TxProcessor implements Client { } const pos = q.result.findIndex((p) => p._id === tx.objectId) if (pos !== -1) { - const updatedDoc = q.result[pos] - await this.__updateDoc(q, updatedDoc, tx) - if (!this.match(q, updatedDoc)) { - q.result.splice(pos, 1) + // If query contains search we must check use fulltext + if (q.query.$search != null && q.query.$search.length > 0) { + const match = await this.findOne(q._class, { $search: q.query.$search, _id: tx.objectId }, q.options) + if (match === undefined) { + q.result.splice(pos, 1) + } else { + q.result[pos] = match + } } else { - q.result[pos] = updatedDoc + const updatedDoc = q.result[pos] + await this.__updateDoc(q, updatedDoc, tx) + if (!this.match(q, updatedDoc)) { + q.result.splice(pos, 1) + } else { + q.result[pos] = updatedDoc + } } this.sort(q, tx) - await this.callback(updatedDoc, q) + await this.callback(q.result[pos], q) } else if (this.matchQuery(q, tx)) { return await this.refresh(q) } @@ -383,6 +393,12 @@ export class LiveQuery extends TxProcessor implements Client { // No need to update, document already in results. return } + + // If query contains search we must check use fulltext + if (q.query.$search != null && q.query.$search.length > 0) { + const match = await this.findOne(q._class, { $search: q.query.$search, _id: doc._id }, q.options) + if (match === undefined) return + } q.result.push(doc) if (q.options?.sort !== undefined) { diff --git a/plugins/recruit-resources/src/components/VacancyPresenter.svelte b/plugins/recruit-resources/src/components/VacancyPresenter.svelte index 5503dadcca..f2149ea2ce 100644 --- a/plugins/recruit-resources/src/components/VacancyPresenter.svelte +++ b/plugins/recruit-resources/src/components/VacancyPresenter.svelte @@ -16,17 +16,12 @@ diff --git a/server/core/src/fulltext.ts b/server/core/src/fulltext.ts index 93af4e5076..29c04c5bff 100644 --- a/server/core/src/fulltext.ts +++ b/server/core/src/fulltext.ts @@ -28,6 +28,7 @@ import core, { IndexKind, MeasureContext, Obj, + ObjQueryType, PropertyType, Ref, Tx, @@ -148,7 +149,8 @@ export class FullTextIndex implements WithFind { ids.add(doc.attachedTo) } } - return await this.dbStorage.findAll(ctx, _class, { _id: { $in: Array.from(ids) as any }, ...mainQuery }, options) // TODO: remove `as any` + const resultIds = getResultIds(ids, _id) + return await this.dbStorage.findAll(ctx, _class, { _id: { $in: resultIds }, ...mainQuery }, options) } private getFullTextAttributes (clazz: Ref>, parentDoc?: Doc): AnyAttribute[] { @@ -309,3 +311,25 @@ function isFullTextAttribute (attr: AnyAttribute): boolean { (attr.type._class === core.class.TypeString || attr.type._class === core.class.TypeMarkup) ) } + +function getResultIds (ids: Set>, _id: ObjQueryType> | undefined): Ref[] { + let result = [] + if (_id !== undefined) { + if (typeof _id === 'string') { + if (!ids.has(_id)) { + return [] + } else { + result = [_id] + } + } else if (_id.$in !== undefined) { + for (const id of _id.$in) { + if (ids.has(id)) { + result.push(id) + } + } + } + } else { + result = Array.from(ids) + } + return result +}