From 9d18bebb132d939b955fe0f0e22bcedda7707c39 Mon Sep 17 00:00:00 2001 From: zadam Date: Mon, 6 Dec 2021 20:43:50 +0100 Subject: [PATCH 1/2] "show in full search" closes the quick search dropdown --- src/public/app/widgets/quick_search.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/public/app/widgets/quick_search.js b/src/public/app/widgets/quick_search.js index 03087b151..a86ab138b 100644 --- a/src/public/app/widgets/quick_search.js +++ b/src/public/app/widgets/quick_search.js @@ -134,6 +134,8 @@ export default class QuickSearchWidget extends BasicWidget { } async showInFullSearch() { + this.$dropdownToggle.dropdown("hide"); + const searchNote = await dateNotesService.createSearchNote({searchString: this.$searchString.val()}); await froca.loadSearchNote(searchNote.noteId); From 263b7a84bbac3a09a23bf0c2e46bc11f4315cb9e Mon Sep 17 00:00:00 2001 From: zadam Date: Mon, 6 Dec 2021 20:54:37 +0100 Subject: [PATCH 2/2] full text search should look into link URLs as well, closes #2412 --- .../note_content_protected_fulltext.js | 28 +++++++++++++------ .../note_content_unprotected_fulltext.js | 28 +++++++++++++------ 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/services/search/expressions/note_content_protected_fulltext.js b/src/services/search/expressions/note_content_protected_fulltext.js index 6b171c3e7..b24d3801a 100644 --- a/src/services/search/expressions/note_content_protected_fulltext.js +++ b/src/services/search/expressions/note_content_protected_fulltext.js @@ -8,6 +8,7 @@ const protectedSessionService = require('../../protected_session'); const striptags = require('striptags'); const utils = require("../../utils"); +// FIXME: create common subclass with NoteContentUnprotectedFulltextExp to avoid duplication class NoteContentProtectedFulltextExp extends Expression { constructor(operator, tokens, raw) { super(); @@ -46,15 +47,7 @@ class NoteContentProtectedFulltextExp extends Expression { continue; } - content = utils.normalize(content); - - if (type === 'text' && mime === 'text/html') { - if (!this.raw && content.length < 20000) { // striptags is slow for very large notes - content = striptags(content); - } - - content = content.replace(/ /g, ' '); - } + content = this.preprocessContent(content, type, mime); if (!this.tokens.find(token => !content.includes(token))) { resultNoteSet.add(becca.notes[noteId]); @@ -63,6 +56,23 @@ class NoteContentProtectedFulltextExp extends Expression { return resultNoteSet; } + + preprocessContent(content, type, mime) { + content = utils.normalize(content.toString()); + + if (type === 'text' && mime === 'text/html') { + if (!this.raw && content.length < 20000) { // striptags is slow for very large notes + // allow link to preserve URLs: https://github.com/zadam/trilium/issues/2412 + content = striptags(content, ['a']); + + // at least the closing tag can be easily stripped + content = content.replace(/<\/a>/ig, ""); + } + + content = content.replace(/ /g, ' '); + } + return content; + } } module.exports = NoteContentProtectedFulltextExp; diff --git a/src/services/search/expressions/note_content_unprotected_fulltext.js b/src/services/search/expressions/note_content_unprotected_fulltext.js index ad43cef46..60df92570 100644 --- a/src/services/search/expressions/note_content_unprotected_fulltext.js +++ b/src/services/search/expressions/note_content_unprotected_fulltext.js @@ -6,6 +6,7 @@ const becca = require('../../../becca/becca'); const striptags = require('striptags'); const utils = require("../../utils"); +// FIXME: create common subclass with NoteContentProtectedFulltextExp to avoid duplication class NoteContentUnprotectedFulltextExp extends Expression { constructor(operator, tokens, raw) { super(); @@ -32,15 +33,7 @@ class NoteContentUnprotectedFulltextExp extends Expression { continue; } - content = utils.normalize(content.toString()); - - if (type === 'text' && mime === 'text/html') { - if (!this.raw && content.length < 20000) { // striptags is slow for very large notes - content = striptags(content); - } - - content = content.replace(/ /g, ' '); - } + content = this.preprocessContent(content, type, mime); if (!this.tokens.find(token => !content.includes(token))) { resultNoteSet.add(becca.notes[noteId]); @@ -49,6 +42,23 @@ class NoteContentUnprotectedFulltextExp extends Expression { return resultNoteSet; } + + preprocessContent(content, type, mime) { + content = utils.normalize(content.toString()); + + if (type === 'text' && mime === 'text/html') { + if (!this.raw && content.length < 20000) { // striptags is slow for very large notes + // allow link to preserve URLs: https://github.com/zadam/trilium/issues/2412 + content = striptags(content, ['a']); + + // at least the closing tag can be easily stripped + content = content.replace(/<\/a>/ig, ""); + } + + content = content.replace(/ /g, ' '); + } + return content; + } } module.exports = NoteContentUnprotectedFulltextExp;