Fix search by collection
This commit is contained in:
parent
8ba9fe7b80
commit
2894e4f462
2 changed files with 43 additions and 10 deletions
|
@ -1152,7 +1152,7 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () {
|
|||
}
|
||||
}
|
||||
else {
|
||||
col = yield objectTypeClass.getByLibraryAndKeyAsync(
|
||||
obj = yield objectTypeClass.getByLibraryAndKeyAsync(
|
||||
objLibraryID, objKey
|
||||
);
|
||||
}
|
||||
|
@ -1175,12 +1175,10 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () {
|
|||
|
||||
// Search descendent collections if recursive search
|
||||
if (recursive){
|
||||
var descendents = col.getDescendents(false, 'collection');
|
||||
if (descendents){
|
||||
for (var k in descendents){
|
||||
q.push('?');
|
||||
p.push({int:descendents[k]['id']});
|
||||
}
|
||||
var descendents = obj.getDescendents(false, 'collection');
|
||||
for (let d of descendents) {
|
||||
q.push('?');
|
||||
p.push(d.id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -101,10 +101,45 @@ describe("Zotero.Search", function() {
|
|||
if (win) {
|
||||
win.close();
|
||||
}
|
||||
yield fooItem.erase();
|
||||
yield foobarItem.erase();
|
||||
yield fooItem.eraseTx();
|
||||
yield foobarItem.eraseTx();
|
||||
});
|
||||
|
||||
|
||||
it("should find item in collection", function* () {
|
||||
var col = yield createDataObject('collection');
|
||||
var item = yield createDataObject('item', { collections: [col.id] });
|
||||
|
||||
var s = new Zotero.Search();
|
||||
s.libraryID = item.libraryID;
|
||||
s.addCondition('collection', 'is', col.key);
|
||||
var matches = yield s.search();
|
||||
assert.sameMembers(matches, [item.id]);
|
||||
});
|
||||
|
||||
it("shouldn't find item in collection with no items", function* () {
|
||||
var col = yield createDataObject('collection');
|
||||
var item = yield createDataObject('item');
|
||||
|
||||
var s = new Zotero.Search();
|
||||
s.libraryID = item.libraryID;
|
||||
s.addCondition('collection', 'is', col.key);
|
||||
var matches = yield s.search();
|
||||
assert.lengthOf(matches, 0);
|
||||
});
|
||||
|
||||
it("should find item in subcollection in recursive mode", function* () {
|
||||
var col1 = yield createDataObject('collection');
|
||||
var col2 = yield createDataObject('collection', { parentID: col1.id });
|
||||
var item = yield createDataObject('item', { collections: [col2.id] });
|
||||
|
||||
var s = new Zotero.Search();
|
||||
s.libraryID = item.libraryID;
|
||||
s.addCondition('collection', 'is', col1.key);
|
||||
s.addCondition('recursive', 'true');
|
||||
var matches = yield s.search();
|
||||
assert.sameMembers(matches, [item.id]);
|
||||
});
|
||||
|
||||
it("should return matches with full-text conditions", function* () {
|
||||
let s = new Zotero.Search();
|
||||
s.addCondition('fulltextWord', 'contains', 'foo');
|
||||
|
|
Loading…
Reference in a new issue