From 02612d098bd6ada82f09ca9c1f593a573eef7a36 Mon Sep 17 00:00:00 2001 From: ghost Date: Thu, 3 Aug 2023 14:08:45 +0300 Subject: [PATCH] delete getFoundHostPage method, update API version --- config/app.php.txt | 2 +- library/mysql.php | 35 ----------- library/sphinxql.php | 4 +- public/api.php | 13 +++-- public/explore.php | 134 ++++++++++++++++++++++--------------------- public/search.php | 44 +++++++------- 6 files changed, 103 insertions(+), 129 deletions(-) diff --git a/config/app.php.txt b/config/app.php.txt index 3e8a1d6..212072e 100644 --- a/config/app.php.txt +++ b/config/app.php.txt @@ -396,7 +396,7 @@ define('CRAWL_MANIFEST', true); * Manifest API version compatibility * */ -define('CRAWL_MANIFEST_API_VERSION', 0.10); +define('CRAWL_MANIFEST_API_VERSION', 0.11); /* * Set default auto-crawl status for new manifest added diff --git a/library/mysql.php b/library/mysql.php index 2811132..f7e1d15 100644 --- a/library/mysql.php +++ b/library/mysql.php @@ -295,41 +295,6 @@ class MySQL { return $query->fetch(); } - public function getFoundHostPage(int $hostPageId) { - - $query = $this->_db->prepare("SELECT `hostPage`.`hostPageId`, - `hostPage`.`uri`, - `hostPage`.`timeAdded`, - `hostPage`.`timeUpdated`, - `hostPage`.`mime`, - `hostPage`.`size`, - - `host`.`scheme`, - `host`.`name`, - `host`.`port`, - - IF (`host`.`port` IS NOT NULL, - CONCAT(`host`.`scheme`, '://', `host`.`name`, ':', `host`.`port`), - CONCAT(`host`.`scheme`, '://', `host`.`name`) - ) AS `hostURL`, - - IF (`host`.`port` IS NOT NULL, - CONCAT(`host`.`scheme`, '://', `host`.`name`, ':', `host`.`port`, `hostPage`.`uri`), - CONCAT(`host`.`scheme`, '://', `host`.`name`, `hostPage`.`uri`) - ) AS `hostPageURL` - - FROM `hostPage` - JOIN `host` ON (`host`.`hostId` = `hostPage`.`hostId`) - - WHERE `hostPage`.`hostPageId` = ? - - LIMIT 1"); - - $query->execute([$hostPageId]); - - return $query->fetch(); - } - public function addHostPage(int $hostId, int $crc32uri, string $uri, diff --git a/library/sphinxql.php b/library/sphinxql.php index e1059d1..e095bb3 100644 --- a/library/sphinxql.php +++ b/library/sphinxql.php @@ -22,13 +22,13 @@ class SphinxQL { public function searchHostPages(string $keyword, string $mime, int $start, int $limit, int $maxMatches) { - $query = $this->_sphinx->prepare("SELECT *, WEIGHT() + `rank` * IF (`rank` > 0, 1000, 1) AS `priority` + $query = $this->_sphinx->prepare("SELECT *, WEIGHT() + `rank` * IF (`rank` > 0, 1000, 1) AS `weight` FROM `hostPage` WHERE MATCH(?) AND `mime` = ? - ORDER BY `priority` DESC, WEIGHT() DESC + ORDER BY `weight` DESC, WEIGHT() DESC LIMIT " . (int) ($start >= $maxMatches ? ($maxMatches > 0 ? $maxMatches - 1 : 0) : $start) . "," . (int) $limit . " diff --git a/public/api.php b/public/api.php index 7ad232a..de3188f 100644 --- a/public/api.php +++ b/public/api.php @@ -1,7 +1,7 @@ $sphinxResult) { - if ($hostPage = $db->getFoundHostPage($sphinxResult->id)) { + if ($hostPage = $db->getHostPage($sphinxResult->id)) { - $dbResults[$i] = $hostPage; + if ($host = $db->getHost($hostPage->hostId)) { - $dbResults[$i]->weight = $sphinxResult->weight; + $dbResults[$i] = $hostPage; + + $dbResults[$i]->url = $host->url . $hostPage->uri; + + $dbResults[$i]->weight = $sphinxResult->weight; + } } } diff --git a/public/explore.php b/public/explore.php index 9b02c66..799ee00 100644 --- a/public/explore.php +++ b/public/explore.php @@ -203,81 +203,83 @@ $placeholder = Filter::plural($totalPages, [sprintf(_('Over %s page or enter the
- getFoundHostPage($hp)) { ?> -
- getLastPageDescription($hp)) { ?> - title)) { ?> -

title) ?>

+ getHostPage($hp)) { ?> + getHost($hostPage->hostId)) { ?> +
+ getLastPageDescription($hp)) { ?> + title)) { ?> +

title) ?>

+ + description)) { ?> + description) ?> + + keywords)) { ?> + keywords) ?> + - description)) { ?> - description) ?> + + identicon + url . $hostPage->uri)) ?> + +
+
+ mime)) { ?> +

+

mime ?>

- keywords)) { ?> - keywords) ?> + size)) { ?> +

+

size ?>

- - - identicon - hostURL) . urldecode($hostPage->uri)) ?> - -
-
- mime)) { ?> -

-

mime ?>

- - size)) { ?> -

-

size ?>

- - timeAdded)) { ?> -

-

timeAdded) ?>

- - timeUpdated)) { ?> -

-

timeUpdated) ?>

- - getTotalHostPageSnaps($hp); ?> -

- -

- - getHostPageSnaps($hp) as $hostPageSnap) { ?> -

- - timeAdded) ?> - -

+ timeAdded)) { ?> +

+

timeAdded) ?>

- - getTotalHostPagesToHostPageByHostPageIdTarget($hp); ?> -

- -

- - getHostPagesToHostPageByHostPageIdTarget($hp) as $hostPageIdSource) { ?> - getFoundHostPage($hostPageIdSource->hostPageIdSource)) { ?> - getLastPageDescription($hostPageIdSource->hostPageIdSource); ?> + timeUpdated)) { ?> +

+

timeUpdated) ?>

+ + getTotalHostPageSnaps($hp); ?> +

+ +

+ + getHostPageSnaps($hp) as $hostPageSnap) { ?>

- - identicon - hostURL) . (mb_strlen(urldecode($hostPage->uri)) > 32 ? '...' . mb_substr(urldecode($hostPage->uri), -32) : urldecode($hostPage->uri))) ?> - - | - - + + timeAdded) ?>

- -
+ getTotalHostPagesToHostPageByHostPageIdTarget($hp); ?> +

+ +

+ + getHostPagesToHostPageByHostPageIdTarget($hp) as $hostPageIdSource) { ?> + getHostPage($hostPageIdSource->hostPageIdSource)) { ?> + getHost($hostPage->hostId)) { ?> +

+ + identicon + url) . (mb_strlen(urldecode($hostPage->uri)) > 28 ? '...' . mb_substr(urldecode($hostPage->uri), -28) : urldecode($hostPage->uri))) ?> + + | + + + +

+ + + + +
+
diff --git a/public/search.php b/public/search.php index 9d64e7c..71537ae 100644 --- a/public/search.php +++ b/public/search.php @@ -318,28 +318,30 @@ if (filter_var($q, FILTER_VALIDATE_URL) && preg_match(CRAWL_URL_REGEXP, $q)) {
- getFoundHostPage($result->id)) { ?> -
- getLastPageDescription($result->id)) { ?> - title)) { ?> -

title ?>

+ getHostPage($result->id)) { ?> + getHost($hostPage->hostId)) { ?> +
+ getLastPageDescription($result->id)) { ?> + title)) { ?> +

title ?>

+ + description)) { ?> + description ?> + + keywords)) { ?> + keywords ?> + - description)) { ?> - description ?> - - keywords)) { ?> - keywords ?> - - - - identicon - hostURL) . (mb_strlen(urldecode($hostPage->uri)) > 28 ? '...' . mb_substr(urldecode($hostPage->uri), -28) : urldecode($hostPage->uri))) ?> - - | - - - -
+ + identicon + url) . (mb_strlen(urldecode($hostPage->uri)) > 28 ? '...' . mb_substr(urldecode($hostPage->uri), -28) : urldecode($hostPage->uri))) ?> + + | + + + +
+