files/collections: more robust sphinxsearch reindexing; add reindex command to tools/cli
This commit is contained in:
parent
d40756540c
commit
e97634b7bf
@ -320,13 +320,14 @@ function wff_reindex(): void {
|
|||||||
$q = $db->query("SELECT * FROM wff_collection");
|
$q = $db->query("SELECT * FROM wff_collection");
|
||||||
while ($row = $db->fetch($q)) {
|
while ($row = $db->fetch($q)) {
|
||||||
$item = new WFFCollectionItem($row);
|
$item = new WFFCollectionItem($row);
|
||||||
|
$text = '';
|
||||||
if ($item->isFile()) {
|
if ($item->isFile()) {
|
||||||
$txt = file_get_contents('/home/user/nsa/txt/'.str_replace('.pdf', '.txt', basename($item->path)));
|
$text_q = $db->query("SELECT text FROM wff_texts WHERE wff_id=?", $item->id);
|
||||||
} else {
|
if ($db->numRows($text_q))
|
||||||
$txt = '';
|
$text = $db->result($text_q);
|
||||||
}
|
}
|
||||||
sphinx_execute("INSERT INTO ".WFF_ARCHIVE_SPHINX_RTINDEX." (id, document_id, title, text, is_folder, parent_id) VALUES (?, ?, ?, ?, ?, ?)",
|
sphinx_execute("INSERT INTO ".WFF_ARCHIVE_SPHINX_RTINDEX." (id, document_id, title, text, is_folder, parent_id) VALUES (?, ?, ?, ?, ?, ?)",
|
||||||
$item->id, $item->getDocumentId(), $item->title, $txt, (int)$item->isFolder(), $item->parentId);
|
$item->id, $item->getDocumentId(), $item->title, $text, (int)$item->isFolder(), $item->parentId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -585,7 +586,10 @@ function baconiana_reindex(): void {
|
|||||||
$db = DB();
|
$db = DB();
|
||||||
$baconiana = baconiana_get(null);
|
$baconiana = baconiana_get(null);
|
||||||
foreach ($baconiana as $item) {
|
foreach ($baconiana as $item) {
|
||||||
$text = $db->result($db->query("SELECT text FROM baconiana_texts WHERE bcn_id=?", $item->id));
|
$text_q = $db->query("SELECT text FROM baconiana_texts WHERE bcn_id=?", $item->id);
|
||||||
|
if (!$db->numRows($text_q))
|
||||||
|
continue;
|
||||||
|
$text = $db->result($text_q);
|
||||||
sphinx_execute("INSERT INTO ".BACONIANA_ARCHIVE_SPHINX_RTINDEX." (id, title, year, text) VALUES (?, ?, ?, ?)",
|
sphinx_execute("INSERT INTO ".BACONIANA_ARCHIVE_SPHINX_RTINDEX." (id, title, year, text) VALUES (?, ?, ?, ?)",
|
||||||
$item->id, "$item->year ($item->issues)", $item->year, $text);
|
$item->id, "$item->year ($item->issues)", $item->year, $text);
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@ function file(SkinContext $ctx,
|
|||||||
FilesItemInterface $file,
|
FilesItemInterface $file,
|
||||||
?SkinString $unsafe_query = null,
|
?SkinString $unsafe_query = null,
|
||||||
bool $disabled = false,
|
bool $disabled = false,
|
||||||
?array $text_excerpts = null,) {
|
?array $text_excerpts = null) {
|
||||||
$icons = svg();
|
$icons = svg();
|
||||||
if ($file instanceof BookItem && $file->fileType == BookFileType::BOOK)
|
if ($file instanceof BookItem && $file->fileType == BookFileType::BOOK)
|
||||||
$icon = $icons->book_20();
|
$icon = $icons->book_20();
|
||||||
|
@ -79,6 +79,17 @@ require_once 'lib/admin.php';
|
|||||||
echo "upload id: $id\n";
|
echo "upload id: $id\n";
|
||||||
})
|
})
|
||||||
|
|
||||||
|
->on('collection-reindex', function() {
|
||||||
|
require_once 'lib/files.php';
|
||||||
|
$collections = array_map(fn($c) => $c->value, FilesCollection::cases());
|
||||||
|
$s = cli::input('Enter collection to reindex (variants: '.implode(', ', $collections).': ');
|
||||||
|
$c = FilesCollection::from($s);
|
||||||
|
$f = "{$s}_reindex";
|
||||||
|
echo "calling $f()... ";
|
||||||
|
call_user_func($f);
|
||||||
|
echo "done\n";
|
||||||
|
})
|
||||||
|
|
||||||
->run();
|
->run();
|
||||||
|
|
||||||
function _get_admin_login_password_input(): array {
|
function _get_admin_login_password_input(): array {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user