01-16-2021, 05:33 PM | #1 |
Custom User Title
Posts: 9,369
Karma: 64435965
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Saved Searches: Recursing hierarchical searches
EDIT: "Recursing" probably isn't the right word here. I was thinking more of something similiar to the the divide-and-conquer algorithm, where a task is split up into a bunch of smaller tasks and then combined back together.
I've been starting to split up my monstrous long "Cleanup" saved search. However, I just wanted to make sure this wouldn't cause any issues. Example: If I have this hierarchy: Cleanup Cleanup.Missing Metadata Cleanup.Missing Metadata.Missing Page Count Cleanup.Missing Metadata.Missing Language Cleanup.Fanfiction Cleanup.Fanfiction.Fanfics with Errors Would there be any problem if I nested these? Cleanup would be search:"=Cleanup.Missing Metadata" OR search:"=Cleanup.Fanfiction" While Cleanup.Missing Metadata would be search:"=Cleanup.Missing Metadata.Missing Page Count" OR search:"=Cleanup.Missing Metadata.Missing Language" This seems like the best way to split it up, but I don't want to break things! Last edited by ownedbycats; 01-17-2021 at 01:09 AM. |
01-16-2021, 06:01 PM | #2 |
Custom User Title
Posts: 9,369
Karma: 64435965
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
I split it successfully (saved my monster search to a text file in case I need to revert it). Works right so long as all the subsearches are valid. But splitting it up makes it easier to track down where an error is.
Performance seems to be a bit better too. There was a tiny lag on my old search that's gone now. Last edited by ownedbycats; 01-17-2021 at 01:07 AM. |
Advert | |
|
01-17-2021, 07:04 AM | #3 | |
Grand Sorcerer
Posts: 11,963
Karma: 7225107
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Recursion means X uses itself to compute the answer; X calls X directly or indirectly. Recursion requires that X have a "termination condition"; a situation where X returns a value instead of calling X. This allows the call chain to undo and return a value. If there is no termination condition then X will call X forever, eventually running out of memory or some other resource. Saved searches do not have termination conditions so recursion is not allowed by the search parser. This Wikipedia article discusses recursion both formally and informally. |
|
01-17-2021, 03:00 PM | #4 |
Custom User Title
Posts: 9,369
Karma: 64435965
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
The only issue I found with the nesting is that you can't omit a subsearch, e.g.
search:"=Cleanup" AND NOT search:"=Cleanup.Missing Metadata.Missing Pagecount" will come up invalid, presumably because Cleanup (indirectly) calls Missing Pagecount—seems intentional enough that I won't file a bug report over it. But I can just do an OR search for all the subsearches except Missing Pagecount. Last edited by ownedbycats; 01-17-2021 at 03:05 PM. |
01-17-2021, 03:58 PM | #5 |
Grand Sorcerer
Posts: 11,963
Karma: 7225107
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
The check-for-recursion test is approximate because the search parser doesn't maintain a call (recursion) stack. Instead it uses the heuristic that a search must be recursive if the search expression executes the same saved search more than 5 times. For example, this search doesn't fail:
Code:
search:"b" or search:"b" or search:"b" or search:"b" or search:"b" Code:
search:"b" or search:"b" or search:"b" or search:"b" or search:"b" or search:"b" |
Advert | |
|
01-17-2021, 04:01 PM | #6 |
Custom User Title
Posts: 9,369
Karma: 64435965
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Cleanup contains (search:"=Cleanup.Missing Metadata"), and Cleanup.Missing Metadata contains (search:"=Cleanup.Missing Metadata.Missing Pagecount").
I did test the recursion though just to see what would happen - two searches called foo and bar that try to call each other results in a red invalid search border. |
01-17-2021, 04:04 PM | #7 |
Grand Sorcerer
Posts: 11,963
Karma: 7225107
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
When you get a recursion error the tooltip on the search box tells you what saved search calibre has seen more than 5 times.
|
01-18-2021, 05:33 AM | #8 |
Grand Sorcerer
Posts: 11,963
Karma: 7225107
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
I changed the "recursion" limit count from 5 to 10.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Saved searches in tag_browser_category_order | ownedbycats | Calibre | 2 | 10-07-2020 10:41 AM |
Saved Searches? | jim3692 | Sigil | 3 | 04-26-2020 06:10 PM |
group saved searches | Katja_hbg | Library Management | 1 | 02-04-2018 12:28 AM |
Saved searches | abecedarian | Sigil | 5 | 04-14-2017 06:48 PM |
Where are searches saved? | travger | Calibre | 2 | 08-26-2012 01:37 PM |