Merge branch '19051-handle-quotes-in-search' into main
[arvados-workbench2.git] / src / services / api / filter-builder.ts
index 489f7b8947a4f962ce1768b57e383269b28800db..da67935a1e5d8a44c5bf2c601c3fc639204ca8ab 100644 (file)
@@ -9,7 +9,7 @@ export function joinFilters(...filters: string[]) {
 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);
     }
 
@@ -60,9 +60,23 @@ 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) {
-        const terms = value.trim().split(/(\s+)/);
+        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);
+        }
+
+        const terms = value.trim().split(/(\s+)/).concat(matches);
         terms.forEach(term => {
             if (term !== " ") {
                 this.addCondition("any", "ilike", term, "%", "%");