#82352 Implement sorting for search results#86563
#82352 Implement sorting for search results#86563roblourens merged 4 commits intomicrosoft:masterfrom jzyrobert:83252-search-sort
Conversation
|
Things to look at:
|
|
So it turns out that:
I have:
|
|
@jzyrobert The URI class converts |
|
Please keep using resource.getBaseName. It's designed to work for any schema, also for the file scheme. |
|
I see, thanks guys. |
roblourens
left a comment
There was a problem hiding this comment.
This looks awesome, thanks for the PR! I am actually not clear what getBaseName refers to but it sounds like you are on top of it
There was a problem hiding this comment.
You don't need to explictly return a promise in an async function, this line can be removed.
There was a problem hiding this comment.
Again here, you don't need to explicity return a promise in async functions.
There was a problem hiding this comment.
Should this be ||? Otherwise const matches = this.viewModel.searchResult.matches(); below will throw when the search order is modified but the viewModel is undefined
There was a problem hiding this comment.
This will check each file syncronously. You might consider using Promise.all to run these in parallel.
There was a problem hiding this comment.
Thanks, I was going to look into that
There was a problem hiding this comment.
These two can be unified into a single const enum. Following that, the == 'modified'-style checks elsewhere should be changed to == SearchSortOrder.Modified. Also we aren't super consistent about CAPS_CASE vs. PascalCase for const enums in elsewhere in vscode, but I think here PascalCase feels better. Up to you.
JacksonKearl
left a comment
There was a problem hiding this comment.
Thanks for working on this! I have left some comments throughout.
|
@roblourens @JacksonKearl I've made the requested changes. I went with the object + type initially instead of the enum because the explorer sort uses that, should that be refactored into an enum too? I also did not see an easy way to retrieve the elements out of the tree for re-ordering, is it an acceptable performance hit to resolve the search results every time when a file match count is updated? |
|
@jzyrobert We probably don't want to touch Explorer files in this, as it would add another reviewer and complexity just for a minor refactoring.
What do you mean by "resolve"? The search isn't run again, correct? Are you referring to this // If updated counts affect our search order, re-sort the view.
if (this.searchConfig.sortOrder === SearchSortOrder.CountAscending ||
this.searchConfig.sortOrder === SearchSortOrder.CountDescending) {
this.tree.setChildren(null, this.createResultIterator(collapseResults));
}? That shouldn't be a particularly expensive operation. I played around with it and even with the max of 10000 results I didn't notice a problem. If it comes up as an issue we can look at it then. I should have been more clear about the export const enum SearchSortOrder {
Default = 'default',
FileNames = 'fileNames',
Type = 'type',
Modified = 'modified',
CountDescending = 'countDescending',
CountAscending = 'countAscending'
} |
JacksonKearl
left a comment
There was a problem hiding this comment.
LGTM conditional on the
export const enum SearchSortOrder {
Default = 'default',
FileNames = 'fileNames',
Type = 'type',
Modified = 'modified',
CountDescending = 'countDescending',
CountAscending = 'countAscending'
}
roblourens
left a comment
There was a problem hiding this comment.
is it an acceptable performance hit to resolve the search results every time when a file match count is updated?
Or if you are referring to resolving file stats, then I think it should only be done once per search. If I am reading the code correctly, it looks like that is the case now right?
There was a problem hiding this comment.
Looks like it's updating all file stats, when just elements would be preferable
I could make it another PR if this is refactoring that should be done.
Sounds good. I tried it as well with the maximum results and it was very fast, but I have a (and you probably do) quite powerful machine, and I was thinking of users with older CPUs.
I see the values are used for the actual option values, should have checked for that. |
|
I'm commenting on the one that does and the function is already taking |
Oh I see, sorry about that. Yes you're right, I forgot to correct the mapping. |

This PR fixes #82352
Added a setting to allow sorting of search results.

Demo:
The following are the possible options:
compareFileNamesto correct the ordering of numeral files (e.g. file1 is now in front of file10)The
modifiedsorting is implemented as follows:refreshTreeis called, we ensure that if thesortOrder === modifiedallfileMatchitems have a existingIFileStatWithMetaData, or it will retrieve it.onFilesChangedis called, modified files are retrieved and have theirfileStatupdated.sortOrderis set away frommodified, removefileStatinformation so it is re-calculated when it is set tomodified again.I think this is fair on performance, always tracking all meta-data would be performance intensive.
I'm not sure how I would add tests for the modified/count settings as you would have to set several properties.