diff --git a/src/auth.js b/src/auth.js index 58fc35fbe59ce09efd54fd179c0f75837fd6acf9..068759b9f86cbd5d8fc14d9b2bae62a11cfd8e7d 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 5968d46ee5fe600bbfc518e2edd8994b773d8c3b..0fd7fb942f4fc9444715ed82c777d0c63cc54954 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