Fixes #546, Advanced search : match "any" is broken

This commit is contained in:
Dan Stillman 2015-04-09 02:57:29 -04:00
parent c1a581168a
commit f5ce2d238e
3 changed files with 21 additions and 36 deletions

View file

@ -62,25 +62,7 @@ var ZoteroAdvancedSearch = new function() {
isSearchMode: function() { return true; }, isSearchMode: function() { return true; },
getItems: function () { getItems: function () {
var search = _searchBox.search.clone(); var search = _searchBox.search.clone();
search.libraryID = _libraryID;
// Hack to create a condition for the search's library --
// this logic should really go in the search itself instead of here
// and in collectionTreeView.js
var conditions = search.getSearchConditions();
if (!conditions.some(function (condition) condition.condition == 'libraryID')) {
let libraryID = _searchBox.search.libraryID;
// TEMP: libraryIDInt
if (libraryID) {
search.addCondition('libraryID', 'is', libraryID);
}
else {
let groups = Zotero.Groups.getAll();
for (let i=0; i<groups.length; i++) {
search.addCondition('libraryID', 'isNot', groups[i].libraryID);
}
}
}
return Zotero.Items.get(search.search()); return Zotero.Items.get(search.search());
}, },
isLibrary: function () { return false; }, isLibrary: function () { return false; },

View file

@ -2148,21 +2148,6 @@ Zotero.ItemGroup.prototype.getSearchResults = function(asTempTable) {
if(!Zotero.ItemGroupCache.lastResults) { if(!Zotero.ItemGroupCache.lastResults) {
var s = this.getSearchObject(); var s = this.getSearchObject();
// FIXME: Hack to exclude group libraries for now
if (this.isSearch()) {
var currentLibraryID = this.ref.libraryID;
if (currentLibraryID) {
s.addCondition('libraryID', 'is', currentLibraryID);
}
else {
var groups = Zotero.Groups.getAll();
for each(var group in groups) {
s.addCondition('libraryID', 'isNot', group.libraryID);
}
}
}
Zotero.ItemGroupCache.lastResults = s.search(); Zotero.ItemGroupCache.lastResults = s.search();
Zotero.ItemGroupCache.lastItemGroup = this; Zotero.ItemGroupCache.lastItemGroup = this;
} }

View file

@ -36,7 +36,7 @@ Zotero.Search = function() {
Zotero.Search.prototype._init = function () { Zotero.Search.prototype._init = function () {
// Public members for access by public methods -- do not access directly // Public members for access by public methods -- do not access directly
this._id = null; this._id = null;
this._libraryID = null; this._libraryID; // TEMP: libraryIDInt
this._key = null; this._key = null;
this._name = null; this._name = null;
this._dateAdded = null; this._dateAdded = null;
@ -290,7 +290,7 @@ Zotero.Search.prototype.save = function(fixGaps) {
this._changed.dateModified ? this._changed.dateModified ?
this.dateModified : Zotero.DB.transactionDateTime, this.dateModified : Zotero.DB.transactionDateTime,
Zotero.DB.transactionDateTime, Zotero.DB.transactionDateTime,
this.libraryID ? this.libraryID : this.libraryID, this.libraryID ? this.libraryID : null,
key key
]; ];
@ -1139,6 +1139,23 @@ Zotero.Search.prototype._buildQuery = function(){
+ ")"; + ")";
} }
// Limit to library search belongs to
//
// This is equivalent to adding libraryID as a search condition,
// but it works with ANY
if (this.libraryID !== undefined) {
sql += " AND (itemID IN (SELECT itemID FROM items WHERE libraryID";
// TEMP: libraryIDInt
if (this.libraryID) {
sql += "=?";
sqlParams.push(this.libraryID);
}
else {
sql += " IS NULL";
}
sql += "))";
}
if (this._hasPrimaryConditions) { if (this._hasPrimaryConditions) {
sql += " AND "; sql += " AND ";
@ -1755,6 +1772,7 @@ Zotero.Searches = new function(){
for each(var row in rows) { for each(var row in rows) {
var search = new Zotero.Search; var search = new Zotero.Search;
search.id = row.id; search.id = row.id;
search.libraryID = libraryID;
searches.push(search); searches.push(search);
} }
return searches; return searches;