Zotero.Search.prototype.addCondition() doesn't need to be async
This commit is contained in:
parent
973e602cfc
commit
293f7c6dd4
|
@ -62,7 +62,7 @@ var ZoteroAdvancedSearch = new function() {
|
||||||
ref: _searchBox.search,
|
ref: _searchBox.search,
|
||||||
isSearchMode: function() { return true; },
|
isSearchMode: function() { return true; },
|
||||||
getItems: Zotero.Promise.coroutine(function* () {
|
getItems: Zotero.Promise.coroutine(function* () {
|
||||||
var search = yield _searchBox.search.clone();
|
var search = _searchBox.search.clone();
|
||||||
search.libraryID = _libraryID;
|
search.libraryID = _libraryID;
|
||||||
var ids = yield search.search();
|
var ids = yield search.search();
|
||||||
return Zotero.Items.get(ids);
|
return Zotero.Items.get(ids);
|
||||||
|
@ -128,7 +128,7 @@ var ZoteroAdvancedSearch = new function() {
|
||||||
name.value = untitled;
|
name.value = untitled;
|
||||||
}
|
}
|
||||||
|
|
||||||
var s = yield _searchBox.search.clone();
|
var s = _searchBox.search.clone();
|
||||||
s.name = name.value;
|
s.name = name.value;
|
||||||
yield s.save();
|
yield s.save();
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ Zotero.API = {
|
||||||
s2.setScope(s);
|
s2.setScope(s);
|
||||||
var groups = Zotero.Groups.getAll();
|
var groups = Zotero.Groups.getAll();
|
||||||
for each(var group in groups) {
|
for each(var group in groups) {
|
||||||
yield s2.addCondition('libraryID', 'isNot', group.libraryID);
|
s2.addCondition('libraryID', 'isNot', group.libraryID);
|
||||||
}
|
}
|
||||||
var ids = yield s2.search();
|
var ids = yield s2.search();
|
||||||
break;
|
break;
|
||||||
|
@ -90,29 +90,29 @@ Zotero.API = {
|
||||||
|
|
||||||
var s = new Zotero.Search;
|
var s = new Zotero.Search;
|
||||||
if (params.libraryID !== undefined) {
|
if (params.libraryID !== undefined) {
|
||||||
yield s.addCondition('libraryID', 'is', params.libraryID);
|
s.addCondition('libraryID', 'is', params.libraryID);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params.objectKey) {
|
if (params.objectKey) {
|
||||||
yield s.addCondition('key', 'is', params.objectKey);
|
s.addCondition('key', 'is', params.objectKey);
|
||||||
}
|
}
|
||||||
else if (params.objectID) {
|
else if (params.objectID) {
|
||||||
Zotero.debug('adding ' + params.objectID);
|
Zotero.debug('adding ' + params.objectID);
|
||||||
yield s.addCondition('itemID', 'is', params.objectID);
|
s.addCondition('itemID', 'is', params.objectID);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params.itemKey) {
|
if (params.itemKey) {
|
||||||
yield s.addCondition('blockStart');
|
s.addCondition('blockStart');
|
||||||
for (let i=0; i<params.itemKey.length; i++) {
|
for (let i=0; i<params.itemKey.length; i++) {
|
||||||
let itemKey = params.itemKey[i];
|
let itemKey = params.itemKey[i];
|
||||||
yield s.addCondition('key', 'is', itemKey);
|
s.addCondition('key', 'is', itemKey);
|
||||||
}
|
}
|
||||||
yield s.addCondition('blockEnd');
|
s.addCondition('blockEnd');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display all top-level items
|
// Display all top-level items
|
||||||
/*if (params.onlyTopLevel) {
|
/*if (params.onlyTopLevel) {
|
||||||
yield s.addCondition('noChildren', 'true');
|
s.addCondition('noChildren', 'true');
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
var ids = yield s.search();
|
var ids = yield s.search();
|
||||||
|
|
|
@ -1054,8 +1054,8 @@ Zotero.CollectionTreeView.prototype._expandRow = Zotero.Promise.coroutine(functi
|
||||||
let s = new Zotero.Search;
|
let s = new Zotero.Search;
|
||||||
s.libraryID = libraryID;
|
s.libraryID = libraryID;
|
||||||
s.name = Zotero.getString('pane.collections.unfiled');
|
s.name = Zotero.getString('pane.collections.unfiled');
|
||||||
yield s.addCondition('libraryID', 'is', libraryID);
|
s.addCondition('libraryID', 'is', libraryID);
|
||||||
yield s.addCondition('unfiled', 'true');
|
s.addCondition('unfiled', 'true');
|
||||||
this._addRow(rows, new Zotero.CollectionTreeRow('unfiled', s), level + 1, row + 1 + newRows);
|
this._addRow(rows, new Zotero.CollectionTreeRow('unfiled', s), level + 1, row + 1 + newRows);
|
||||||
newRows++;
|
newRows++;
|
||||||
}
|
}
|
||||||
|
@ -2295,22 +2295,22 @@ 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);
|
s.addCondition('libraryID', 'is', this.ref.libraryID);
|
||||||
// Library root
|
// Library root
|
||||||
if (this.isLibrary(true)) {
|
if (this.isLibrary(true)) {
|
||||||
yield s.addCondition('noChildren', 'true');
|
s.addCondition('noChildren', 'true');
|
||||||
includeScopeChildren = true;
|
includeScopeChildren = true;
|
||||||
}
|
}
|
||||||
else if (this.isCollection()) {
|
else if (this.isCollection()) {
|
||||||
yield s.addCondition('noChildren', 'true');
|
s.addCondition('noChildren', 'true');
|
||||||
yield s.addCondition('collectionID', 'is', this.ref.id);
|
s.addCondition('collectionID', 'is', this.ref.id);
|
||||||
if (Zotero.Prefs.get('recursiveCollections')) {
|
if (Zotero.Prefs.get('recursiveCollections')) {
|
||||||
yield s.addCondition('recursive', 'true');
|
s.addCondition('recursive', 'true');
|
||||||
}
|
}
|
||||||
includeScopeChildren = true;
|
includeScopeChildren = true;
|
||||||
}
|
}
|
||||||
else if (this.isTrash()) {
|
else if (this.isTrash()) {
|
||||||
yield s.addCondition('deleted', 'true');
|
s.addCondition('deleted', 'true');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new Error('Invalid search mode in Zotero.CollectionTreeRow.getSearchObject()');
|
throw new Error('Invalid search mode in Zotero.CollectionTreeRow.getSearchObject()');
|
||||||
|
@ -2320,19 +2320,19 @@ Zotero.CollectionTreeRow.prototype.getSearchObject = Zotero.Promise.coroutine(fu
|
||||||
// Create the outer (filter) search
|
// Create the outer (filter) search
|
||||||
var s2 = new Zotero.Search();
|
var s2 = new Zotero.Search();
|
||||||
if (this.isTrash()) {
|
if (this.isTrash()) {
|
||||||
yield s2.addCondition('deleted', 'true');
|
s2.addCondition('deleted', 'true');
|
||||||
}
|
}
|
||||||
s2.setScope(s, includeScopeChildren);
|
s2.setScope(s, includeScopeChildren);
|
||||||
|
|
||||||
if (this.searchText) {
|
if (this.searchText) {
|
||||||
var cond = 'quicksearch-' + Zotero.Prefs.get('search.quicksearch-mode');
|
var cond = 'quicksearch-' + Zotero.Prefs.get('search.quicksearch-mode');
|
||||||
yield s2.addCondition(cond, 'contains', this.searchText);
|
s2.addCondition(cond, 'contains', this.searchText);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.tags){
|
if (this.tags){
|
||||||
for (var tag in this.tags){
|
for (var tag in this.tags){
|
||||||
if (this.tags[tag]){
|
if (this.tags[tag]){
|
||||||
yield s2.addCondition('tag', 'is', tag);
|
s2.addCondition('tag', 'is', tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,11 +194,11 @@ Zotero.Items = function() {
|
||||||
this.apiDataGenerator = function* (params) {
|
this.apiDataGenerator = function* (params) {
|
||||||
Zotero.debug(params);
|
Zotero.debug(params);
|
||||||
var s = new Zotero.Search;
|
var s = new Zotero.Search;
|
||||||
yield s.addCondition('libraryID', 'is', params.libraryID);
|
s.addCondition('libraryID', 'is', params.libraryID);
|
||||||
if (params.scopeObject == 'collections') {
|
if (params.scopeObject == 'collections') {
|
||||||
yield s.addCondition('collection', 'is', params.scopeObjectKey);
|
s.addCondition('collection', 'is', params.scopeObjectKey);
|
||||||
}
|
}
|
||||||
yield s.addCondition('title', 'contains', 'test');
|
s.addCondition('title', 'contains', 'test');
|
||||||
var ids = yield s.search();
|
var ids = yield s.search();
|
||||||
|
|
||||||
yield '[\n';
|
yield '[\n';
|
||||||
|
|
|
@ -67,7 +67,7 @@ Zotero.Duplicates.prototype.getSearchObject = Zotero.Promise.coroutine(function*
|
||||||
|
|
||||||
var s = new Zotero.Search;
|
var s = new Zotero.Search;
|
||||||
s.libraryID = this._libraryID;
|
s.libraryID = this._libraryID;
|
||||||
yield s.addCondition('tempTable', 'is', 'tmpDuplicates');
|
s.addCondition('tempTable', 'is', 'tmpDuplicates');
|
||||||
return s;
|
return s;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -282,7 +282,7 @@ Zotero.Search.prototype._finalizeSave = Zotero.Promise.coroutine(function* (env)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
Zotero.Search.prototype.clone = Zotero.Promise.coroutine(function* (libraryID) {
|
Zotero.Search.prototype.clone = function (libraryID) {
|
||||||
var s = new Zotero.Search();
|
var s = new Zotero.Search();
|
||||||
s.libraryID = libraryID === undefined ? this.libraryID : libraryID;
|
s.libraryID = libraryID === undefined ? this.libraryID : libraryID;
|
||||||
|
|
||||||
|
@ -293,19 +293,19 @@ Zotero.Search.prototype.clone = Zotero.Promise.coroutine(function* (libraryID) {
|
||||||
condition.condition + '/' + condition.mode :
|
condition.condition + '/' + condition.mode :
|
||||||
condition.condition
|
condition.condition
|
||||||
|
|
||||||
yield s.addCondition(name, condition.operator, condition.value,
|
s.addCondition(name, condition.operator, condition.value,
|
||||||
condition.required);
|
condition.required);
|
||||||
}
|
}
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
});
|
};
|
||||||
|
|
||||||
|
|
||||||
Zotero.Search.prototype.addCondition = Zotero.Promise.coroutine(function* (condition, operator, value, required) {
|
Zotero.Search.prototype.addCondition = function (condition, operator, value, required) {
|
||||||
this._requireData('conditions');
|
this._requireData('conditions');
|
||||||
|
|
||||||
if (!Zotero.SearchConditions.hasOperator(condition, operator)){
|
if (!Zotero.SearchConditions.hasOperator(condition, operator)){
|
||||||
throw ("Invalid operator '" + operator + "' for condition " + condition);
|
throw new Error("Invalid operator '" + operator + "' for condition " + condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shortcut to add a condition on every table -- does not return an id
|
// Shortcut to add a condition on every table -- does not return an id
|
||||||
|
@ -313,71 +313,79 @@ Zotero.Search.prototype.addCondition = Zotero.Promise.coroutine(function* (condi
|
||||||
var parts = Zotero.SearchConditions.parseSearchString(value);
|
var parts = Zotero.SearchConditions.parseSearchString(value);
|
||||||
|
|
||||||
for each(var part in parts) {
|
for each(var part in parts) {
|
||||||
yield this.addCondition('blockStart');
|
this.addCondition('blockStart');
|
||||||
|
|
||||||
// If search string is 8 characters, see if this is a item key
|
// If search string is 8 characters, see if this is a item key
|
||||||
if (operator == 'contains' && part.text.length == 8) {
|
if (operator == 'contains' && part.text.length == 8) {
|
||||||
yield this.addCondition('key', 'is', part.text, false);
|
this.addCondition('key', 'is', part.text, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (condition == 'quicksearch-titleCreatorYear') {
|
if (condition == 'quicksearch-titleCreatorYear') {
|
||||||
yield this.addCondition('title', operator, part.text, false);
|
this.addCondition('title', operator, part.text, false);
|
||||||
yield this.addCondition('publicationTitle', operator, part.text, false);
|
this.addCondition('publicationTitle', operator, part.text, false);
|
||||||
yield this.addCondition('shortTitle', operator, part.text, false);
|
this.addCondition('shortTitle', operator, part.text, false);
|
||||||
yield this.addCondition('court', operator, part.text, false);
|
this.addCondition('court', operator, part.text, false);
|
||||||
yield this.addCondition('year', operator, part.text, false);
|
this.addCondition('year', operator, part.text, false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
yield this.addCondition('field', operator, part.text, false);
|
this.addCondition('field', operator, part.text, false);
|
||||||
yield this.addCondition('tag', operator, part.text, false);
|
this.addCondition('tag', operator, part.text, false);
|
||||||
yield this.addCondition('note', operator, part.text, false);
|
this.addCondition('note', operator, part.text, false);
|
||||||
}
|
}
|
||||||
yield this.addCondition('creator', operator, part.text, false);
|
this.addCondition('creator', operator, part.text, false);
|
||||||
|
|
||||||
if (condition == 'quicksearch-everything') {
|
if (condition == 'quicksearch-everything') {
|
||||||
yield this.addCondition('annotation', operator, part.text, false);
|
this.addCondition('annotation', operator, part.text, false);
|
||||||
|
|
||||||
if (part.inQuotes) {
|
if (part.inQuotes) {
|
||||||
yield this.addCondition('fulltextContent', operator, part.text, false);
|
this.addCondition('fulltextContent', operator, part.text, false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var splits = Zotero.Fulltext.semanticSplitter(part.text);
|
var splits = Zotero.Fulltext.semanticSplitter(part.text);
|
||||||
for each(var split in splits) {
|
for each(var split in splits) {
|
||||||
yield this.addCondition('fulltextWord', operator, split, false);
|
this.addCondition('fulltextWord', operator, split, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
yield this.addCondition('blockEnd');
|
this.addCondition('blockEnd');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (condition == 'quicksearch-titleCreatorYear') {
|
if (condition == 'quicksearch-titleCreatorYear') {
|
||||||
yield this.addCondition('noChildren', 'true');
|
this.addCondition('noChildren', 'true');
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Shortcut to add a collection
|
// Shortcut to add a collection (which must be loaded first)
|
||||||
else if (condition == 'collectionID') {
|
else if (condition == 'collectionID') {
|
||||||
var c = yield Zotero.Collections.getAsync(value);
|
let [libraryID, key] = Zotero.Collections.getLibraryAndKeyFromID(value);
|
||||||
if (!c) {
|
if (!key) {
|
||||||
var msg = "Collection " + value + " not found";
|
let msg = "Collection " + value + " not found";
|
||||||
Zotero.debug(msg, 2);
|
Zotero.debug(msg, 2);
|
||||||
Components.utils.reportError(msg);
|
Components.utils.reportError(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return this.addCondition('collection', operator, c.key, required);
|
if (this.libraryID && libraryID != this.libraryID) {
|
||||||
|
Zotero.logError(new Error("Collection " + value + " is in different library"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return this.addCondition('collection', operator, key, required);
|
||||||
}
|
}
|
||||||
// Shortcut to add a saved search
|
// Shortcut to add a saved search (which must be loaded first)
|
||||||
else if (condition == 'savedSearchID') {
|
else if (condition == 'savedSearchID') {
|
||||||
var s = yield Zotero.Searches.getAsync(value);
|
let [libraryID, key] = Zotero.Searches.getLibraryAndKeyFromID(value);
|
||||||
if (!s) {
|
if (!key) {
|
||||||
var msg = "Saved search " + value + " not found";
|
let msg = "Saved search " + value + " not found";
|
||||||
Zotero.debug(msg, 2);
|
Zotero.debug(msg, 2);
|
||||||
Components.utils.reportError(msg);
|
Components.utils.reportError(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return this.addCondition('savedSearch', operator, s.key, required);
|
if (this.libraryID && libraryID != this.libraryID) {
|
||||||
|
Zotero.logError(new Error("Collection " + value + " is in different library"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return this.addCondition('savedSearch', operator, key, required);
|
||||||
}
|
}
|
||||||
|
|
||||||
var searchConditionID = ++this._maxSearchConditionID;
|
var searchConditionID = ++this._maxSearchConditionID;
|
||||||
|
@ -399,7 +407,7 @@ Zotero.Search.prototype.addCondition = Zotero.Promise.coroutine(function* (condi
|
||||||
this._sql = null;
|
this._sql = null;
|
||||||
this._sqlParams = false;
|
this._sqlParams = false;
|
||||||
return searchConditionID;
|
return searchConditionID;
|
||||||
});
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -691,12 +699,12 @@ Zotero.Search.prototype.search = Zotero.Promise.coroutine(function* (asTempTable
|
||||||
else if (joinMode == 'any' && !c.required) {
|
else if (joinMode == 'any' && !c.required) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
yield s.addCondition(c.condition, c.operator, c.value);
|
s.addCondition(c.condition, c.operator, c.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
var splits = Zotero.Fulltext.semanticSplitter(condition.value);
|
var splits = Zotero.Fulltext.semanticSplitter(condition.value);
|
||||||
for each(var split in splits){
|
for each(var split in splits){
|
||||||
yield s.addCondition('fulltextWord', condition.operator, split);
|
s.addCondition('fulltextWord', condition.operator, split);
|
||||||
}
|
}
|
||||||
var fulltextWordIDs = yield s.search();
|
var fulltextWordIDs = yield s.search();
|
||||||
|
|
||||||
|
|
|
@ -859,7 +859,7 @@ var ZoteroPane = new function()
|
||||||
|
|
||||||
var s = new Zotero.Search();
|
var s = new Zotero.Search();
|
||||||
s.libraryID = this.getSelectedLibraryID();
|
s.libraryID = this.getSelectedLibraryID();
|
||||||
yield s.addCondition('title', 'contains', '');
|
s.addCondition('title', 'contains', '');
|
||||||
|
|
||||||
var untitled = Zotero.getString('pane.collections.untitled');
|
var untitled = Zotero.getString('pane.collections.untitled');
|
||||||
untitled = yield Zotero.DB.getNextName('savedSearches', 'savedSearchName',
|
untitled = yield Zotero.DB.getNextName('savedSearches', 'savedSearchName',
|
||||||
|
@ -953,7 +953,7 @@ var ZoteroPane = new function()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
this.openAdvancedSearchWindow = Zotero.Promise.coroutine(function* () {
|
this.openAdvancedSearchWindow = function () {
|
||||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
||||||
.getService(Components.interfaces.nsIWindowMediator);
|
.getService(Components.interfaces.nsIWindowMediator);
|
||||||
var enumerator = wm.getEnumerator('zotero:search');
|
var enumerator = wm.getEnumerator('zotero:search');
|
||||||
|
@ -968,11 +968,11 @@ var ZoteroPane = new function()
|
||||||
|
|
||||||
var s = new Zotero.Search();
|
var s = new Zotero.Search();
|
||||||
s.libraryID = this.getSelectedLibraryID();
|
s.libraryID = this.getSelectedLibraryID();
|
||||||
yield s.addCondition('title', 'contains', '');
|
s.addCondition('title', 'contains', '');
|
||||||
|
|
||||||
var io = {dataIn: {search: s}, dataOut: null};
|
var io = {dataIn: {search: s}, dataOut: null};
|
||||||
window.openDialog('chrome://zotero/content/advancedSearch.xul', '', 'chrome,dialog=no,centerscreen', io);
|
window.openDialog('chrome://zotero/content/advancedSearch.xul', '', 'chrome,dialog=no,centerscreen', io);
|
||||||
});
|
};
|
||||||
|
|
||||||
|
|
||||||
this.toggleTagSelector = Zotero.Promise.coroutine(function* () {
|
this.toggleTagSelector = Zotero.Promise.coroutine(function* () {
|
||||||
|
|
|
@ -598,7 +598,7 @@ function ZoteroProtocolHandler() {
|
||||||
search.setScope(s);
|
search.setScope(s);
|
||||||
var groups = yield Zotero.Groups.getAll();
|
var groups = yield Zotero.Groups.getAll();
|
||||||
for each(var group in groups) {
|
for each(var group in groups) {
|
||||||
yield search.addCondition('libraryID', 'isNot', group.libraryID);
|
search.addCondition('libraryID', 'isNot', group.libraryID);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -624,8 +624,8 @@ function ZoteroProtocolHandler() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let s = new Zotero.Search();
|
let s = new Zotero.Search();
|
||||||
yield s.addCondition('libraryID', 'is', params.libraryID);
|
s.addCondition('libraryID', 'is', params.libraryID);
|
||||||
yield s.addCondition('noChildren', 'true');
|
s.addCondition('noChildren', 'true');
|
||||||
var ids = yield s.search();
|
var ids = yield s.search();
|
||||||
var results = yield Zotero.Items.getAsync(ids);
|
var results = yield Zotero.Items.getAsync(ids);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user