From fef2b1abec4bce4e993a4abb617d5886b4fda3df Mon Sep 17 00:00:00 2001 From: yggverse Date: Fri, 22 Mar 2024 22:50:52 +0200 Subject: [PATCH] implement reindex by request feature --- README.md | 3 +- composer.json | 3 +- example/config.json | 4 ++ src/cli/document/crawl.php | 4 +- src/cli/index/init.php | 4 ++ src/webui/explore.php | 85 +++++++++++++++++++++++++++++++++----- 6 files changed, 89 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 71e6899..4f19ff6 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ Yo! is the super thin layer for Manticore search server that extends official [m * [Symfony CSS selector](https://github.com/symfony/css-selector) * [FTP client for snap mirrors](https://github.com/YGGverse/ftp-php) * [Hostname ident icons](https://github.com/dmester/jdenticon-php) +* [Captcha](https://github.com/Gregwar/Captcha) * [Bootstrap icons](https://icons.getbootstrap.com/) ### Install @@ -31,7 +32,7 @@ Yo! is the super thin layer for Manticore search server that extends official [m * `wget https://repo.manticoresearch.com/manticore-repo.noarch.deb` * `dpkg -i manticore-repo.noarch.deb` * `apt update` -* `apt install git composer manticore manticore-extra php-fpm php-curl php-mbstring` +* `apt install git composer manticore manticore-extra php-fpm php-curl php-mbstring php-gd` Yo search engine uses Manticore as the primary database. If your server sensitive to power down, change default [binlog flush strategy](https://manual.manticoresearch.com/Logging/Binary_logging#Binary-flushing-strategies) to `binlog_flush = 1` diff --git a/composer.json b/composer.json index f8d2cf0..012f838 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,7 @@ "symfony/css-selector": "^6.3", "symfony/dom-crawler": "^6.3", "jdenticon/jdenticon": "^1.0", - "yggverse/ftp": "^1.0" + "yggverse/ftp": "^1.0", + "gregwar/captcha": "^1.2" } } diff --git a/example/config.json b/example/config.json index e51dad3..affdf46 100644 --- a/example/config.json +++ b/example/config.json @@ -121,6 +121,10 @@ "index":[] } ] + }, + "reindex": + { + "enabled":true } }, "cli": diff --git a/src/cli/document/crawl.php b/src/cli/document/crawl.php index 92a1d56..b9aeb61 100644 --- a/src/cli/document/crawl.php +++ b/src/cli/document/crawl.php @@ -87,6 +87,7 @@ if ($config->cli->document->crawl->debug->level->notice) foreach($index->search('') ->expression('random', 'rand()') + ->sort('reindex', 'desc') ->sort('time', 'asc') ->sort('rank', 'asc') ->sort('random', 'asc') @@ -106,7 +107,8 @@ foreach($index->search('') 'size' => $document->get('size'), 'mime' => $document->get('mime'), 'rank' => $document->get('rank'), - 'time' => $time + 'time' => $time, + 'reindex' => 0 ]; // Debug target diff --git a/src/cli/index/init.php b/src/cli/index/init.php index 6cf1a8a..0787756 100644 --- a/src/cli/index/init.php +++ b/src/cli/index/init.php @@ -85,6 +85,10 @@ $result = $index->create( 'type' => 'integer' ], 'time' => + [ + 'type' => 'integer' + ], + 'reindex' => [ 'type' => 'integer' ] diff --git a/src/webui/explore.php b/src/webui/explore.php index 3264365..65328ef 100644 --- a/src/webui/explore.php +++ b/src/webui/explore.php @@ -77,7 +77,9 @@ $icon = $identicon->getImageDataUri('webp'); $snaps = []; /// Prepare location -$md5url = md5($document->url); +$md5url = md5( + $document->url +); $filepath = implode( '/', @@ -176,6 +178,28 @@ foreach ($config->snap->storage->remote->ftp as $i => $ftp) } } +// Process reindex request +if ($config->webui->reindex->enabled) +{ + session_start(); + + if (isset($_POST['captcha']) && $_POST['captcha'] == $_SESSION['captcha']) + { + $index->updateDocument( + [ + 'reindex' => time() + ], + $document->getId() + ); + } + + $captcha = new \Gregwar\Captcha\CaptchaBuilder(); + $captcha->setBackgroundColor(46, 52, 54); + $captcha->build(); + + $_SESSION['captcha'] = $captcha->getPhrase(); +} + ?> @@ -275,9 +299,13 @@ foreach ($config->snap->storage->remote->ftp as $i => $ftp) text-align: center; } - input, - input:-webkit-autofill, - input:-webkit-autofill:focus { + fieldset { + width: 150px; + } + + input[type="text"], + input[type="text"]:-webkit-autofill, + input[type="text"]:-webkit-autofill:focus { transition: background-color 0s 600000s, color 0s 600000s; /* chrome */ width: 100%; margin: 12px 0; @@ -289,16 +317,16 @@ foreach ($config->snap->storage->remote->ftp as $i => $ftp) text-align: center; } - input:hover { + input[type="text"]:hover { background-color: #111 } - input:focus { + input[type="text"]:focus { outline: none; background-color: #111 } - input:focus::placeholder { + input[type="text"]:focus::placeholder { color: #090808 } @@ -321,13 +349,18 @@ foreach ($config->snap->storage->remote->ftp as $i => $ftp) background-color: #3394fb; color: #fff; font-size: 14px; - position: fixed; - top: 12px; - right: 24px; } - button:hover { + button { background-color: #4b9df4; + height: 32px; + vertical-align: top; + } + + header button { + position: fixed; + top: 12px; + right: 24px; } a, a:visited, a:active { @@ -455,6 +488,36 @@ foreach ($config->snap->storage->remote->ftp as $i => $ftp)

body) ?>
+ webui->reindex->enabled) { ?> +

+
+ get('reindex')) { ?> + get('reindex'))) ?> + + captcha +
+
+ + + +
+
+ +
+