I did similar thing to my client before, I created a meta search site for my client which use WordPress Rest API that search through all of my client sites.
Here is just a little idea to working with multiple site search in different server, this is just a rough example using PHP. If you're using WP site itself as the center of the search site, then it will be much easier with wp_remote_get function.
Requirements:
Here are the codes:
Setting up API request using CURL
function call_api( $url ) {
$curl = curl_init();
curl_setopt_array( $curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true
));
$result = curl_exec($curl);
curl_close($curl);
return json_decode($result);
}
Search function to handle form submit
function site_search( $sites, $search = '' ) {
$results = array();
$api_url = 'wp-json/wp/v2';
$types = 'posts';
foreach( $sites as $site ) {
$rest_url = "{$site}/{$api_url}/{$types}?search={$search}";
$req = call_api( $rest_url );
if( $req ) {
$results = array_merge( $results, $req );
}
}
return $results;
}
the variables
//The search keyword
$search_key = isset( $_GET['search'] ) ? $_GET['search'] : '';
//lists of the sites you want to search with v2 rest api enabled
$sites = array(
'http://wordpress-site-with-v2-rest-api-enabled.com',
'http://another-wp-site-with-v2-rest-api-enabled.com',
);
the handler
$contents = array();
if( !empty( $search_key ) ) {
$contents = site_search( $sites, $search_key );
}
the HTML
<!DOCTYPE html>
<html>
<head>
<title>Test WP REST API</title>
</head>
<body>
<form method="GET">
<input type="text" name="search" value="<?php echo ( isset( $_GET['search'] ) ? $_GET['search'] : '' ); ?>" />
<input type="submit" value="SUBMIT" />
</form>
<?php foreach( $contents as $content ) : ?>
<div class="content">
<h2><a href="<?php echo $content->link; ?>"><?php echo $content->title->rendered; ?></a></h2>
<?php echo $content->excerpt->rendered; ?>
</div>
<?php endforeach; ?>
</body>
</html>
This is just a rough example, you'll need to work on security, etc. Hope this can help you get started.
"your query" (site:www.stackexchange.com) OR (site:stackoverflow.com)
in Google?