From ca3cf44c704bca4b221327a52e548437871e14ce Mon Sep 17 00:00:00 2001 From: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> Date: Thu, 26 May 2022 12:51:47 +0600 Subject: [PATCH] Do not match elastic orde (#1871) Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> --- server/core/src/fulltext.ts | 40 +------------------------------------ 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/server/core/src/fulltext.ts b/server/core/src/fulltext.ts index 91d8950fea..a97bee09c1 100644 --- a/server/core/src/fulltext.ts +++ b/server/core/src/fulltext.ts @@ -165,45 +165,7 @@ export class FullTextIndex implements WithFind { } } const resultIds = Array.from(getResultIds(ids, _id)) - return await this.getResult(ctx, _class, resultIds, mainQuery as DocumentQuery, options) - } - - private async getResult( - ctx: MeasureContext, - _class: Ref>, - ids: Ref[], - mainQuery: DocumentQuery, - options?: FindOptions - ): Promise> { - const orderMap = new Map, number>() - for (let index = 0; index < ids.length; index++) { - orderMap.set(ids[index], index) - } - const { sort, ...otherOptions } = options ?? {} - if (options?.lookup !== undefined && options.limit !== undefined) { - const resIds = await this.dbStorage.findAll( - ctx, - _class, - { _id: { $in: ids }, ...mainQuery }, - { projection: { _id: 1 } } - ) - const total = resIds.total - resIds.sort((a, b) => (orderMap.get(a._id) ?? 0) - (orderMap.get(b._id) ?? 0)) - const targetIds = resIds.slice(0, options.limit).map((p) => p._id) - - const result = await this.dbStorage.findAll(ctx, _class, { _id: { $in: targetIds }, ...mainQuery }, otherOptions) - result.sort((a, b) => (orderMap.get(a._id) ?? 0) - (orderMap.get(b._id) ?? 0)) - - return toFindResult(result, total) - } else { - const result = await this.dbStorage.findAll(ctx, _class, { _id: { $in: ids }, ...mainQuery }, otherOptions) - - const total = result.total - - result.sort((a, b) => (orderMap.get(a._id) ?? 0) - (orderMap.get(b._id) ?? 0)) - - return toFindResult(result, total) - } + return await this.dbStorage.findAll(ctx, _class, { _id: { $in: resultIds }, ...mainQuery }, options) } private getFullTextAttributes (clazz: Ref>, parentDoc?: Doc): AnyAttribute[] {