Skip to content

Commit

Permalink
Merge pull request storybookjs#6244 from mohsinulhaq/next
Browse files Browse the repository at this point in the history
use Fuse.js package instead of fuzzy-search for customizable search threshold
  • Loading branch information
ndelangen authored Mar 25, 2019
2 parents 8c4ee76 + 6df76ef commit 301d578
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/api/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = '5.1.0-alpha.10';
export const version = '5.1.0-alpha.13';
2 changes: 1 addition & 1 deletion lib/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@storybook/theming": "5.1.0-alpha.13",
"core-js": "^2.6.5",
"fast-deep-equal": "^2.0.1",
"fuzzy-search": "^3.0.1",
"fuse.js": "^3.4.4",
"global": "^4.3.2",
"lodash.debounce": "^4.0.8",
"lodash.isequal": "^4.5.0",
Expand Down
13 changes: 9 additions & 4 deletions lib/ui/src/components/sidebar/treeview/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import memoize from 'memoizerific';
import FuzzySearch from 'fuzzy-search';
import Fuse from 'fuse.js';

const FUZZY_SEARCH_THRESHOLD = 0.4;

export const prevent = e => e.preventDefault();

Expand Down Expand Up @@ -163,9 +165,12 @@ export const getNext = ({ id, dataset, expanded }) => {
return next.result;
};

const toHayStack = memoize(2)(
const fuse = memoize(5)(
dataset =>
new FuzzySearch(toList(dataset), ['kind', 'name', 'parameters.fileName', 'parameters.notes'])
new Fuse(toList(dataset), {
threshold: FUZZY_SEARCH_THRESHOLD,
keys: ['kind', 'name', 'parameters.fileName', 'parameters.notes'],
})
);

const exactMatch = memoize(1)(filter => i =>
Expand All @@ -179,7 +184,7 @@ export const toId = (base, addition) => (base === '' ? `${addition}` : `${base}-
export const toFiltered = (dataset, filter) => {
let found;
if (filter.length && filter.length > 2) {
found = toHayStack(dataset).search(filter);
found = fuse(dataset).search(filter);
} else {
found = toList(dataset).filter(exactMatch(filter));
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12144,10 +12144,10 @@ functional-red-black-tree@^1.0.1:
resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327"
integrity sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=

fuzzy-search@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/fuzzy-search/-/fuzzy-search-3.0.1.tgz#14a4964508a9607d6e9a88818e7ff634108260b6"
integrity sha512-rjUvzdsMlOyarm0oD5k6zVQwgvt4Tb5Xe3YdIGU+Vogw54+ueAGPUTMU2B9jfPQEie5cD11i/S9J9d+MNBSQ3Q==
fuse.js@^3.4.4:
version "3.4.4"
resolved "https://registry.yarnpkg.com/fuse.js/-/fuse.js-3.4.4.tgz#f98f55fcb3b595cf6a3e629c5ffaf10982103e95"
integrity sha512-pyLQo/1oR5Ywf+a/tY8z4JygnIglmRxVUOiyFAbd11o9keUDpUJSMGRWJngcnkURj30kDHPmhoKY8ChJiz3EpQ==

g-status@^2.0.2:
version "2.0.2"
Expand Down

0 comments on commit 301d578

Please sign in to comment.