Browse Source

implement reindex by request feature

main
yggverse 8 months ago
parent
commit
fef2b1abec
  1. 3
      README.md
  2. 3
      composer.json
  3. 4
      example/config.json
  4. 4
      src/cli/document/crawl.php
  5. 4
      src/cli/index/init.php
  6. 85
      src/webui/explore.php

3
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) * [Symfony CSS selector](https://github.com/symfony/css-selector)
* [FTP client for snap mirrors](https://github.com/YGGverse/ftp-php) * [FTP client for snap mirrors](https://github.com/YGGverse/ftp-php)
* [Hostname ident icons](https://github.com/dmester/jdenticon-php) * [Hostname ident icons](https://github.com/dmester/jdenticon-php)
* [Captcha](https://github.com/Gregwar/Captcha)
* [Bootstrap icons](https://icons.getbootstrap.com/) * [Bootstrap icons](https://icons.getbootstrap.com/)
### Install ### 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` * `wget https://repo.manticoresearch.com/manticore-repo.noarch.deb`
* `dpkg -i manticore-repo.noarch.deb` * `dpkg -i manticore-repo.noarch.deb`
* `apt update` * `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, 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` change default [binlog flush strategy](https://manual.manticoresearch.com/Logging/Binary_logging#Binary-flushing-strategies) to `binlog_flush = 1`

3
composer.json

@ -18,6 +18,7 @@
"symfony/css-selector": "^6.3", "symfony/css-selector": "^6.3",
"symfony/dom-crawler": "^6.3", "symfony/dom-crawler": "^6.3",
"jdenticon/jdenticon": "^1.0", "jdenticon/jdenticon": "^1.0",
"yggverse/ftp": "^1.0" "yggverse/ftp": "^1.0",
"gregwar/captcha": "^1.2"
} }
} }

4
example/config.json

@ -121,6 +121,10 @@
"index":[] "index":[]
} }
] ]
},
"reindex":
{
"enabled":true
} }
}, },
"cli": "cli":

4
src/cli/document/crawl.php

@ -87,6 +87,7 @@ if ($config->cli->document->crawl->debug->level->notice)
foreach($index->search('') foreach($index->search('')
->expression('random', 'rand()') ->expression('random', 'rand()')
->sort('reindex', 'desc')
->sort('time', 'asc') ->sort('time', 'asc')
->sort('rank', 'asc') ->sort('rank', 'asc')
->sort('random', 'asc') ->sort('random', 'asc')
@ -106,7 +107,8 @@ foreach($index->search('')
'size' => $document->get('size'), 'size' => $document->get('size'),
'mime' => $document->get('mime'), 'mime' => $document->get('mime'),
'rank' => $document->get('rank'), 'rank' => $document->get('rank'),
'time' => $time 'time' => $time,
'reindex' => 0
]; ];
// Debug target // Debug target

4
src/cli/index/init.php

@ -85,6 +85,10 @@ $result = $index->create(
'type' => 'integer' 'type' => 'integer'
], ],
'time' => 'time' =>
[
'type' => 'integer'
],
'reindex' =>
[ [
'type' => 'integer' 'type' => 'integer'
] ]

85
src/webui/explore.php

@ -77,7 +77,9 @@ $icon = $identicon->getImageDataUri('webp');
$snaps = []; $snaps = [];
/// Prepare location /// Prepare location
$md5url = md5($document->url); $md5url = md5(
$document->url
);
$filepath = implode( $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();
}
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
@ -275,9 +299,13 @@ foreach ($config->snap->storage->remote->ftp as $i => $ftp)
text-align: center; text-align: center;
} }
input, fieldset {
input:-webkit-autofill, width: 150px;
input:-webkit-autofill:focus { }
input[type="text"],
input[type="text"]:-webkit-autofill,
input[type="text"]:-webkit-autofill:focus {
transition: background-color 0s 600000s, color 0s 600000s; /* chrome */ transition: background-color 0s 600000s, color 0s 600000s; /* chrome */
width: 100%; width: 100%;
margin: 12px 0; margin: 12px 0;
@ -289,16 +317,16 @@ foreach ($config->snap->storage->remote->ftp as $i => $ftp)
text-align: center; text-align: center;
} }
input:hover { input[type="text"]:hover {
background-color: #111 background-color: #111
} }
input:focus { input[type="text"]:focus {
outline: none; outline: none;
background-color: #111 background-color: #111
} }
input:focus::placeholder { input[type="text"]:focus::placeholder {
color: #090808 color: #090808
} }
@ -321,13 +349,18 @@ foreach ($config->snap->storage->remote->ftp as $i => $ftp)
background-color: #3394fb; background-color: #3394fb;
color: #fff; color: #fff;
font-size: 14px; font-size: 14px;
position: fixed;
top: 12px;
right: 24px;
} }
button:hover { button {
background-color: #4b9df4; background-color: #4b9df4;
height: 32px;
vertical-align: top;
}
header button {
position: fixed;
top: 12px;
right: 24px;
} }
a, a:visited, a:active { a, a:visited, a:active {
@ -455,6 +488,36 @@ foreach ($config->snap->storage->remote->ftp as $i => $ftp)
<h3><?php echo _('Cache') ?></h3> <h3><?php echo _('Cache') ?></h3>
<pre><?php echo htmlentities($document->body) ?></pre> <pre><?php echo htmlentities($document->body) ?></pre>
<?php } ?> <?php } ?>
<?php if ($config->webui->reindex->enabled) { ?>
<h3><?php echo _('Reindex') ?></h3>
<div>
<?php if ($document->get('reindex')) { ?>
<?php echo sprintf(_('Request sent at %s'), date('c', $document->get('reindex'))) ?>
<?php } else { ?>
<img src="<?php echo $captcha->inline(100) ?>" alt="captcha" />
<form name="reindex" method="POST" action="explore.php?i=<?php echo $document->getId() ?>">
<fieldset>
<input type="text"
name="captcha"
value=""
placeholder="<?php echo _('Code on picture'); ?>"
autocomplete="off" />
<button type="submit">
<?php echo _('Request') ?>
</button>
<button type="submit">
<sub>
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="white" viewBox="0 0 16 16">
<path d="M11.534 7h3.932a.25.25 0 0 1 .192.41l-1.966 2.36a.25.25 0 0 1-.384 0l-1.966-2.36a.25.25 0 0 1 .192-.41m-11 2h3.932a.25.25 0 0 0 .192-.41L2.692 6.23a.25.25 0 0 0-.384 0L.342 8.59A.25.25 0 0 0 .534 9"/>
<path fill-rule="evenodd" d="M8 3c-1.552 0-2.94.707-3.857 1.818a.5.5 0 1 1-.771-.636A6.002 6.002 0 0 1 13.917 7H12.9A5 5 0 0 0 8 3M3.1 9a5.002 5.002 0 0 0 8.757 2.182.5.5 0 1 1 .771.636A6.002 6.002 0 0 1 2.083 9z"/>
</svg>
</sub>
</button>
</fieldset>
</form>
<?php } ?>
</div>
<?php } ?>
</div> </div>
<?php } else { ?> <?php } else { ?>
<div> <div>

Loading…
Cancel
Save