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
parent 6f85be04fc
commit 74dfcc43c2
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

@ -641,7 +641,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())];
@ -941,3 +941,15 @@ 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
};
}