From a4cd45ceb400ef742ce980e5331dca3e40625b8a Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 26 Apr 2018 02:14:37 -0400 Subject: [PATCH] Exclude note prefix and suffix when searching This avoids having "1" match all notes (though really we should be searching on a plain-text string stored in a separate column). --- chrome/content/zotero/xpcom/data/item.js | 3 +-- chrome/content/zotero/xpcom/data/searchConditions.js | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index dfada89f82..4aecb5ebef 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -1644,8 +1644,7 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) { let noteText = this._noteText ? this._noteText : ''; // Add
wrapper if not present if (!noteText.match(/^
[\s\S]*<\/div>$/)) { - // Keep consistent with getNote() - noteText = '
' + noteText + '
'; + noteText = Zotero.Notes.notePrefix + noteText + Zotero.Notes.noteSuffix; } let params = [ diff --git a/chrome/content/zotero/xpcom/data/searchConditions.js b/chrome/content/zotero/xpcom/data/searchConditions.js index 6c4905f380..5fe884a9d5 100644 --- a/chrome/content/zotero/xpcom/data/searchConditions.js +++ b/chrome/content/zotero/xpcom/data/searchConditions.js @@ -338,7 +338,9 @@ Zotero.SearchConditions = new function(){ doesNotContain: true }, table: 'itemNotes', - field: 'note' + // Exclude note prefix and suffix + field: `SUBSTR(note, ${1 + Zotero.Notes.notePrefix.length}, ` + + `LENGTH(note) - ${Zotero.Notes.notePrefix.length + Zotero.Notes.noteSuffix.length})` }, { @@ -348,7 +350,9 @@ Zotero.SearchConditions = new function(){ doesNotContain: true }, table: 'items', - field: 'note' + // Exclude note prefix and suffix + field: `SUBSTR(note, ${1 + Zotero.Notes.notePrefix.length}, ` + + `LENGTH(note) - ${Zotero.Notes.notePrefix.length + Zotero.Notes.noteSuffix.length})` }, {