Skip to content

Commit

Permalink
support customized keys in search method
Browse files Browse the repository at this point in the history
  • Loading branch information
springuper committed Nov 25, 2022
1 parent 04295e5 commit 81d11b7
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 63 deletions.
14 changes: 8 additions & 6 deletions dist/fuse.basic.common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Fuse.js v6.6.2 - Lightweight fuzzy-search (http://fusejs.io)
* Fuse.js v6.6.2-beta.1 - Lightweight fuzzy-search (http://fusejs.io)
*
* Copyright (c) 2022 Kiro Risk (http://kiro.me)
* All Rights Reserved. Apache Software License 2.0
Expand Down Expand Up @@ -193,7 +193,6 @@ var KeyStore = /*#__PURE__*/function () {
var totalWeight = 0;
keys.forEach(function (key) {
var obj = createKey(key);
totalWeight += obj.weight;

_this._keys.push(obj);

Expand Down Expand Up @@ -1278,15 +1277,17 @@ var Fuse$1 = /*#__PURE__*/function () {
value: function search(query) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref$limit = _ref.limit,
limit = _ref$limit === void 0 ? -1 : _ref$limit;
limit = _ref$limit === void 0 ? -1 : _ref$limit,
_ref$keys = _ref.keys,
keys = _ref$keys === void 0 ? [] : _ref$keys;

var _this$options = this.options,
includeMatches = _this$options.includeMatches,
includeScore = _this$options.includeScore,
shouldSort = _this$options.shouldSort,
sortFn = _this$options.sortFn,
ignoreFieldNorm = _this$options.ignoreFieldNorm;
var results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query);
var results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query, keys) : this._searchLogical(query);
computeScore(results, {
ignoreFieldNorm: ignoreFieldNorm
});
Expand Down Expand Up @@ -1350,7 +1351,7 @@ var Fuse$1 = /*#__PURE__*/function () {
}
}, {
key: "_searchObjectList",
value: function _searchObjectList(query) {
value: function _searchObjectList(query, searchKeys) {
var _this2 = this;

var searcher = createSearcher(query, this.options);
Expand All @@ -1370,6 +1371,7 @@ var Fuse$1 = /*#__PURE__*/function () {
var matches = []; // Iterate over every key (i.e, path), and fetch the value at that key

keys.forEach(function (key, keyIndex) {
if (searchKeys.length > 0 && !searchKeys.includes(key.id)) return;
matches.push.apply(matches, _toConsumableArray(_this2._findMatches({
key: key,
value: item[keyIndex],
Expand Down Expand Up @@ -1453,7 +1455,7 @@ var Fuse$1 = /*#__PURE__*/function () {
return Fuse;
}();

Fuse$1.version = '6.6.2';
Fuse$1.version = '6.6.2-beta.1';
Fuse$1.createIndex = createIndex;
Fuse$1.parseIndex = parseIndex;
Fuse$1.config = Config;
Expand Down
13 changes: 6 additions & 7 deletions dist/fuse.basic.esm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Fuse.js v6.6.2 - Lightweight fuzzy-search (http://fusejs.io)
* Fuse.js v6.6.2-beta.1 - Lightweight fuzzy-search (http://fusejs.io)
*
* Copyright (c) 2022 Kiro Risk (http://kiro.me)
* All Rights Reserved. Apache Software License 2.0
Expand Down Expand Up @@ -101,8 +101,6 @@ class KeyStore {
keys.forEach((key) => {
let obj = createKey(key);

totalWeight += obj.weight;

this._keys.push(obj);
this._keyMap[obj.id] = obj;

Expand Down Expand Up @@ -1112,7 +1110,7 @@ class Fuse {
return this._myIndex
}

search(query, { limit = -1 } = {}) {
search(query, { limit = -1, keys = [] } = {}) {
const {
includeMatches,
includeScore,
Expand All @@ -1124,7 +1122,7 @@ class Fuse {
let results = isString(query)
? isString(this._docs[0])
? this._searchStringList(query)
: this._searchObjectList(query)
: this._searchObjectList(query, keys)
: this._searchLogical(query);

computeScore(results, { ignoreFieldNorm });
Expand Down Expand Up @@ -1174,7 +1172,7 @@ class Fuse {
}
}

_searchObjectList(query) {
_searchObjectList(query, searchKeys) {
const searcher = createSearcher(query, this.options);
const { keys, records } = this._myIndex;
const results = [];
Expand All @@ -1189,6 +1187,7 @@ class Fuse {

// Iterate over every key (i.e, path), and fetch the value at that key
keys.forEach((key, keyIndex) => {
if (searchKeys.length > 0 && !searchKeys.includes(key.id)) return
matches.push(
...this._findMatches({
key,
Expand Down Expand Up @@ -1249,7 +1248,7 @@ class Fuse {
}
}

Fuse.version = '6.6.2';
Fuse.version = '6.6.2-beta.1';
Fuse.createIndex = createIndex;
Fuse.parseIndex = parseIndex;
Fuse.config = Config;
Expand Down
4 changes: 2 additions & 2 deletions dist/fuse.basic.esm.min.js

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions dist/fuse.basic.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Fuse.js v6.6.2 - Lightweight fuzzy-search (http://fusejs.io)
* Fuse.js v6.6.2-beta.1 - Lightweight fuzzy-search (http://fusejs.io)
*
* Copyright (c) 2022 Kiro Risk (http://kiro.me)
* All Rights Reserved. Apache Software License 2.0
Expand Down Expand Up @@ -197,7 +197,6 @@
var totalWeight = 0;
keys.forEach(function (key) {
var obj = createKey(key);
totalWeight += obj.weight;

_this._keys.push(obj);

Expand Down Expand Up @@ -1282,15 +1281,17 @@
value: function search(query) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref$limit = _ref.limit,
limit = _ref$limit === void 0 ? -1 : _ref$limit;
limit = _ref$limit === void 0 ? -1 : _ref$limit,
_ref$keys = _ref.keys,
keys = _ref$keys === void 0 ? [] : _ref$keys;

var _this$options = this.options,
includeMatches = _this$options.includeMatches,
includeScore = _this$options.includeScore,
shouldSort = _this$options.shouldSort,
sortFn = _this$options.sortFn,
ignoreFieldNorm = _this$options.ignoreFieldNorm;
var results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query);
var results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query, keys) : this._searchLogical(query);
computeScore(results, {
ignoreFieldNorm: ignoreFieldNorm
});
Expand Down Expand Up @@ -1354,7 +1355,7 @@
}
}, {
key: "_searchObjectList",
value: function _searchObjectList(query) {
value: function _searchObjectList(query, searchKeys) {
var _this2 = this;

var searcher = createSearcher(query, this.options);
Expand All @@ -1374,6 +1375,7 @@
var matches = []; // Iterate over every key (i.e, path), and fetch the value at that key

keys.forEach(function (key, keyIndex) {
if (searchKeys.length > 0 && !searchKeys.includes(key.id)) return;
matches.push.apply(matches, _toConsumableArray(_this2._findMatches({
key: key,
value: item[keyIndex],
Expand Down Expand Up @@ -1457,7 +1459,7 @@
return Fuse;
}();

Fuse$1.version = '6.6.2';
Fuse$1.version = '6.6.2-beta.1';
Fuse$1.createIndex = createIndex;
Fuse$1.parseIndex = parseIndex;
Fuse$1.config = Config;
Expand Down
Loading

0 comments on commit 81d11b7

Please sign in to comment.