Improve recent projects search result ordering (#38795)

Previously, search results were sorted solely by candidate_id
(preserving original order from the database), which could result in
less relevant matches appearing before better ones.

This change sorts results primarily by fuzzy match score (descending),
with candidate_id as a tiebreaker for equal scores. This ensures that
better matches appear first while preserving recency order among items
with identical scores.

Example improvement:
- Searching for 'pica' will now rank 'picabo' higher than scattered
matches like 'project-api, project-chat'
- Consecutive character matches are prioritized over scattered matches
across multiple path segments

Release Notes:
- Improved project search relevance by ranking results using match score
instead of insertion order.
This commit is contained in:
tsjason
2025-09-29 17:15:47 +02:00
committed by GitHub
parent 163219af35
commit 1e70a1a4ce
@@ -328,7 +328,12 @@ impl PickerDelegate for RecentProjectsDelegate {
&Default::default(),
cx.background_executor().clone(),
));
self.matches.sort_unstable_by_key(|m| m.candidate_id);
self.matches.sort_unstable_by(|a, b| {
b.score
.partial_cmp(&a.score) // Descending score
.unwrap_or(std::cmp::Ordering::Equal)
.then_with(|| a.candidate_id.cmp(&b.candidate_id)) // Ascending candidate_id for ties
});
if self.reset_selected_match_index {
self.selected_match_index = self