From baed74f0a8aad0cb3765dc9c2100493950a41e72 Mon Sep 17 00:00:00 2001 From: ghost Date: Mon, 14 Aug 2023 11:15:29 +0300 Subject: [PATCH] add url support in search requests --- src/library/sphinxql.php | 29 +++++++++++++++++++++-------- src/public/search.php | 12 +++++++++--- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/library/sphinxql.php b/src/library/sphinxql.php index 709d34b..65de5ed 100644 --- a/src/library/sphinxql.php +++ b/src/library/sphinxql.php @@ -50,17 +50,30 @@ class SphinxQL { private static function _match(string $keyword) : string { $keyword = trim($keyword); - $keyword = preg_replace('/[\:]+/', ':', $keyword); + + // Parse url request + $peerAddress = $keyword; + $peerRemoteScheme = $keyword; + $peerRemoteHost = $keyword; + $peerRemotePort = $keyword; + + if ($url = Yggverse\Parser\Url::parse($keyword)) { + + $peerAddress = $url->host->name ? $url->host->name : $keyword; + $peerRemoteScheme = $url->host->scheme ? $url->host->scheme : $keyword; + $peerRemoteHost = $url->host->name ? $url->host->name : $keyword; + $peerRemotePort = $url->host->port ? $url->host->port : $keyword; + } return sprintf( '@peerAddress "%s" | @peerKey "%s" | @peerCoordinatePort "%s" | @peerCoordinateRoute "%s" | @peerRemoteScheme "%s" | @peerRemoteHost "%s" | @peerRemotePort "%s"', - preg_replace('/[^A-z0-9\:]/', '', $keyword), - preg_replace('/[^A-z0-9]/', '', $keyword), - preg_replace('/[^\d]/', '', $keyword), - preg_replace('/[^\d]/', '', $keyword), - preg_replace('/[^A-z]/', '', $keyword), - preg_replace('/[^A-z0-9\.\:]/', '', $keyword), - preg_replace('/[^\d]/', '', $keyword), + preg_replace('/[^A-z0-9\:\[\]]/', '', $peerAddress), + preg_replace('/[^A-z0-9]/', '', $keyword), + preg_replace('/[^\d]/', '', $keyword), + preg_replace('/[^\d]/', '', $keyword), + preg_replace('/[^A-z]/', '', $peerRemoteScheme), + preg_replace('/[^A-z0-9\.\:\[\]]/', '', $peerRemoteHost), + preg_replace('/[^\d]/', '', $peerRemotePort), ); } } diff --git a/src/public/search.php b/src/public/search.php index 3b7d23d..70bacc9 100644 --- a/src/public/search.php +++ b/src/public/search.php @@ -146,7 +146,9 @@ $results = $sphinx->searchPeers($requestQuery, - peerremotescheme, $requestQuery)) { ?> + peerremotescheme, + Yggverse\Parser\Url::is($requestQuery) ? Yggverse\Parser\Url::parse($requestQuery)->host->scheme : $requestQuery)) { ?> @@ -157,7 +159,9 @@ $results = $sphinx->searchPeers($requestQuery, - peerremotehost, $requestQuery)) { ?> + peerremotehost, + Yggverse\Parser\Url::is($requestQuery) ? Yggverse\Parser\Url::parse($requestQuery)->host->name : $requestQuery)) { ?> @@ -168,7 +172,9 @@ $results = $sphinx->searchPeers($requestQuery, - peerremoteport, $requestQuery)) { ?> + peerremoteport, + Yggverse\Parser\Url::is($requestQuery) ? (int) Yggverse\Parser\Url::parse($requestQuery)->host->port : $requestQuery)) { ?>