增加主动更新标题索引功能

main
落雨楓 2 years ago
parent cec2ca565d
commit a2ec580fef

@ -56,7 +56,7 @@
"ResourceLoaderGetConfigVars": [
"Isekai\\AIToolbox\\Hooks::onResourceLoaderGetConfigVars"
],
"onPageSaveComplete": [
"PageSaveComplete": [
"Isekai\\AIToolbox\\Hooks::onPageSaveComplete"
]
},
@ -64,6 +64,9 @@
"aitoolbox": "Isekai\\AIToolbox\\Api\\ApiAIToolbox",
"aitoolboxbot": "Isekai\\AIToolbox\\Api\\ApiAIToolboxBot"
},
"JobClasses": {
"isekaiAIUpdateTitleIndex": "Isekai\\AIToolbox\\Job\\UpdateTitleIndexJob"
},
"ResourceModules": {
"ext.isekai.ai-toolbox.launcher": {
"scripts": [

@ -39,8 +39,9 @@ class Hooks {
*/
public static function onPageSaveComplete($wikiPage, $user, $summary, $flags, $revisionRecord, $editResult) {
$title = $wikiPage->getTitle();
if ($title && $title->exists() && $title->getNamespace() === NS_MAIN) {
$job = new UpdateTitleIndexJob($wikiPage->getTitle(), []);
if ($title && $title->inNamespace(NS_MAIN)) {
wfDebug('[IsekaiAIToolbox] push UpdateTitleIndexJob');
$job = new UpdateTitleIndexJob($wikiPage->getTitle());
MediaWikiServices::getInstance()->getJobQueueGroup()->push($job);
}
}

@ -6,8 +6,8 @@ use MediaWiki\MediaWikiServices;
use Title;
class UpdateTitleIndexJob extends Job {
public function __construct(Title $title, array $params){
parent::__construct('IsekaiAIUpdateTitleIndex', $title, $params);
public function __construct(Title $title) {
parent::__construct('isekaiAIUpdateTitleIndex', $title);
}
/**
@ -17,20 +17,29 @@ class UpdateTitleIndexJob extends Job {
$services = MediaWikiServices::getInstance();
$config = $services->getMainConfig();
$endpoint = $config->get('wgIsekaiAIBackendEndpoint');
$endpoint = $config->get('IsekaiAIBackendEndpoint');
$authToken = $config->get('IsekaiAIToolboxToken');
$title = $this->title;
$pageTitle = $title->getText();
$factory = MediaWikiServices::getInstance()->getHttpRequestFactory();
$req = $factory->create($endpoint + '/sys/embedding_search/title/update', [
$req = $factory->create($endpoint . '/sys/embedding_search/title/update', [
'method' => 'POST',
'postData' => [
'title' => $pageTitle
],
'timeout' => 10
'timeout' => 20
], __METHOD__);
$req->setHeader('Authorization', 'Bearer ' . $authToken);
$status = \Status::wrap($req->execute());
if(!$status->isOK()){
$this->setLastError($status->getMessage());
return false;
}
return true;
}
}
Loading…
Cancel
Save