diff --git a/src/structures/structures.service.ts b/src/structures/structures.service.ts index 477324a4d4bf6d33b69e62fa73229e75871640cd..7c9b021980a81598267c22dd013e60f330b946a4 100644 --- a/src/structures/structures.service.ts +++ b/src/structures/structures.service.ts @@ -20,15 +20,15 @@ export class StructuresService { } public async search(searchString: string, filters?: Array<any>): Promise<Structure[]> { - let query: any; if (searchString && filters) { - query = [...this.parseFilter(filters), { $text: { $search: searchString } }]; + return this.structureModel + .find({ $and: [...this.parseFilter(filters), { $text: { $search: searchString } }] }) + .exec(); } else if (filters) { - query = this.parseFilter(filters); + return this.structureModel.find({ $or: this.parseFilter(filters) }).exec(); } else { - query = [{ $text: { $search: searchString } }]; + return this.structureModel.find({ $or: [{ $text: { $search: searchString } }] }).exec(); } - return this.structureModel.find({ $or: query }).exec(); } /**