diff options
author | Minteck <contact@minteck.org> | 2022-01-06 22:20:22 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-01-06 22:20:22 +0100 |
commit | e41f05b77fe8d757d8acd6a638d7f2b28155e4e3 (patch) | |
tree | e2fe749ed5e05760ab0877d6b7b9c7bbdca1dcf3 /result.js | |
download | ponyfind-e41f05b77fe8d757d8acd6a638d7f2b28155e4e3.tar.gz ponyfind-e41f05b77fe8d757d8acd6a638d7f2b28155e4e3.tar.bz2 ponyfind-e41f05b77fe8d757d8acd6a638d7f2b28155e4e3.zip |
Initial commit
Diffstat (limited to 'result.js')
-rw-r--r-- | result.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/result.js b/result.js new file mode 100644 index 0000000..faef56c --- /dev/null +++ b/result.js @@ -0,0 +1,24 @@ +const db = require('./data/search.json').associations; +const Fuse = require('fuse.js'); + +module.exports = (query, id) => { + const fuse = new Fuse(db, { + keys: [ 'title', 'endpoint' ] + }) + + let results = []; + for (let item of fuse.search(query)) { + results.push(item.item.endpoint); + } + + if (fuse.search(query).length > 0) { + exact = fuse.search(query)[0].endpoint; + } else { + exact = null; + } + + return { + results, + exact + }; +}
\ No newline at end of file |