Browse Source

add url support in search requests

yggdrasil-0.4.7
ghost 1 year ago
parent
commit
baed74f0a8
  1. 23
      src/library/sphinxql.php
  2. 12
      src/public/search.php

23
src/library/sphinxql.php

@ -50,17 +50,30 @@ class SphinxQL { @@ -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\:\[\]]/', '', $peerAddress),
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-z]/', '', $peerRemoteScheme),
preg_replace('/[^A-z0-9\.\:\[\]]/', '', $peerRemoteHost),
preg_replace('/[^\d]/', '', $peerRemotePort),
);
}
}

12
src/public/search.php

@ -146,7 +146,9 @@ $results = $sphinx->searchPeers($requestQuery, @@ -146,7 +146,9 @@ $results = $sphinx->searchPeers($requestQuery,
<?php } ?>
</td>
<td class="text-center">
<?php if (false === strpos($result->peerremotescheme, $requestQuery)) { ?>
<?php if (false === strpos(
$result->peerremotescheme,
Yggverse\Parser\Url::is($requestQuery) ? Yggverse\Parser\Url::parse($requestQuery)->host->scheme : $requestQuery)) { ?>
<span title="<?php echo $result->peerremotescheme ?>" class="font-size-22 cursor-default text-color-red">
&bull;
</span>
@ -157,7 +159,9 @@ $results = $sphinx->searchPeers($requestQuery, @@ -157,7 +159,9 @@ $results = $sphinx->searchPeers($requestQuery,
<?php } ?>
</td>
<td class="text-center">
<?php if (false === strpos($result->peerremotehost, $requestQuery)) { ?>
<?php if (false === strpos(
$result->peerremotehost,
Yggverse\Parser\Url::is($requestQuery) ? Yggverse\Parser\Url::parse($requestQuery)->host->name : $requestQuery)) { ?>
<span title="<?php echo $result->peerremotehost ?>" class="font-size-22 cursor-default text-color-red">
&bull;
</span>
@ -168,7 +172,9 @@ $results = $sphinx->searchPeers($requestQuery, @@ -168,7 +172,9 @@ $results = $sphinx->searchPeers($requestQuery,
<?php } ?>
</td>
<td class="text-center">
<?php if (false === strpos($result->peerremoteport, $requestQuery)) { ?>
<?php if (false === strpos(
$result->peerremoteport,
Yggverse\Parser\Url::is($requestQuery) ? (int) Yggverse\Parser\Url::parse($requestQuery)->host->port : $requestQuery)) { ?>
<span title="<?php echo $result->peerremoteport ?>" class="font-size-22 cursor-default text-color-red">
&bull;
</span>

Loading…
Cancel
Save