Add name+description ToolSearch

This commit is contained in:
Ahmed Awan
2023-01-28 23:26:48 +05:00
parent 790bb6e458
commit 63d0e5c149
3 changed files with 13 additions and 2 deletions
@@ -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 {
+6 -1
View File
@@ -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 ?
@@ -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 () => {