Search pages that are a child of the current page

I started this in a comment but thought I’d expand it for you because I do like the question 😉

I’d probably tackle this by adding a hidden field to the search form with the current page ID, and then using the pre_get_posts filter to modify the search query to only return pages with a matching parent.

However: I don’t think we can deal with an additional level of subpages in this way, just the first level. I know this answer therefore doesn’t completely answer your question, but it’s a start, and I’ll add to it if I can figure this out (in the meantime, hopefully someone else can use this as a base for their own answer).

1. Adding the hidden field

In your theme, you’ll need to create a searchform.php if it’s not already there, in order to modify the default form that is output. If you’re creating this from scratch, you can grab the existing form from this page.

We’ll then add a hidden field, in between the <form></form> tags, printing out either the ID of the current page, or its parent page if we’re not at the top level:

<?php if(is_page()){ ?>
  <input type="hidden" name="current_page_id" value="<?php echo $post->post_parent == 0 ? $post->ID : $post->post_parent; ?>" />
<?php } ?>

2. Hooking into pre_get_posts

In your theme’s functions.php, we’ll need to hook into WordPress’ pre_get_posts action to modify the query to exclude pages that aren’t in our desired hierarchy. Of course, we want to make sure we only do this when doing a search:

add_action("pre_get_posts", "wpse_226092_search_by_page_parent");

function wpse_226092_search_by_page_parent($query){
  if(!is_admin() && $query->is_main_query() && is_search() && isset($_GET["current_page_id"])){
    $query->set("post_parent", $_GET["current_page_id"]);
  }
}

There’s a few other conditionals in that code there, to make sure we don’t affect the admin panel or other queries on the page (such as menu queries), and of course to make sure our custom value is actually set before we try to use it.

I haven’t tested this, but fairly sure it should work!