diff --git a/out/main/index.js b/out/main/index.js
index f6d3e08..a8d6dd4 100644
--- a/out/main/index.js
+++ b/out/main/index.js
@@ -98,8 +98,7 @@ class NotesAPI {
this.encryptionKey = encryptionKey || process.env.NOTES_ENCRYPTION_KEY;
this._sodiumReady = false;
this.index = new Index({
- tokenize: "tolerant",
- resolution: 9
+ tokenize: "forward"
});
}
async _initSodium() {
@@ -179,12 +178,23 @@ class NotesAPI {
try {
const note = this._decrypt(encryptedNote.data || encryptedNote);
this.notesCache.set(note.id, note);
- this.index.add(note.id, note.title + "\n" + note.content);
+ const searchText = note.plainText || this._extractPlainText(note.content);
+ this.index.add(note.id, note.title + "\n" + searchText);
} catch (error) {
console.error("Failed to decrypt note:", error);
}
}
}
+ _extractPlainText(content) {
+ if (!content) return "";
+ if (typeof content === "string") return content;
+ const extractText = (node) => {
+ if (typeof node === "string") return node;
+ if (!node || !node.content) return "";
+ return node.content.map(extractText).join(" ");
+ };
+ return extractText(content);
+ }
/* -----------------------
Public API
------------------------*/
@@ -203,7 +213,7 @@ class NotesAPI {
getNote(id) {
return this.notesCache.get(id) ?? null;
}
- async createNote(metadata = {}, content = "") {
+ async createNote(metadata = {}, content = "", plainText = "") {
const id = crypto.randomUUID();
const now = (/* @__PURE__ */ new Date()).toISOString();
const note = {
@@ -212,14 +222,15 @@ class NotesAPI {
category: metadata.category || null,
createdAt: now,
updatedAt: now,
- content
+ content,
+ plainText
};
const encryptedNote = {
id: note.id,
data: this._encrypt(note)
};
this.notesCache.set(id, note);
- this.index.add(id, note.title + "\n" + content);
+ this.index.add(id, note.title + "\n" + plainText);
await this.adapter.create(encryptedNote);
return note;
}
@@ -228,16 +239,17 @@ class NotesAPI {
this.notesCache.delete(id);
this.index.remove(id);
}
- async updateNote(id, content) {
+ async updateNote(id, content, plainText = "") {
const note = this.notesCache.get(id);
if (!note) throw new Error("Note not found");
note.content = content;
+ note.plainText = plainText;
note.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
const encryptedNote = {
id: note.id,
data: this._encrypt(note)
};
- this.index.update(id, note.title + "\n" + content);
+ this.index.update(id, note.title + "\n" + plainText);
await this.adapter.update(encryptedNote);
return note;
}
@@ -261,12 +273,18 @@ class NotesAPI {
id: note.id,
data: this._encrypt(note)
};
- this.index.update(id, note.title + "\n" + note.content);
+ this.index.update(
+ id,
+ note.title + "\n" + (note.plainText || this._extractPlainText(note.content))
+ );
await this.adapter.update(encryptedNote);
return note;
}
search(query) {
- const ids = this.index.search(query);
+ const ids = this.index.search(query, {
+ limit: 50,
+ suggest: true
+ });
return ids.map((id) => this.notesCache.get(id));
}
}
diff --git a/src/main/core/NotesAPI.js b/src/main/core/NotesAPI.js
index 8f3f8d8..2ebcc19 100644
--- a/src/main/core/NotesAPI.js
+++ b/src/main/core/NotesAPI.js
@@ -14,8 +14,7 @@ export default class NotesAPI {
this._sodiumReady = false
this.index = new Index({
- tokenize: 'tolerant',
- resolution: 9,
+ tokenize: 'forward',
})
}
@@ -118,13 +117,28 @@ export default class NotesAPI {
const note = this._decrypt(encryptedNote.data || encryptedNote)
this.notesCache.set(note.id, note)
- this.index.add(note.id, note.title + '\n' + note.content)
+ const searchText =
+ note.plainText || this._extractPlainText(note.content)
+ this.index.add(note.id, note.title + '\n' + searchText)
} catch (error) {
console.error('Failed to decrypt note:', error)
}
}
}
+ _extractPlainText(content) {
+ if (!content) return ''
+ if (typeof content === 'string') return content
+
+ const extractText = (node) => {
+ if (typeof node === 'string') return node
+ if (!node || !node.content) return ''
+ return node.content.map(extractText).join(' ')
+ }
+
+ return extractText(content)
+ }
+
/* -----------------------
Public API
------------------------*/
@@ -150,7 +164,7 @@ export default class NotesAPI {
return this.notesCache.get(id) ?? null
}
- async createNote(metadata = {}, content = '') {
+ async createNote(metadata = {}, content = '', plainText = '') {
const id = crypto.randomUUID()
const now = new Date().toISOString()
@@ -161,6 +175,7 @@ export default class NotesAPI {
createdAt: now,
updatedAt: now,
content,
+ plainText,
}
const encryptedNote = {
@@ -169,7 +184,7 @@ export default class NotesAPI {
}
this.notesCache.set(id, note)
- this.index.add(id, note.title + '\n' + content)
+ this.index.add(id, note.title + '\n' + plainText)
await this.adapter.create(encryptedNote)
@@ -183,11 +198,12 @@ export default class NotesAPI {
this.index.remove(id)
}
- async updateNote(id, content) {
+ async updateNote(id, content, plainText = '') {
const note = this.notesCache.get(id)
if (!note) throw new Error('Note not found')
note.content = content
+ note.plainText = plainText
note.updatedAt = new Date().toISOString()
const encryptedNote = {
@@ -195,7 +211,7 @@ export default class NotesAPI {
data: this._encrypt(note),
}
- this.index.update(id, note.title + '\n' + content)
+ this.index.update(id, note.title + '\n' + plainText)
await this.adapter.update(encryptedNote)
@@ -228,7 +244,12 @@ export default class NotesAPI {
data: this._encrypt(note),
}
- this.index.update(id, note.title + '\n' + note.content)
+ this.index.update(
+ id,
+ note.title +
+ '\n' +
+ (note.plainText || this._extractPlainText(note.content)),
+ )
await this.adapter.update(encryptedNote)
@@ -236,7 +257,10 @@ export default class NotesAPI {
}
search(query) {
- const ids = this.index.search(query)
+ const ids = this.index.search(query, {
+ limit: 50,
+ suggest: true,
+ })
return ids.map((id) => this.notesCache.get(id))
}
}
diff --git a/src/renderer/src/components/Nav.vue b/src/renderer/src/components/Nav.vue
index bd439f5..794ae77 100644
--- a/src/renderer/src/components/Nav.vue
+++ b/src/renderer/src/components/Nav.vue
@@ -1,6 +1,8 @@
@@ -29,6 +31,9 @@ onMounted(() => {