Fixes #546, Advanced search : match "any" is broken
This commit is contained in:
parent
c1a581168a
commit
f5ce2d238e
3 changed files with 21 additions and 36 deletions
|
@ -62,25 +62,7 @@ var ZoteroAdvancedSearch = new function() {
|
|||
isSearchMode: function() { return true; },
|
||||
getItems: function () {
|
||||
var search = _searchBox.search.clone();
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
search.libraryID = _libraryID;
|
||||
return Zotero.Items.get(search.search());
|
||||
},
|
||||
isLibrary: function () { return false; },
|
||||
|
|
|
@ -2148,21 +2148,6 @@ Zotero.ItemGroup.prototype.getSearchResults = function(asTempTable) {
|
|||
|
||||
if(!Zotero.ItemGroupCache.lastResults) {
|
||||
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.lastItemGroup = this;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ Zotero.Search = function() {
|
|||
Zotero.Search.prototype._init = function () {
|
||||
// Public members for access by public methods -- do not access directly
|
||||
this._id = null;
|
||||
this._libraryID = null;
|
||||
this._libraryID; // TEMP: libraryIDInt
|
||||
this._key = null;
|
||||
this._name = null;
|
||||
this._dateAdded = null;
|
||||
|
@ -290,7 +290,7 @@ Zotero.Search.prototype.save = function(fixGaps) {
|
|||
this._changed.dateModified ?
|
||||
this.dateModified : Zotero.DB.transactionDateTime,
|
||||
Zotero.DB.transactionDateTime,
|
||||
this.libraryID ? this.libraryID : this.libraryID,
|
||||
this.libraryID ? this.libraryID : null,
|
||||
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) {
|
||||
sql += " AND ";
|
||||
|
||||
|
@ -1755,6 +1772,7 @@ Zotero.Searches = new function(){
|
|||
for each(var row in rows) {
|
||||
var search = new Zotero.Search;
|
||||
search.id = row.id;
|
||||
search.libraryID = libraryID;
|
||||
searches.push(search);
|
||||
}
|
||||
return searches;
|
||||
|
|
Loading…
Reference in a new issue