Skip to content

Commit 61803e2

Browse files
committed
Ranking fallbacks again
1 parent 5234bd6 commit 61803e2

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/MainListPage.cs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public override IListItem[] GetItems()
179179
// and eventually ordered based on user preference
180180
.Concat(_fallbackItems is not null ?
181181
_fallbackItems
182-
.Where(w => !string.IsNullOrEmpty(w.Item.Title))
182+
.Where(w => !string.IsNullOrWhiteSpace(w.Item.Title))
183183
.OrderByDescending(o => o.Score) : [])
184184
.Select(s => s.Item)
185185
.ToArray();
@@ -251,7 +251,7 @@ public override void UpdateSearchText(string oldSearch, string newSearch)
251251

252252
// prefilter fallbacks
253253
var specialFallbacks = new List<TopLevelViewModel>();
254-
var commonFallbacks = new List<TopLevelViewModel>();
254+
var commonFallbacks = new List<Scored<IListItem>>();
255255

256256
lock (_settings)
257257
{
@@ -269,15 +269,15 @@ public override void UpdateSearchText(string oldSearch, string newSearch)
269269
}
270270
else
271271
{
272-
commonFallbacks.Add(s);
272+
commonFallbacks.Add(new Scored<IListItem>() { Item = s, Score = fallbackSettings.WeightBoost });
273273
}
274274
}
275275
}
276276

277277
// start update of fallbacks; update special fallbacks separately,
278278
// so they can finish faster
279279
UpdateFallbacks(SearchText, specialFallbacks, token);
280-
UpdateFallbacks(SearchText, commonFallbacks, token);
280+
UpdateFallbacks(SearchText, commonFallbacks.Select(s => s.Item).Cast<TopLevelViewModel>().ToList(), token);
281281

282282
if (token.IsCancellationRequested)
283283
{
@@ -312,7 +312,7 @@ public override void UpdateSearchText(string oldSearch, string newSearch)
312312
}
313313

314314
var newFilteredItems = Enumerable.Empty<IListItem>();
315-
var newFallbacks = Enumerable.Empty<IListItem>();
315+
var newFallbacks = Enumerable.Empty<Scored<IListItem>>();
316316
var newApps = Enumerable.Empty<IListItem>();
317317

318318
if (_filteredItems is not null)
@@ -337,7 +337,7 @@ public override void UpdateSearchText(string oldSearch, string newSearch)
337337

338338
if (_fallbackItems is not null)
339339
{
340-
newFallbacks = _fallbackItems.Select(s => s.Item);
340+
newFallbacks = _fallbackItems;
341341
}
342342

343343
if (token.IsCancellationRequested)
@@ -388,7 +388,7 @@ public override void UpdateSearchText(string oldSearch, string newSearch)
388388
}
389389

390390
var history = _serviceProvider.GetService<AppStateModel>()!.RecentCommands!;
391-
Func<string, IListItem, int> scoreTopLevelItem = (a, b) => { return ScoreTopLevelItem(a, b, history, null); };
391+
Func<string, IListItem, int> scoreTopLevelItem = (a, b) => { return ScoreTopLevelItem(a, b, history); };
392392

393393
// Produce a list of everything that matches the current filter.
394394
_filteredItems = [.. ListHelpers.FilterListWithScores<IListItem>(newFilteredItems ?? [], SearchText, scoreTopLevelItem)];
@@ -405,8 +405,7 @@ public override void UpdateSearchText(string oldSearch, string newSearch)
405405
return;
406406
}
407407

408-
Func<string, IListItem, int> scoreFallbackItem = (a, b) => { return ScoreTopLevelItem(a, b, history, null); };
409-
_fallbackItems = ListHelpers.FilterListWithScores<IListItem>(newFallbacks ?? [], SearchText, scoreFallbackItem);
408+
_fallbackItems = newFallbacks;
410409

411410
if (token.IsCancellationRequested)
412411
{
@@ -483,7 +482,7 @@ private bool ActuallyLoading()
483482
// Almost verbatim ListHelpers.ScoreListItem, but also accounting for the
484483
// fact that we want fallback handlers down-weighted, so that they don't
485484
// _always_ show up first.
486-
internal static int ScoreTopLevelItem(string query, IListItem topLevelOrAppItem, IRecentCommandsManager history, int? weightBoost)
485+
internal static int ScoreTopLevelItem(string query, IListItem topLevelOrAppItem, IRecentCommandsManager history)
487486
{
488487
var title = topLevelOrAppItem.Title;
489488
if (string.IsNullOrWhiteSpace(title))
@@ -566,12 +565,6 @@ internal static int ScoreTopLevelItem(string query, IListItem topLevelOrAppItem,
566565
finalScore += recentWeightBoost;
567566
}
568567

569-
// If we're a fallback, we don't care about the rest. Use the weight boost.
570-
if (isFallback && weightBoost is not null)
571-
{
572-
finalScore = weightBoost.Value;
573-
}
574-
575568
return (int)finalScore;
576569
}
577570

src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/FallbackOpenFileItem.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@
22
// The Microsoft Corporation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using System;
6-
using System.Globalization;
7-
using System.IO;
8-
using System.Text;
95
using Microsoft.CmdPal.Ext.Indexer.Data;
106
using Microsoft.CmdPal.Ext.Indexer.Properties;
11-
using Microsoft.CommandPalette.Extensions.Toolkit;
12-
using Windows.Storage.Streams;
137

148
namespace Microsoft.CmdPal.Ext.Indexer;
159

@@ -120,9 +114,9 @@ public override void UpdateQuery(string query)
120114
// Exit 4: We found more than one result. Make our command take
121115
// us to the file search page, prepopulated with this search.
122116
var indexerPage = new IndexerPage(query, _searchEngine, _queryCookie, results);
123-
Title = string.Format(CultureInfo.CurrentCulture, fallbackItemSearchPageTitleCompositeFormat, query);
117+
Title = Resources.Indexer_Title;
124118
Icon = Icons.FileExplorerIcon;
125-
Subtitle = Resources.Indexer_Subtitle;
119+
Subtitle = string.Format(CultureInfo.CurrentCulture, fallbackItemSearchPageTitleCompositeFormat, query);
126120
Command = indexerPage;
127121

128122
return;

0 commit comments

Comments
 (0)