Include parents and children in a search
Report ID 121864589
If you include parents and children in a search, parent items of deleted notes are also included in the search result, but should not.
Example:
1. Create a child note of a regular Zotero item. Insert the text "asdf".
2. Delete the child note.
3. Open the search dialog.
4. Search for notes containing "asdf". The result is empty (unless you have other notes containing "asdf".
5. Mark the checkbox "include parent and children". Now the result contains the parent item of the deleted note and all other non deleted child notes of that item.
I have inspected the source code and found the following in search.js:
if (includeParentsAndChildren || includeParents) {
var parentSQL = "SELECT itemID FROM items WHERE "
+ "itemID IN (SELECT sourceItemID FROM itemAttachments "
+ "WHERE itemID IN (" + condSQL + ")) "
+ "OR itemID IN (SELECT sourceItemID FROM itemNotes "
+ "WHERE itemID IN (" + condSQL + ")) ";
var parentSQLParams = condSQLParams.concat(condSQLParams);
}
In the condSQL query the deleted items are included. They are excluded in the sql query some lines above:
sql += " WHERE itemID " + (deleted ? "" : "NOT ") + "IN "
+ "("
+ "SELECT itemID FROM deletedItems "
+ "UNION "
+ "SELECT itemID FROM itemNotes "
+ "WHERE sourceItemID IS NOT NULL AND "
+ "sourceItemID IN (SELECT itemID FROM deletedItems) "
+ "UNION "
+ "SELECT itemID FROM itemAttachments "
+ "WHERE sourceItemID IS NOT NULL AND "
+ "sourceItemID IN (SELECT itemID FROM deletedItems) "
+ ")";
If you include parents and children in a search, parent items of deleted notes are also included in the search result, but should not.
Example:
1. Create a child note of a regular Zotero item. Insert the text "asdf".
2. Delete the child note.
3. Open the search dialog.
4. Search for notes containing "asdf". The result is empty (unless you have other notes containing "asdf".
5. Mark the checkbox "include parent and children". Now the result contains the parent item of the deleted note and all other non deleted child notes of that item.
I have inspected the source code and found the following in search.js:
if (includeParentsAndChildren || includeParents) {
var parentSQL = "SELECT itemID FROM items WHERE "
+ "itemID IN (SELECT sourceItemID FROM itemAttachments "
+ "WHERE itemID IN (" + condSQL + ")) "
+ "OR itemID IN (SELECT sourceItemID FROM itemNotes "
+ "WHERE itemID IN (" + condSQL + ")) ";
var parentSQLParams = condSQLParams.concat(condSQLParams);
}
In the condSQL query the deleted items are included. They are excluded in the sql query some lines above:
sql += " WHERE itemID " + (deleted ? "" : "NOT ") + "IN "
+ "("
+ "SELECT itemID FROM deletedItems "
+ "UNION "
+ "SELECT itemID FROM itemNotes "
+ "WHERE sourceItemID IS NOT NULL AND "
+ "sourceItemID IN (SELECT itemID FROM deletedItems) "
+ "UNION "
+ "SELECT itemID FROM itemAttachments "
+ "WHERE sourceItemID IS NOT NULL AND "
+ "sourceItemID IN (SELECT itemID FROM deletedItems) "
+ ")";
This is an old discussion that has not been active in a long time. Before commenting here, you should strongly consider starting a new discussion instead. If you think the content of this discussion is still relevant, you can link to it from your new discussion.
If you have a tested fix, we'd take a patch against master for this, but the search code is too much of a mess to change in 3.0. We'll be overhauling the search code in a future version and can address this then if it's not dealt with sooner. I've created an issue to keep track of this.