Local API: Improve search debugging

Use our own method in order to debug scopes, with a new getter for
that property.
This commit is contained in:
Abe Jellinek 2024-07-05 13:08:51 -04:00 • committed by Dan Stillman
parent 7da9c0669d
commit e921a4bc7f
2 changed files with 16 additions and 1 deletions

View file

@ -93,6 +93,9 @@ Zotero.defineProperty(Zotero.Search.prototype, 'synced', {
Zotero.defineProperty(Zotero.Search.prototype, 'conditions', {
get: function () { return this.getConditions(); }
});
Zotero.defineProperty(Zotero.Search.prototype, 'scope', {
get: function() { return this._scope; }
});
Zotero.defineProperty(Zotero.Search.prototype, '_canHaveParent', {
value: false
});

View file

@ -661,7 +661,7 @@ Zotero.Server.LocalAPI.Items = class extends LocalAPIEndpoint {
);
Zotero.debug('Executing local API search');
Zotero.debug(search.toJSON());
Zotero.debug(searchToDebugJSON(search));
// Searches sometimes return duplicate IDs; de-duplicate first
// TODO: Fix in search.js
let uniqueResultIDs = [...new Set(await search.search())];
@ -1042,4 +1042,16 @@ function buildSearchFromSearchSyntax(parentSearch, searchStrings, condition) {
return parentSearch;
}
function searchToDebugJSON(search) {
return {
conditions: Object.values(search.conditions).map(condition => ({
condition: condition.condition,
operator: condition.operator,
value: condition.value
})),
libraryID: search.libraryID,
scope: search.scope ? searchToDebugJSON(search.scope) : undefined
};
}
class BadRequestError extends Error {}