Skip to content

Conversation

TomyCesaille
Copy link
Contributor

#9

@aliasadidev
Copy link
Owner

Hi @TomyCesaille.
Thank you for your collaboration.
I think we have an issue. If we've two repositories and both have the same result, it's not a good idea that concat them together (duplicate results may occur).
I think it's better that, Insert all results into one list, and makes it unique, and sort it.
I've prepared a sample code.

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)

@TomyCesaille
Copy link
Contributor Author

I don't know how VS2019-17 handle the duplicates though. I've been avoiding this risks for years.
Thanks for the code sample, I'll integrate it.

First source listed will have priority in case of duplicates; I guess this is fair.

@TomyCesaille
Copy link
Contributor Author

New commits gives:

  • No duplicates (first source will be kept)
  • Best matching algorithm as follow:
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 startsWith logic. It mimic quite well the way VS 2017-19 rank results with multiple sources (they maybe use the downloaded counter in consideration ?).

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 .ts formatter in .vscode/settings.json for the futur collaborators.

@aliasadidev
Copy link
Owner

The sort has a problem in some cases (When the popular packages don't start with the user query).

The Nuget result

image

The extension result

image

I think using the totalDownloads property is more efficient.

@TomyCesaille
Copy link
Contributor Author

Sorting by installs was my first try. I didn't liked the behavior so much.

For instance, I have a Some.MongoWrapper NuGet in my company NuGet source.
Searching Some.Mongo is ranking Some.MongoWrapper first in VS2017-19 (despite the poor 1k downloads).
However, sorting by downloads in here would shows the official MongoDB drivers packages first which can be annoying.

I let you decide for the feature though, it won't stop me from using it.

@aliasadidev
Copy link
Owner

We have two types of users:

  1. Those users that use the single repository
  2. Those users that use more than 1 repository

For type 1, we don't need to sort and unique it
For type 2, your solution would be better( the company's packages aren't always at the end of the list)

We have to see both of them

@aliasadidev aliasadidev requested review from aliasadidev and removed request for aliasadidev January 29, 2021 10:56
@aliasadidev aliasadidev linked an issue Jan 29, 2021 that may be closed by this pull request
@aliasadidev aliasadidev merged commit 0a7b1e5 into aliasadidev:support-several-nuget-servers Jan 29, 2021
@TomyCesaille
Copy link
Contributor Author

Nice implementation ;)

@aliasadidev
Copy link
Owner

I waiting for PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support several nuget servers ?
2 participants