diff --git a/chrome/content/zotero/xpcom/data/search.js b/chrome/content/zotero/xpcom/data/search.js index 20a36b77f9..6c0ad10c54 100644 --- a/chrome/content/zotero/xpcom/data/search.js +++ b/chrome/content/zotero/xpcom/data/search.js @@ -700,6 +700,10 @@ Zotero.Search.prototype.search = Zotero.Promise.coroutine(function* (asTempTable for (let split of splits){ s.addCondition('fulltextWord', condition.operator, split); } + // If applicable, only search for words within specified scope (e.g. collection) + if (this._scope) { + s.setScope(this._scope, true); + } numSplits = splits.length; let wordMatches = yield s.search(); diff --git a/test/tests/searchTest.js b/test/tests/searchTest.js index c2c7a85096..e4eade07c2 100644 --- a/test/tests/searchTest.js +++ b/test/tests/searchTest.js @@ -634,6 +634,28 @@ describe("Zotero.Search", function() { // TEMP: Match parent attachment assert.sameMembers(matches, [attachment.id]); }); + + it("should not include items outside of scope during phrase search", async function () { + var col = await createDataObject('collection'); + fooItem.addToCollection(col.id); + await fooItem.saveTx(); + + // Quicksearch from a collection + let collectionScope = new Zotero.Search(); + collectionScope.libraryID = userLibraryID; + collectionScope.addCondition('noChildren', 'true'); + collectionScope.addCondition('collectionID', 'is', col.id); + + var s = new Zotero.Search(); + s.libraryID = userLibraryID; + // Phrase search + s.addCondition('quicksearch-everything', 'contains', '"foo"'); + s.setScope(collectionScope, true); + var matches = await s.search(); + // Only the item from the collection is returned + assert.equal(matches.length, 1); + assert.equal(matches[0], fooItem.id); + }); }); });