From c1aba9728c1ae735715f83014f38d89cbda27df3 Mon Sep 17 00:00:00 2001 From: Hermann <blumh@ethz.ch> Date: Thu, 17 May 2018 18:23:30 +0200 Subject: [PATCH] add case-insensitive regex search to online and offline search --- src/auth.js | 5 ++++- src/listcontroller.js | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/auth.js b/src/auth.js index 58fc35f..068759b 100644 --- a/src/auth.js +++ b/src/auth.js @@ -123,7 +123,10 @@ export class ResourceHandler { const searchQuery = { $or: this.searchKeys.map((key) => { const fieldQuery = {}; - fieldQuery[key] = query.search; + fieldQuery[key] = { + $regex: `${query.search}`, + $options: 'i' + }; return fieldQuery; }), }; diff --git a/src/listcontroller.js b/src/listcontroller.js index 5968d46..0fd7fb9 100644 --- a/src/listcontroller.js +++ b/src/listcontroller.js @@ -51,6 +51,7 @@ export default class DatalistController { // embedded keys like user.firstname if (!this.onlineSearch && this.clientSearchKeys.length > 0 && this.search) { const response = []; + const searchRegex = new RegExp(this.search, "i") // We go through all response items and will add them to response if // they match the query. data._items.forEach((item) => { @@ -63,13 +64,13 @@ export default class DatalistController { key.split('.').forEach((subKey) => { intermediateObject = intermediateObject[subKey]; }); - if (intermediateObject.includes(this.search)) { + if (intermediateObject.match(searchRegex)) { response.push(item); // return true to end the search of this object, it is already // matched return true; } - } else if (item[key] && item[key].includes(this.search)) { + } else if (item[key] && item[key].match(searchRegex)) { response.push(item); // return true to end the search of this object, it is already // matched -- GitLab