Skip to content

Commit

Permalink
improve sorting vscodeworkspaces plugin (#10861)
Browse files Browse the repository at this point in the history
* improve sorting vscodeworkspaces

* String.empty to string.empty. use ToLowerInvariant() instead of ToLower().

* more String.empty to string.empty. use ToLowerInvariant() instead of ToLower().
  • Loading branch information
ricardosantos9521 committed May 4, 2021
1 parent 86e4a91 commit 4dab056
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public List<Result> Query(Query query)
{
var title = $"{a.Host}";
if (a.User != null && a.User != String.Empty && a.HostName != null && a.HostName != String.Empty)
if (a.User != null && a.User != string.Empty && a.HostName != null && a.HostName != string.Empty)
{
title += $" [{a.User}@{a.HostName}]";
}
Expand Down Expand Up @@ -135,29 +135,34 @@ public List<Result> Query(Query query)
});
}

if (query.ActionKeyword == string.Empty || (query.ActionKeyword != string.Empty && query.Search != string.Empty))
{
results = results.Where(a => a.Title.ToLowerInvariant().Contains(query.Search.ToLowerInvariant())).ToList();
}

results.ForEach(x =>
{
if (x.Score == 0)
{
x.Score = 100;
}
//intersect the title with the query
var intersection = Convert.ToInt32(x.Title.ToLowerInvariant().Intersect(query.Search.ToLowerInvariant()).Count() * query.Search.Count());
var differenceWithQuery = Convert.ToInt32((x.Title.Count() - intersection) * query.Search.Count() * 0.7);
x.Score = x.Score - differenceWithQuery + intersection;
//if is a remote machine give it 12 extra points
if (x.ContextData is VSCodeRemoteMachine)
{
x.Score = x.Score + (query.Search.Count() * 5);
x.Score = Convert.ToInt32(x.Score + intersection * 2);
}
//intersect the title with the query
var intersection = x.Title.ToLower().Intersect(query.Search.ToLower()).Count();
x.Score = x.Score - (Convert.ToInt32(((x.Title.Count() - intersection) *2.5)));
});

results = results.OrderBy(x => x.Title).ToList();

if (query.ActionKeyword == String.Empty || (query.ActionKeyword != String.Empty && query.Search != String.Empty))
results = results.OrderByDescending(x => x.Score).ToList();
if (query.Search == string.Empty || query.Search.Replace(" ", "") == string.Empty)
{
results = results.Where(a => a.Title.ToLower().Contains(query.Search.ToLower())).ToList();
results = results.OrderBy(x => x.Title).ToList();
}

return results;
Expand Down

0 comments on commit 4dab056

Please sign in to comment.