Fuzzy 0.5.0 process extract - CyrilB1531/lodestar GitHub Wiki
Lodestar.Fuzzy 0.5.0. This page is frozen at that release. Read the current documentation for what
mainsays now. A link to a decision or a migration page followsmain, and leaves the archive.
The best candidates, ranked.
public static IReadOnlyList<ExtractResult> Extract(string query, IEnumerable<string> choices, Func<string, string, double> scorer = null, int? limit = 5, double scoreCutoff = 0)Parameters — query is what to match. choices are the candidates. scorer is the scoring
function, Fuzz.WRatio when omitted. limit caps how many come back, 5 by
default and null for all of them. scoreCutoff drops anything scoring below it.
Returns — IReadOnlyList<ExtractResult>, best first, at most limit long.
Exceptions — ArgumentNullException when query or choices is null.
ArgumentOutOfRangeException when limit is negative; 0 returns an empty list.
Example — the two best of four candidates.
using Lodestar.Fuzzy;
string[] choices = ["apple pie", "apple tart", "banana bread", "cherry pie"];
IReadOnlyList<ExtractResult> best = Process.Extract("apple pie", choices, limit: 2);
int returned = best.Count; // => 2
string first = best[0].Choice; // => apple pie
int where = best[0].Index; // => 0Remarks — the default limit of 5 is rapidfuzz's, and it is a cap rather than a
guarantee: fewer come back when fewer clear the cutoff, and passing null returns every
candidate ranked, which on a large list is the expensive call.
scoreCutoff filters after scoring: every candidate is scored in full and the ones below the
cutoff are dropped, so it makes the result shorter and the heap smaller, not the scoring faster.
For rapidfuzz's scores on text outside the BMP, pass a code-point scorer, such as
(q, c) => Fuzz.WRatio(q, c, TextElement.CodePoint).
Each result carries its Index, which is how a match is traced back to the record it came from
rather than to the string.
Applies to — net10.0, netstandard2.0.
See also — Process.ExtractOne,
ExtractResult.