Merge pull request #15434 from ahmedhamidawan/fix_fullname_tool_search

[23.0] Add name+description ToolSearch
This commit is contained in:
Dannon
2023-01-30 11:26:17 -05:00
committed by GitHub
3 changed files with 14 additions and 3 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 ?
@@ -17,7 +17,7 @@ describe("test helpers in tool searching utilities", () => {
});
it("test tool search helper that searches for tools given keys", async () => {
const q = "collection";
let q = "collection";
let expectedResults = [
"__FILTER_FAILED_DATASETS__",
"__FILTER_EMPTY_DATASETS__",
@@ -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 () => {