From 75e13d718ca8bab9900a6be7603786d7ed8998e1 Mon Sep 17 00:00:00 2001 From: Steve Von Worley Date: Wed, 16 Oct 2024 14:45:02 -0700 Subject: [PATCH] fix faceted search for complex queries involving ORs https://ucsc-cgl.atlassian.net/browse/DOCK-2592 dockstore/dockstore#6020 https://ucsc-cgl.atlassian.net/browse/SEAB-6308 --- src/app/search/query-builder.service.ts | 39 ++++++++++--------- .../shared/ai-bubble/ai-bubble.component.html | 2 +- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/app/search/query-builder.service.ts b/src/app/search/query-builder.service.ts index 547caaad3e..4bb323a7ac 100644 --- a/src/app/search/query-builder.service.ts +++ b/src/app/search/query-builder.service.ts @@ -173,26 +173,27 @@ export class QueryBuilderService { * @memberof SearchComponent */ appendFilter(body: any, aggKey: string | null, filters: Map>, exclusiveFilters: Array): Bodybuilder { - filters.forEach((value: Set, key: string) => { - value.forEach((insideFilter) => { - const isExclusiveFilter = exclusiveFilters.includes(key); - if (aggKey === key && !isExclusiveFilter) { - // Return some garbage filter because we've decided to append a filter, there's no turning back - // return body; // <--- this does not work - body = body.notFilter('term', 'some garbage term that hopefully never gets matched', insideFilter); - } else { - // value refers to the buckets selected - if (value.size > 1) { - body = body.orFilter('term', key, insideFilter); - } else { - if (isExclusiveFilter) { - body = body.filter('term', key, this.convertIntStringToBoolString(insideFilter)); - } else { - body = body.filter('term', key, insideFilter); - } + filters.forEach((values: Set, key: string) => { + const isExclusiveFilter = exclusiveFilters.includes(key); + if (aggKey === key && !isExclusiveFilter) { + // Return some garbage filter because we've decided to append a filter, there's no turning back + values.forEach((value) => { + body = body.notFilter('term', 'some garbage term that hopefully never gets matched', value); + }); + } else if (values.size == 1) { + // Add a filter that matches a single value + const [value] = values; + const convertedValue = isExclusiveFilter ? this.convertIntStringToBoolString(value) : value; + body = body.filter('term', key, convertedValue); + } else { + // Add a filter that matches at least one of multiple values + body = body.filter('bool', (b) => { + for (const value of values) { + b = b.orFilter('term', key, value); } - } - }); + return b; + }); + } }); return body; } diff --git a/src/app/shared/ai-bubble/ai-bubble.component.html b/src/app/shared/ai-bubble/ai-bubble.component.html index 925be1f3ce..d0271f9036 100644 --- a/src/app/shared/ai-bubble/ai-bubble.component.html +++ b/src/app/shared/ai-bubble/ai-bubble.component.html @@ -1,5 +1,5 @@