Advance queries in blueprints

There are docs about how to create custom methods, in this case probably a page method: Page methods | Kirby CMS

As for the actual logic, there is of course no guide. But I think if you search a bit, you will find something here on the forum you can build on.