-
Notifications
You must be signed in to change notification settings - Fork 21
bug fix search package for multiple sources #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug fix search package for multiple sources #10
Conversation
Hi @TomyCesaille. let server1Result = [
"Microsoft.Extensions.DependencyInjection",
"Microsoft.Extensions.Configuration.Json",
"Microsoft.AspNetCore.TestHost",
"Microsoft.NET.Test.Sdk"
];
let server2Result = [
"Microsoft.Extensions.DependencyInjection",
"Microsoft.Extensions.Configuration.Json",
"Microsoft.AspNetCore.TestHost",
"Microsoft.NET.Test.Sdk",
"Microsoft.EntityFrameworkCore.Relational",
"Microsoft.EntityFrameworkCore.Abstractions"
];
let server3Result = [
"Microsoft.Extensions.DependencyInjection",
"Microsoft.Extensions.Configuration.Json",
"Microsoft.NET.Test.Sdk2",
];
/// serverNResult ...
let keyValuePackages: Record<string, number> = {};
let packages = [...server1Result, ...server2Result, ...server3Result];
packages.forEach(pkg => {
keyValuePackages[pkg] = keyValuePackages[pkg] ? keyValuePackages[pkg] + 1 : 1;
});
let resultConsolided = Object.keys(keyValuePackages).sort((n1, n2) => keyValuePackages[n2] - keyValuePackages[n1]);
console.log(resultConsolided) |
I don't know how VS2019-17 handle the duplicates though. I've been avoiding this risks for years. First source listed will have priority in case of duplicates; I guess this is fair. |
New commits gives:
const isBestMatch = (packageNuget: any, query: string) => {
return packageNuget.id.toLowerCase().startsWith(query.toLowerCase());
};
let packagesUniques = uniqBy(packages, "id");
let packagesBestMatch = packagesUniques.filter(o => isBestMatch(o, query));
packagesBestMatch = packagesBestMatch.concat().sort(sortBy("id"));
let packagesOthers = packagesUniques.filter(o => !isBestMatch(o, query));
packagesOthers = packagesOthers.concat().sort(sortBy("id"));
return { data: [...packagesBestMatch, ...packagesOthers], totalHits: packagesUniques.length }; It returns the package that match the best based on the Counting the number of duplicates between sources and use it a a sort filter like you were suggestion in your code sample is not really relevant for user experience. Looks good to you ? Also, I specified your |
Sorting by installs was my first try. I didn't liked the behavior so much. For instance, I have a I let you decide for the feature though, it won't stop me from using it. |
We have two types of users:
For type 1, we don't need to sort and unique it We have to see both of them |
Nice implementation ;) |
I waiting for PR |
#9