Use only keys for collections and saved searches in search conditions
Previously, 'collection' and 'savedSearch' conditions used "[libraryID]_[key]" format. Now, the condition should contain only a key, and the libraryID will be drawn from either the search itself or a libraryID search condition. Old-style conditions are still parsed if provided.
This commit is contained in:
parent
985a5db0da
commit
c917d9e30e
|
@ -451,7 +451,7 @@
|
||||||
}
|
}
|
||||||
indent += '- ';
|
indent += '- ';
|
||||||
}
|
}
|
||||||
rows.push([indent + cols[i].name, 'C' + Zotero.Collections.getLibraryKeyHash(cols[i])]);
|
rows.push([indent + cols[i].name, 'C' + cols[i].key]);
|
||||||
}
|
}
|
||||||
this.createValueMenu(rows);
|
this.createValueMenu(rows);
|
||||||
break;
|
break;
|
||||||
|
@ -462,7 +462,7 @@
|
||||||
var searches = Zotero.Searches.getAll(libraryID);
|
var searches = Zotero.Searches.getAll(libraryID);
|
||||||
for (var i in searches) {
|
for (var i in searches) {
|
||||||
if (searches[i].id != this.parent.search.id) {
|
if (searches[i].id != this.parent.search.id) {
|
||||||
rows.push([searches[i].name, 'S' + Zotero.Searches.getLibraryKeyHash(searches[i])]);
|
rows.push([searches[i].name, 'S' + searches[i].key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.createValueMenu(rows);
|
this.createValueMenu(rows);
|
||||||
|
|
|
@ -2216,9 +2216,9 @@ Zotero.CollectionTreeRow.prototype.getSearchObject = Zotero.Promise.coroutine(fu
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var s = new Zotero.Search();
|
var s = new Zotero.Search();
|
||||||
|
yield s.addCondition('libraryID', 'is', this.ref.libraryID);
|
||||||
// Library root
|
// Library root
|
||||||
if (this.isLibrary(true)) {
|
if (this.isLibrary(true)) {
|
||||||
yield s.addCondition('libraryID', 'is', this.ref.libraryID);
|
|
||||||
yield s.addCondition('noChildren', 'true');
|
yield s.addCondition('noChildren', 'true');
|
||||||
includeScopeChildren = true;
|
includeScopeChildren = true;
|
||||||
}
|
}
|
||||||
|
@ -2231,7 +2231,6 @@ Zotero.CollectionTreeRow.prototype.getSearchObject = Zotero.Promise.coroutine(fu
|
||||||
includeScopeChildren = true;
|
includeScopeChildren = true;
|
||||||
}
|
}
|
||||||
else if (this.isTrash()) {
|
else if (this.isTrash()) {
|
||||||
yield s.addCondition('libraryID', 'is', this.ref.libraryID);
|
|
||||||
yield s.addCondition('deleted', 'true');
|
yield s.addCondition('deleted', 'true');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -197,7 +197,7 @@ Zotero.Items = new function() {
|
||||||
var s = new Zotero.Search;
|
var s = new Zotero.Search;
|
||||||
yield s.addCondition('libraryID', 'is', params.libraryID);
|
yield s.addCondition('libraryID', 'is', params.libraryID);
|
||||||
if (params.scopeObject == 'collections') {
|
if (params.scopeObject == 'collections') {
|
||||||
yield s.addCondition('collection', 'is', params.libraryID + '/' + params.scopeObjectKey);
|
yield s.addCondition('collection', 'is', params.scopeObjectKey);
|
||||||
}
|
}
|
||||||
yield s.addCondition('title', 'contains', 'test');
|
yield s.addCondition('title', 'contains', 'test');
|
||||||
var ids = yield s.search();
|
var ids = yield s.search();
|
||||||
|
|
|
@ -389,9 +389,7 @@ Zotero.Search.prototype.addCondition = Zotero.Promise.coroutine(function* (condi
|
||||||
Components.utils.reportError(msg);
|
Components.utils.reportError(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var lkh = Zotero.Collections.getLibraryKeyHash(c);
|
return this.addCondition('collection', operator, c.key, required);
|
||||||
// TEMP: Bluebird return yield
|
|
||||||
return yield this.addCondition('collection', operator, lkh, required);
|
|
||||||
}
|
}
|
||||||
// Shortcut to add a saved search
|
// Shortcut to add a saved search
|
||||||
else if (condition == 'savedSearchID') {
|
else if (condition == 'savedSearchID') {
|
||||||
|
@ -402,9 +400,7 @@ Zotero.Search.prototype.addCondition = Zotero.Promise.coroutine(function* (condi
|
||||||
Components.utils.reportError(msg);
|
Components.utils.reportError(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var lkh = Zotero.Searches.getLibraryKeyHash(s);
|
return this.addCondition('savedSearch', operator, s.key, required);
|
||||||
// TEMP: Bluebird return yield
|
|
||||||
return yield this.addCondition('savedSearch', operator, lkh, required);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var searchConditionID = ++this._maxSearchConditionID;
|
var searchConditionID = ++this._maxSearchConditionID;
|
||||||
|
@ -836,7 +832,7 @@ Zotero.Search.prototype.search = Zotero.Promise.coroutine(function* (asTempTable
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if (tmpTable && !asTempTable) {
|
if (tmpTable && !asTempTable) {
|
||||||
yield Zotero.DB.queryAsync("DROP TABLE " + tmpTable);
|
yield Zotero.DB.queryAsync("DROP TABLE IF EXISTS " + tmpTable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1185,24 +1181,63 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'collection':
|
case 'collection':
|
||||||
var col;
|
case 'savedSearch':
|
||||||
if (condition.value) {
|
let obj;
|
||||||
var lkh = Zotero.Collections.parseLibraryKeyHash(condition.value);
|
let objLibraryID;
|
||||||
if (lkh) {
|
let objKey = condition.value;
|
||||||
col = yield Zotero.Collections.getByLibraryAndKeyAsync(lkh.libraryID, lkh.key);
|
let objectType = condition.name == 'collection' ? 'collection' : 'search';
|
||||||
|
let objectTypeClass = Zotero.DataObjectUtilities.getClassForObjectType(objectType);
|
||||||
|
|
||||||
|
// Old-style library-key hash
|
||||||
|
if (objKey.contains('_')) {
|
||||||
|
[objLibraryID, objKey] = objKey.split('_');
|
||||||
|
}
|
||||||
|
// libraryID assigned on search
|
||||||
|
else if (this.libraryID !== null) {
|
||||||
|
objLibraryID = this.libraryID;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If search doesn't have a libraryID, check all possible libraries
|
||||||
|
// for the collection/search
|
||||||
|
if (objLibraryID === undefined) {
|
||||||
|
let foundLibraryID = false;
|
||||||
|
for each (let c in this._conditions) {
|
||||||
|
if (c.condition == 'libraryID' && c.operator == 'is') {
|
||||||
|
foundLibraryID = true;
|
||||||
|
obj = yield objectTypeClass.getByLibraryAndKeyAsync(
|
||||||
|
c.value, objKey
|
||||||
|
);
|
||||||
|
if (obj) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!col) {
|
}
|
||||||
var msg = "Collection " + condition.value + " specified in saved search doesn't exist";
|
if (!foundLibraryID) {
|
||||||
|
Zotero.debug("WARNING: libraryID condition not found for "
|
||||||
|
+ objectType + " in search", 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
col = yield objectTypeClass.getByLibraryAndKeyAsync(
|
||||||
|
objLibraryID, objKey
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (!obj) {
|
||||||
|
var msg = objectType.charAt(0).toUpperCase() + objectType.substr(1)
|
||||||
|
+ " " + objKey + " specified in search not found";
|
||||||
Zotero.debug(msg, 2);
|
Zotero.debug(msg, 2);
|
||||||
Zotero.log(msg, 'warning', 'chrome://zotero/content/xpcom/search.js');
|
Zotero.log(msg, 'warning', 'chrome://zotero/content/xpcom/search.js');
|
||||||
col = {
|
if (objectType == 'search') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
obj = {
|
||||||
id: 0
|
id: 0
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (objectType == 'collection') {
|
||||||
var q = ['?'];
|
var q = ['?'];
|
||||||
var p = [col.id];
|
var p = [obj.id];
|
||||||
|
|
||||||
// Search descendent collections if recursive search
|
// Search descendent collections if recursive search
|
||||||
if (recursive){
|
if (recursive){
|
||||||
|
@ -1217,31 +1252,8 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () {
|
||||||
|
|
||||||
condSQL += "collectionID IN (" + q.join() + ")";
|
condSQL += "collectionID IN (" + q.join() + ")";
|
||||||
condSQLParams = condSQLParams.concat(p);
|
condSQLParams = condSQLParams.concat(p);
|
||||||
|
|
||||||
skipOperators = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'savedSearch':
|
|
||||||
condSQL += "itemID ";
|
|
||||||
if (condition['operator']=='isNot'){
|
|
||||||
condSQL += "NOT ";
|
|
||||||
}
|
}
|
||||||
condSQL += "IN (";
|
else {
|
||||||
|
|
||||||
var search;
|
|
||||||
if (condition.value) {
|
|
||||||
var lkh = Zotero.Searches.parseLibraryKeyHash(condition.value);
|
|
||||||
if (lkh) {
|
|
||||||
search = Zotero.Searches.getByLibraryAndKey(lkh.libraryID, lkh.key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!search) {
|
|
||||||
var msg = "Search " + condition.value + " specified in saved search doesn't exist";
|
|
||||||
Zotero.debug(msg, 2);
|
|
||||||
Zotero.log(msg, 'warning', 'chrome://zotero/content/xpcom/search.js');
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if there are any post-search filters
|
// Check if there are any post-search filters
|
||||||
var hasFilter = search.hasPostSearchFilter();
|
var hasFilter = search.hasPostSearchFilter();
|
||||||
|
|
||||||
|
@ -1266,6 +1278,7 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
condSQL += ")";
|
condSQL += ")";
|
||||||
|
}
|
||||||
|
|
||||||
skipOperators = true;
|
skipOperators = true;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user