api: implement notes fuzzy search

This commit is contained in:
thecodrr
2019-11-29 21:28:31 +05:00
parent 35e2850861
commit 1c5909127b
3 changed files with 29 additions and 0 deletions

View File

@@ -1,4 +1,6 @@
import Storage from "../helpers/storage";
import fuzzysearch from "fuzzysearch";
import ff from "fast-filter";
const KEYS = {
notes: "notes"
@@ -76,6 +78,19 @@ class Database {
}
}
/**
* Searches all notes in the database with the given query
* @param {string} query the search query
*/
searchNotes(query) {
//TODO add logic to update the cache if necessary
return ff(
this.notes,
v => fuzzysearch(query, v.title) || fuzzysearch(query, v.content.text),
this
);
}
//Notebooks
getNotebooks() {}
getNotebook() {}

View File

@@ -15,5 +15,9 @@
},
"scripts": {
"test": "jest --coverage"
},
"dependencies": {
"fast-filter": "^1.0.4",
"fuzzysearch": "^1.0.3"
}
}

View File

@@ -2161,6 +2161,11 @@ fast-deep-equal@^2.0.1:
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49"
integrity sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=
fast-filter@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/fast-filter/-/fast-filter-1.0.4.tgz#db462c3e8e6d3c66305752cdb8831a81c8b275db"
integrity sha1-20YsPo5tPGYwV1LNuIMagciydds=
fast-json-stable-stringify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2"
@@ -2246,6 +2251,11 @@ function-bind@^1.1.1:
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d"
integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==
fuzzysearch@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/fuzzysearch/-/fuzzysearch-1.0.3.tgz#dffc80f6d6b04223f2226aa79dd194231096d008"
integrity sha1-3/yA9tawQiPyImqnndGUIxCW0Ag=
gauge@~2.7.3:
version "2.7.4"
resolved "https://registry.yarnpkg.com/gauge/-/gauge-2.7.4.tgz#2c03405c7538c39d7eb37b317022e325fb018bf7"