From 418e48e13cfd874de2677cde76227164cd00a005 Mon Sep 17 00:00:00 2001 From: alyx Date: Fri, 4 Feb 2022 22:21:43 +0000 Subject: made the sorting of search results be based on closeness as opposed to alphabetical --- grapher/script.js | 1 - script.js | 15 ++++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/grapher/script.js b/grapher/script.js index 78b7efd..50d1055 100644 --- a/grapher/script.js +++ b/grapher/script.js @@ -194,7 +194,6 @@ window.onload = async function() { if (e.target.parentElement.matches('.input') && (newCon.i.nextElementSibling.innerText == newCon.o.nextElementSibling.innerText)) connections.push(newCon); break; - break; case 'drag': if ((performance.now() - start) < 150 && !targ.children[0].matches('#selected')) { switchID(targ.children[0], 'selected') diff --git a/script.js b/script.js index 280c484..5a9c0ff 100644 --- a/script.js +++ b/script.js @@ -10,14 +10,16 @@ const fusenameopts = { minMatchCharLength: 1, ignoreLocation: true, threshold: 0, - keys: ["ReadonlyName"] + keys: ["ReadonlyName"], + includeScore: true }; const fusedescopts = { isCaseSensitive: false, minMatchCharLength: 1, ignoreLocation: true, threshold: 0, - keys: ["Description"] + keys: ["Description"], + includeScore: true }; function genExplanation(name) { @@ -143,9 +145,12 @@ window.addEventListener("load", async (e) => { fuse.setCollection(content2.nodes); }); - var content = endOfPath ? fuseinuse.map(fuse => fuse.search(endOfPath).map(e => e.item)) : content2.nodes; - content = Array.from(new Set(content.flat())); - content.sort((a, b) => (a.ReadonlyName.toLowerCase() > b.ReadonlyName.toLowerCase()) ? 1 : -1); + var content = endOfPath ? (() => { + let m = fuseinuse.map(fuse => fuse.search(endOfPath)).flat() + m.sort((a,b) => a.score - b.score); + m = Array.from(new Set(m.map(e => e.item))); + return m; + })() : content2.nodes; //console.log(content2.nodes) content = content.map(el => { -- cgit v1.2.3-54-g00ecf