@@ -339,7 +339,13 @@ public PSTypeName[] ParameterType
339339 [ Parameter ( ParameterSetName = "AllCommandSet" ) ]
340340 public SwitchParameter UseFuzzyMatching { get ; set ; }
341341
342- private readonly List < CommandScore > _commandScores = new List < CommandScore > ( ) ;
342+ /// <summary>
343+ /// Gets or sets the minimum fuzzy matching distance.
344+ /// </summary>
345+ [ Parameter ( ParameterSetName = "AllCommandSet" ) ]
346+ public uint FuzzyMinimumDistance { get ; set ; } = 5 ;
347+
348+ private List < CommandScore > _commandScores = new List < CommandScore > ( ) ;
343349
344350 /// <summary>
345351 /// Gets or sets the parameter that determines if return cmdlets based on abbreviation expansion.
@@ -501,13 +507,16 @@ private void OutputResultsHelper(IEnumerable<CommandInfo> results)
501507
502508 if ( UseFuzzyMatching )
503509 {
504- results = _commandScores . OrderBy ( static x => x . Score ) . Select ( static x => x . Command ) . ToList ( ) ;
510+ _commandScores = _commandScores
511+ . Where ( x => x . Score <= FuzzyMinimumDistance )
512+ . OrderBy ( static x => x . Score )
513+ . ToList ( ) ;
514+ results = _commandScores . Select ( static x => x . Command ) ;
505515 }
506516
507517 int count = 0 ;
508518 foreach ( CommandInfo result in results )
509519 {
510- count += 1 ;
511520 // Only write the command if it is visible to the requestor
512521 if ( SessionState . IsVisible ( origin , result ) )
513522 {
@@ -532,11 +541,21 @@ private void OutputResultsHelper(IEnumerable<CommandInfo> results)
532541 }
533542 else
534543 {
535- // Write output as normal command info object.
536- WriteObject ( result ) ;
544+ if ( UseFuzzyMatching )
545+ {
546+ PSObject obj = new PSObject ( result ) ;
547+ obj . Properties . Add ( new PSNoteProperty ( "Score" , _commandScores [ count ] . Score ) ) ;
548+ WriteObject ( obj ) ;
549+ }
550+ else
551+ {
552+ WriteObject ( result ) ;
553+ }
537554 }
538555 }
539556 }
557+
558+ count += 1 ;
540559 }
541560
542561#if LEGACYTELEMETRY
0 commit comments