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).
This commit is contained in:
Dan Stillman 2018-04-26 02:14:37 -04:00
parent 6fb99d2d90
commit a4cd45ceb4
2 changed files with 7 additions and 4 deletions

View file

@ -1644,8 +1644,7 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
let noteText = this._noteText ? this._noteText : '';
// Add <div> wrapper if not present
if (!noteText.match(/^<div class="zotero-note znv[0-9]+">[\s\S]*<\/div>$/)) {
// Keep consistent with getNote()
noteText = '<div class="zotero-note znv1">' + noteText + '</div>';
noteText = Zotero.Notes.notePrefix + noteText + Zotero.Notes.noteSuffix;
}
let params = [

View file

@ -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})`
},
{