@getpaseo/protocol 0.5.2 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -15,6 +15,14 @@ export interface MatchScore {
|
|
|
15
15
|
export interface MatchOptions {
|
|
16
16
|
/** Omit or pass null to match exactly. `fuzzyPolicyForToken` picks a policy. */
|
|
17
17
|
fuzzy?: FuzzyPolicy | null;
|
|
18
|
+
/**
|
|
19
|
+
* Match characters that appear in order but not adjacently, so `pasbab` finds
|
|
20
|
+
* `paseo-babysit`. Defaults to on. Turn it off where a near miss has to read as
|
|
21
|
+
* no match at all: it widens far enough that most typos hit something, and a
|
|
22
|
+
* list that preselects its first row would then act on that row when the user
|
|
23
|
+
* presses Enter expecting nothing to happen.
|
|
24
|
+
*/
|
|
25
|
+
subsequence?: boolean;
|
|
18
26
|
}
|
|
19
27
|
/**
|
|
20
28
|
* How much a typo in one query token is forgiven. Short tokens get
|
|
@@ -52,6 +60,12 @@ export interface TextFieldsOptions {
|
|
|
52
60
|
* query mixes long words that can absorb an edit with short ones that cannot.
|
|
53
61
|
*/
|
|
54
62
|
typoTolerant?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* See `MatchOptions.subsequence`. Applied per token, so turning it off means
|
|
65
|
+
* every token has to appear as a run of adjacent characters in some field —
|
|
66
|
+
* `lab des` still matches "Label as Design", `labdes` no longer does.
|
|
67
|
+
*/
|
|
68
|
+
subsequence?: boolean;
|
|
55
69
|
}
|
|
56
70
|
export declare function scoreTextFields(query: string, fields: string[], options?: TextFieldsOptions): MatchScore | null;
|
|
57
71
|
//# sourceMappingURL=text-match.d.ts.map
|
|
@@ -168,7 +168,8 @@ export function scoreMatch(query, text, options = {}) {
|
|
|
168
168
|
const t = text.toLowerCase();
|
|
169
169
|
if (t === q)
|
|
170
170
|
return { tier: TIER_EXACT, offset: 0 };
|
|
171
|
-
const
|
|
171
|
+
const substring = scoreSubstringMatch(q, t);
|
|
172
|
+
const exact = substring ?? (options.subsequence === false ? null : scoreSubsequenceMatch(q, t));
|
|
172
173
|
if (exact)
|
|
173
174
|
return exact;
|
|
174
175
|
const fuzzy = options.fuzzy;
|
|
@@ -274,7 +275,7 @@ export function scoreTextFields(query, fields, options = {}) {
|
|
|
274
275
|
const fuzzy = options.typoTolerant ? fuzzyPolicyForToken(token) : null;
|
|
275
276
|
let best = null;
|
|
276
277
|
for (const field of fields) {
|
|
277
|
-
const score = scoreMatch(token, field, { fuzzy });
|
|
278
|
+
const score = scoreMatch(token, field, { fuzzy, subsequence: options.subsequence });
|
|
278
279
|
if (score && (!best || compareMatchScores(score, best) < 0)) {
|
|
279
280
|
best = score;
|
|
280
281
|
}
|