fix quicksearch phrase search not respecting scope (#4608)

Fixes: #4381
This commit is contained in:
abaevbog 2024-09-12 03:27:29 -07:00 • committed by GitHub
parent 78077fab9d
commit 82d50676d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 0 deletions

View file

@ -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();

View file

@ -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);
});
});
});