From a1616b4e0ce86f92f852bb578f3b3318884c43d8 Mon Sep 17 00:00:00 2001
From: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com>
Date: Fri, 11 Feb 2022 23:55:14 +0600
Subject: [PATCH 1/2] Search query fix
Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com>
---
packages/query/src/index.ts | 28 +++++++++++++++----
.../src/components/VacancyPresenter.svelte | 7 +----
server/core/src/fulltext.ts | 26 ++++++++++++++++-
3 files changed, 48 insertions(+), 13 deletions(-)
diff --git a/packages/query/src/index.ts b/packages/query/src/index.ts
index e9ed78f6b4..dc2ae92b80 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 })
+ 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 })
+ 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
+}
From 7e40d3943d6a794085686e42f66c65a482b88622 Mon Sep 17 00:00:00 2001
From: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com>
Date: Sat, 12 Feb 2022 01:01:57 +0600
Subject: [PATCH 2/2] lookup fix
Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com>
---
packages/query/src/index.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/packages/query/src/index.ts b/packages/query/src/index.ts
index dc2ae92b80..f11d1b91e3 100644
--- a/packages/query/src/index.ts
+++ b/packages/query/src/index.ts
@@ -230,7 +230,7 @@ export class LiveQuery extends TxProcessor implements Client {
if (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 })
+ 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 {
@@ -396,7 +396,7 @@ export class LiveQuery extends TxProcessor implements Client {
// 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 })
+ const match = await this.findOne(q._class, { $search: q.query.$search, _id: doc._id }, q.options)
if (match === undefined) return
}
q.result.push(doc)
]