Skip to content

Commit d33b735

Browse files
kriskclaude
andcommitted
feat: getFn null return, escaped pipe in extended search, empty query returns all
Three small features: - Allow key-level getFn to return null/undefined (closes #800) - Support \| to search literal pipe in extended search (closes #765) - Empty string query returns all docs with refIndex (closes #728) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5a01f29 commit d33b735

18 files changed

Lines changed: 182 additions & 18 deletions

dist/fuse.basic.cjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,20 @@ var Fuse = /*#__PURE__*/function () {
12941294
shouldSort = _this$options.shouldSort,
12951295
sortFn = _this$options.sortFn,
12961296
ignoreFieldNorm = _this$options.ignoreFieldNorm;
1297+
1298+
// Empty string query returns all docs (useful for search UIs)
1299+
if (isString(query) && !query.trim()) {
1300+
var docs = this._docs.map(function (item, idx) {
1301+
return {
1302+
item: item,
1303+
refIndex: idx
1304+
};
1305+
});
1306+
if (isNumber(limit) && limit > -1) {
1307+
docs = docs.slice(0, limit);
1308+
}
1309+
return docs;
1310+
}
12971311
var useHeap = isNumber(limit) && limit > 0 && isString(query);
12981312
var results;
12991313
if (useHeap) {

dist/fuse.basic.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,20 @@
12981298
shouldSort = _this$options.shouldSort,
12991299
sortFn = _this$options.sortFn,
13001300
ignoreFieldNorm = _this$options.ignoreFieldNorm;
1301+
1302+
// Empty string query returns all docs (useful for search UIs)
1303+
if (isString(query) && !query.trim()) {
1304+
var docs = this._docs.map(function (item, idx) {
1305+
return {
1306+
item: item,
1307+
refIndex: idx
1308+
};
1309+
});
1310+
if (isNumber(limit) && limit > -1) {
1311+
docs = docs.slice(0, limit);
1312+
}
1313+
return docs;
1314+
}
13011315
var useHeap = isNumber(limit) && limit > 0 && isString(query);
13021316
var results;
13031317
if (useHeap) {

dist/fuse.basic.min.cjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/fuse.basic.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/fuse.basic.min.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/fuse.basic.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,18 @@ class Fuse {
10641064
sortFn,
10651065
ignoreFieldNorm
10661066
} = this.options;
1067+
1068+
// Empty string query returns all docs (useful for search UIs)
1069+
if (isString(query) && !query.trim()) {
1070+
let docs = this._docs.map((item, idx) => ({
1071+
item,
1072+
refIndex: idx
1073+
}));
1074+
if (isNumber(limit) && limit > -1) {
1075+
docs = docs.slice(0, limit);
1076+
}
1077+
return docs;
1078+
}
10671079
const useHeap = isNumber(limit) && limit > 0 && isString(query);
10681080
let results;
10691081
if (useHeap) {

dist/fuse.cjs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,7 @@ var IncludeMatch = /*#__PURE__*/function (_BaseMatch) {
13741374
// ❗Order is important. DO NOT CHANGE.
13751375
var searchers = [ExactMatch, IncludeMatch, PrefixExactMatch, InversePrefixExactMatch, InverseSuffixExactMatch, SuffixExactMatch, InverseExactMatch, FuzzyMatch];
13761376
var searchersLen = searchers.length;
1377+
var ESCAPED_PIPE = "\0"; // placeholder for escaped \|
13771378
var OR_TOKEN = '|';
13781379

13791380
// Tokenize a query string into individual search terms.
@@ -1428,8 +1429,12 @@ function tokenize(pattern) {
14281429
// "^core go$ | rb$ | py$ xy$" => [["^core", "go$"], ["rb$"], ["py$", "xy$"]]
14291430
function parseQuery(pattern) {
14301431
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1431-
return pattern.split(OR_TOKEN).map(function (item) {
1432-
var query = tokenize(item.trim()).filter(function (item) {
1432+
// Replace escaped \| with placeholder before splitting on |
1433+
var escaped = pattern.replace(/\\\|/g, ESCAPED_PIPE);
1434+
return escaped.split(OR_TOKEN).map(function (item) {
1435+
// Restore escaped pipes in each OR group
1436+
var restored = item.replace(/\u0000/g, '|');
1437+
var query = tokenize(restored.trim()).filter(function (item) {
14331438
return item && !!item.trim();
14341439
});
14351440
var results = [];
@@ -1919,6 +1924,20 @@ var Fuse = /*#__PURE__*/function () {
19191924
shouldSort = _this$options.shouldSort,
19201925
sortFn = _this$options.sortFn,
19211926
ignoreFieldNorm = _this$options.ignoreFieldNorm;
1927+
1928+
// Empty string query returns all docs (useful for search UIs)
1929+
if (isString(query) && !query.trim()) {
1930+
var docs = this._docs.map(function (item, idx) {
1931+
return {
1932+
item: item,
1933+
refIndex: idx
1934+
};
1935+
});
1936+
if (isNumber(limit) && limit > -1) {
1937+
docs = docs.slice(0, limit);
1938+
}
1939+
return docs;
1940+
}
19221941
var useHeap = isNumber(limit) && limit > 0 && isString(query);
19231942
var results;
19241943
if (useHeap) {

dist/fuse.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ interface Searcher {
1212
interface FuseOptionKeyObject<T> {
1313
name: string | string[];
1414
weight?: number;
15-
getFn?: (obj: T) => ReadonlyArray<string> | string;
15+
getFn?: (obj: T) => ReadonlyArray<string> | string | null | undefined;
1616
}
1717
type FuseOptionKey<T> = FuseOptionKeyObject<T> | string | string[];
1818
interface KeyObject {
1919
path: string[];
2020
id: string;
2121
weight: number;
2222
src: string | string[];
23-
getFn?: ((obj: any) => ReadonlyArray<string> | string) | null;
23+
getFn?: ((obj: any) => ReadonlyArray<string> | string | null | undefined) | null;
2424
}
2525
type FuseGetFunction<T> = (obj: T, path: string | string[]) => ReadonlyArray<string> | string;
2626
type GetFunction = (obj: any, path: string | string[]) => any;

dist/fuse.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,7 @@
13781378
// ❗Order is important. DO NOT CHANGE.
13791379
var searchers = [ExactMatch, IncludeMatch, PrefixExactMatch, InversePrefixExactMatch, InverseSuffixExactMatch, SuffixExactMatch, InverseExactMatch, FuzzyMatch];
13801380
var searchersLen = searchers.length;
1381+
var ESCAPED_PIPE = "\0"; // placeholder for escaped \|
13811382
var OR_TOKEN = '|';
13821383

13831384
// Tokenize a query string into individual search terms.
@@ -1432,8 +1433,12 @@
14321433
// "^core go$ | rb$ | py$ xy$" => [["^core", "go$"], ["rb$"], ["py$", "xy$"]]
14331434
function parseQuery(pattern) {
14341435
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1435-
return pattern.split(OR_TOKEN).map(function (item) {
1436-
var query = tokenize(item.trim()).filter(function (item) {
1436+
// Replace escaped \| with placeholder before splitting on |
1437+
var escaped = pattern.replace(/\\\|/g, ESCAPED_PIPE);
1438+
return escaped.split(OR_TOKEN).map(function (item) {
1439+
// Restore escaped pipes in each OR group
1440+
var restored = item.replace(/\u0000/g, '|');
1441+
var query = tokenize(restored.trim()).filter(function (item) {
14371442
return item && !!item.trim();
14381443
});
14391444
var results = [];
@@ -1923,6 +1928,20 @@
19231928
shouldSort = _this$options.shouldSort,
19241929
sortFn = _this$options.sortFn,
19251930
ignoreFieldNorm = _this$options.ignoreFieldNorm;
1931+
1932+
// Empty string query returns all docs (useful for search UIs)
1933+
if (isString(query) && !query.trim()) {
1934+
var docs = this._docs.map(function (item, idx) {
1935+
return {
1936+
item: item,
1937+
refIndex: idx
1938+
};
1939+
});
1940+
if (isNumber(limit) && limit > -1) {
1941+
docs = docs.slice(0, limit);
1942+
}
1943+
return docs;
1944+
}
19261945
var useHeap = isNumber(limit) && limit > 0 && isString(query);
19271946
var results;
19281947
if (useHeap) {

dist/fuse.min.cjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)