diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js index 1a0a51c3d..78f6461b0 100644 --- a/chrome/content/zotero/xpcom/collectionTreeView.js +++ b/chrome/content/zotero/xpcom/collectionTreeView.js @@ -669,9 +669,9 @@ Zotero.ItemGroup.prototype.getName = function() Zotero.ItemGroup.prototype.getChildItems = function() { - if(this.searchText) - { - var s = new Zotero.Search(); + var s = new Zotero.Search(); + + if (this.searchText){ if (this.isCollection()) { s.addCondition('collectionID', 'is', this.ref.getID(), true); @@ -681,23 +681,26 @@ Zotero.ItemGroup.prototype.getChildItems = function() s.addCondition('savedSearchID', 'is', this.ref['id'], true); } s.addCondition('quicksearch', 'contains', this.searchText); - return Zotero.Items.get(s.search()); } else { - if(this.isCollection()) - return Zotero.getItems(this.ref.getID()); - else if(this.isLibrary()) - return Zotero.getItems(); - else if(this.isSearch()) - { - var s = new Zotero.Search(); - s.load(this.ref['id']); - return Zotero.Items.get(s.search()); + if (this.isLibrary()){ + s.addCondition('noChildren', 'true'); } - else + else if (this.isCollection()){ + s.addCondition('noChildren', 'true'); + s.addCondition('collectionID', 'is', this.ref.getID()); + } + else if (this.isSearch()){ + s.load(this.ref['id']); + } + else { return null; + } } + + var ids = s.search(); + return Zotero.Items.get(ids); } Zotero.ItemGroup.prototype.setSearch = function(searchText) diff --git a/chrome/content/zotero/xpcom/search.js b/chrome/content/zotero/xpcom/search.js index 6eb92f136..8a87d0df0 100644 --- a/chrome/content/zotero/xpcom/search.js +++ b/chrome/content/zotero/xpcom/search.js @@ -361,11 +361,14 @@ Zotero.Search.prototype._buildQuery = function(){ // Handle special conditions else { switch (data['name']){ + case 'noChildren': + var noChildren = this._conditions[i]['operator']=='true'; + // Search subfolders case 'recursive': var recursive = this._conditions[i]['operator']=='true'; continue; - + // Join mode ('any' or 'all') case 'joinMode': var joinMode = this._conditions[i]['operator'].toUpperCase(); @@ -388,8 +391,20 @@ Zotero.Search.prototype._buildQuery = function(){ } } + if (noChildren){ + sql += " WHERE (itemID NOT IN (SELECT itemID FROM itemNotes " + + "WHERE sourceItemID IS NOT NULL) AND itemID NOT IN " + + "(SELECT itemID FROM itemAttachments " + + "WHERE sourceItemID IS NOT NULL))"; + } + if (hasConditions){ - sql += " WHERE "; + if (noChildren){ + sql += " AND "; + } + else { + sql += " WHERE "; + } for each(var condition in conditions){ var openParens = 0; @@ -820,7 +835,16 @@ Zotero.SearchConditions = new function(){ // Special conditions // - // Search recursively + // Don't include child items + { + name: 'noChildren', + operators: { + true: true, + false: true + } + }, + + // Search recursively within collections { name: 'recursive', operators: {