diff --git a/src/services/search/expressions/note_content_protected_fulltext.js b/src/services/search/expressions/note_content_protected_fulltext.js index 0ed21eb15..c66645865 100644 --- a/src/services/search/expressions/note_content_protected_fulltext.js +++ b/src/services/search/expressions/note_content_protected_fulltext.js @@ -8,7 +8,7 @@ const protectedSessionService = require('../../protected_session'); const striptags = require('striptags'); class NoteContentProtectedFulltextExp extends Expression { - constructor(operator, tokens) { + constructor(operator, tokens, raw) { super(); if (operator !== '*=*') { @@ -16,6 +16,7 @@ class NoteContentProtectedFulltextExp extends Expression { } this.tokens = tokens; + this.raw = !!raw; } execute(inputNoteSet) { @@ -47,7 +48,7 @@ class NoteContentProtectedFulltextExp extends Expression { content = content.toLowerCase(); if (type === 'text' && mime === 'text/html') { - if (content.length < 20000) { // striptags is slow for very large notes + if (!this.raw && content.length < 20000) { // striptags is slow for very large notes content = striptags(content); } diff --git a/src/services/search/expressions/note_content_unprotected_fulltext.js b/src/services/search/expressions/note_content_unprotected_fulltext.js index a9a531269..aace6a115 100644 --- a/src/services/search/expressions/note_content_unprotected_fulltext.js +++ b/src/services/search/expressions/note_content_unprotected_fulltext.js @@ -6,7 +6,7 @@ const noteCache = require('../../note_cache/note_cache'); const striptags = require('striptags'); class NoteContentUnprotectedFulltextExp extends Expression { - constructor(operator, tokens) { + constructor(operator, tokens, raw) { super(); if (operator !== '*=*') { @@ -14,6 +14,7 @@ class NoteContentUnprotectedFulltextExp extends Expression { } this.tokens = tokens; + this.raw = !!raw; } execute(inputNoteSet) { @@ -33,7 +34,7 @@ class NoteContentUnprotectedFulltextExp extends Expression { content = content.toString().toLowerCase(); if (type === 'text' && mime === 'text/html') { - if (content.length < 20000) { // striptags is slow for very large notes + if (!this.raw && content.length < 20000) { // striptags is slow for very large notes content = striptags(content); } diff --git a/src/services/search/services/parse.js b/src/services/search/services/parse.js index fa1b3cc34..d6961d618 100644 --- a/src/services/search/services/parse.js +++ b/src/services/search/services/parse.js @@ -125,7 +125,9 @@ function getExpression(tokens, searchContext, level = 0) { i++; - if (tokens[i].token === 'content') { + if (['content', 'rawcontent'].includes(tokens[i].token)) { + const raw = tokens[i].token === 'rawcontent'; + i += 1; const operator = tokens[i].token; @@ -138,8 +140,8 @@ function getExpression(tokens, searchContext, level = 0) { i++; return new OrExp([ - new NoteContentUnprotectedFulltextExp(operator, [tokens[i].token]), - new NoteContentProtectedFulltextExp(operator, [tokens[i].token]) + new NoteContentUnprotectedFulltextExp(operator, [tokens[i].token], raw), + new NoteContentProtectedFulltextExp(operator, [tokens[i].token], raw) ]); }