A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fix: full text search now works again
thecodrr459247b44027
diff --git a/packages/core/__tests__/notes.test.js b/packages/core/__tests__/notes.test.jsindex ba1104917..9640e6b1e 100644--- a/packages/core/__tests__/notes.test.js+++ b/packages/core/__tests__/notes.test.js@@ -56,7 +56,7 @@ test("get all notes", () =>test("note without a title should get title from content", () =>noteTest().then(async ({ db, id }) => {let note = db.notes.note(id);- expect(note.title).toBe("Hello This is");+ expect(note.title).toBe("Hello This is colorful");}));test("update note", () =>@@ -95,17 +95,6 @@ test("updating empty note should delete it", () =>expect(note).toBeUndefined();}));-test("note with text longer than 150 characters should have ... in the headline", () =>- noteTest({- content: {- type: "delta",- data: [{ insert: LONG_TEXT }, { insert: "\n" }],- },- }).then(({ db, id }) => {- let note = db.notes.note(id);- expect(note.headline.includes("...")).toBe(true);- }));-test("get favorite notes", () =>noteTest({favorite: true,diff --git a/packages/core/api/lookup.js b/packages/core/api/lookup.jsindex 5a4e509e9..9cf6264af 100644--- a/packages/core/api/lookup.js+++ b/packages/core/api/lookup.js@@ -1,4 +1,5 @@import fuzzysearch from "fuzzysearch";+import { getContentFromData } from "../content-types";var tfun = require("transfun/transfun.js").tfun;if (!tfun) {tfun = global.tfun;@@ -19,12 +20,14 @@ export default class Lookup {let index = 0,max = notes.length;notes.forEach(async (note) => {- const text =- note.locked || !note.content- ? ""- : await this._db.text.get(note.content.text);const title = note.title;- if (fzs(query, text + title)) results.push(note);+ if (!note.locked) {+ let content = await this._db.content.raw(note.contentId);+ content = getContentFromData(content.type, content.data);+ if (content.search(query) || fzs(query, title)) results.push(note);+ } else {+ if (fzs(query, title)) results.push(note);+ }if (++index >= max) return resolve(results);});});diff --git a/packages/core/content-types/delta.js b/packages/core/content-types/delta.jsindex 24e44767c..646c12ff8 100644--- a/packages/core/content-types/delta.js+++ b/packages/core/content-types/delta.js@@ -1,10 +1,10 @@import { QuillDeltaToHtmlConverter } from "quill-delta-to-html";import { deltaToMarkdown } from "quill-delta-to-markdown";+const splitter = /\W+/gm;class Delta {constructor(data) {this.data = data;- this._text = this.toTXT();}toHTML() {@@ -28,15 +28,39 @@ class Delta {}toTitle() {- return this._text.split(/\W+/).slice(0, 3).join(" ").trim();+ return getSubstringFromDelta(this.data, 30);}toHeadline() {- return this._text.split(" ").slice(0, 20).join(" ") + "...";+ return getSubstringFromDelta(this.data, 60);}isEmpty() {- return this._text.trim().length <= 0;+ return this.toTXT().trim().length <= 0;+ }++ /**+ * @returns {Boolean}+ */+ search(query) {+ const tokens = query.split(splitter);+ return this.data.some((item) => {+ if (item.insert && item.insert.indexOf) {+ return tokens.some((token) => item.insert.indexOf(token) > -1);+ }+ return false;+ });}}export default Delta;++function getSubstringFromDelta(data, limit) {+ let substr = "";+ for (var i = 0; i < data.length; ++i) {+ const item = data[i];+ if (item.insert && typeof item.insert === "string")+ substr += item.insert.trim() + " ";+ if (substr.length >= limit) return substr.substring(0, limit).trim();+ }+ return substr.trim();+}diff --git a/packages/core/models/note.js b/packages/core/models/note.jsindex b1f25b2ff..bec7a1d62 100644--- a/packages/core/models/note.js+++ b/packages/core/models/note.js@@ -69,7 +69,7 @@ export default class Note {templateData.content = content.toHTML();return HTMLBuilder.buildHTML(templateData);case "txt":- templateData.content = content._text;+ templateData.content = content.toTXT();return TextBuilder.buildText(templateData);case "md":templateData.content = content.toMD();