X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/be8de5acc35c47d0b191223e5ece96fcf452ea5d..2a7fd99c212c33a1ec9911f8529fa5afc59a7bb2:/src/services/api/filter-builder.ts diff --git a/src/services/api/filter-builder.ts b/src/services/api/filter-builder.ts index aa0f011b03..bb97665a8c 100644 --- a/src/services/api/filter-builder.ts +++ b/src/services/api/filter-builder.ts @@ -2,14 +2,14 @@ // // SPDX-License-Identifier: AGPL-3.0 -export function joinFilters(filters0?: string, filters1?: string) { - return [filters0, filters1].filter(s => s).join(","); +export function joinFilters(...filters: string[]) { + return filters.filter(s => s).join(","); } export class FilterBuilder { constructor(private filters = "") { } - public addEqual(field: string, value?: string | boolean | null, resourcePrefix?: string) { + public addEqual(field: string, value?: string | string[] | boolean | null, resourcePrefix?: string) { return this.addCondition(field, "=", value, "", "", resourcePrefix); } @@ -25,6 +25,10 @@ export class FilterBuilder { return this.addCondition(field, "ilike", value, "%", "%", resourcePrefix); } + public addContains(field: string, value?: string, resourcePrefix?: string) { + return this.addCondition(field, "contains", value, "", "", resourcePrefix); + } + public addIsA(field: string, value?: string | string[], resourcePrefix?: string) { return this.addCondition(field, "is_a", value, "", "", resourcePrefix); } @@ -56,12 +60,31 @@ export class FilterBuilder { public addExists(value?: string, resourcePrefix?: string) { return this.addCondition("properties", "exists", value, "", "", resourcePrefix); } + public addDoesNotExist(field: string, resourcePrefix?: string) { + return this.addCondition("properties." + field, "exists", false, "", "", resourcePrefix); + } + + public addFullTextSearch(value: string, table?: string) { + const regex = /"[^"]*"/; + const matches: any[] = []; + + let match = value.match(regex); + + while (match) { + value = value.replace(match[0], ""); + matches.push(match[0].replace(/"/g, '')); + match = value.match(regex); + } + + let searchIn = 'any'; + if (table) { + searchIn = table + ".any"; + } - public addFullTextSearch(value: string) { - const terms = value.trim().split(/(\s+)/); + const terms = value.trim().split(/(\s+)/).concat(matches); terms.forEach(term => { if (term !== " ") { - this.addCondition("any", "ilike", term, "%", "%"); + this.addCondition(searchIn, "ilike", term, "%", "%"); } }); return this;