From 63d0e5c14984265eb78db36b8635c84dccd7f8b0 Mon Sep 17 00:00:00 2001 From: Ahmed Awan Date: Sat, 28 Jan 2023 23:26:48 +0500 Subject: [PATCH] Add name+description ToolSearch --- client/src/components/Panels/Common/ToolSearch.vue | 2 +- client/src/components/Panels/utilities.js | 7 ++++++- client/src/components/Panels/utilities.test.js | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/client/src/components/Panels/Common/ToolSearch.vue b/client/src/components/Panels/Common/ToolSearch.vue index dd2a5303020..167659c2870 100644 --- a/client/src/components/Panels/Common/ToolSearch.vue +++ b/client/src/components/Panels/Common/ToolSearch.vue @@ -109,7 +109,7 @@ export default { this.$emit("onResults", this.favoritesResults); } else { // keys with sorting order - const keys = { exact: 2, name: 1, description: 0 }; + const keys = { exact: 3, name: 2, description: 1, combined: 0 }; this.$emit("onResults", searchToolsByKeys(this.toolsList, keys, q)); } } else { diff --git a/client/src/components/Panels/utilities.js b/client/src/components/Panels/utilities.js index 8431e0828c1..900e32079ba 100644 --- a/client/src/components/Panels/utilities.js +++ b/client/src/components/Panels/utilities.js @@ -89,7 +89,12 @@ export function searchToolsByKeys(tools, keys, query) { const returnedTools = []; for (const tool of tools) { for (const key of Object.keys(keys)) { - const actualValue = tool[key] ? tool[key].toLowerCase() : ""; + let actualValue = ""; + if (key === "combined") { + actualValue = tool.name.toLowerCase() + " " + tool.description.toLowerCase(); + } else { + actualValue = tool[key] ? tool[key].toLowerCase() : ""; + } const queryLowerCase = query.toLowerCase(); if (actualValue.match(queryLowerCase)) { // do we care for exact matches && is it an exact match ? diff --git a/client/src/components/Panels/utilities.test.js b/client/src/components/Panels/utilities.test.js index eb6fdadad6f..976c43e1a47 100644 --- a/client/src/components/Panels/utilities.test.js +++ b/client/src/components/Panels/utilities.test.js @@ -37,6 +37,12 @@ describe("test helpers in tool searching utilities", () => { keys = { description: 0, name: 1 }; results = searchToolsByKeys(normalizeTools(toolsList), keys, q); expect(results).toEqual(expectedResults); + + q = "filter empty datasets"; + expectedResults = ["__FILTER_EMPTY_DATASETS__"]; + keys = { description: 1, name: 2, combined: 0 }; + results = searchToolsByKeys(normalizeTools(toolsList), keys, q); + expect(results).toEqual(expectedResults); }); it("test tool filtering helpers on toolsList given list of ids", async () => {