mirror of
https://github.com/humhub/humhub.git
synced 2025-01-17 22:28:51 +01:00
Added RebuildSearch Job
This commit is contained in:
parent
685ee657af
commit
3f70e9346f
@ -13,10 +13,10 @@ use humhub\modules\admin\components\Controller;
|
||||
use humhub\modules\admin\components\DatabaseInfo;
|
||||
use humhub\modules\admin\libs\HumHubAPI;
|
||||
use humhub\modules\admin\permissions\SeeAdminInformation;
|
||||
use humhub\modules\content\jobs\SearchRebuildIndex;
|
||||
use humhub\modules\queue\driver\MySQL;
|
||||
use humhub\modules\queue\helpers\QueueHelper;
|
||||
use humhub\modules\queue\interfaces\QueueInfoInterface;
|
||||
use humhub\modules\search\jobs\RebuildIndex;
|
||||
use humhub\services\MigrationService;
|
||||
use ReflectionClass;
|
||||
use ReflectionException;
|
||||
@ -108,7 +108,7 @@ class InformationController extends Controller
|
||||
|
||||
$databaseInfo = new DatabaseInfo(Yii::$app->db->dsn);
|
||||
|
||||
$rebuildSearchJob = new RebuildIndex();
|
||||
$rebuildSearchJob = new SearchRebuildIndex();
|
||||
if (Yii::$app->request->isPost && Yii::$app->request->get('rebuildSearch') == 1) {
|
||||
Yii::$app->queue->push($rebuildSearchJob);
|
||||
}
|
||||
|
@ -8,12 +8,13 @@
|
||||
|
||||
namespace humhub\modules\content\commands;
|
||||
|
||||
use humhub\modules\content\jobs\SearchRebuildIndex;
|
||||
use humhub\modules\content\models\Content;
|
||||
use humhub\modules\content\search\driver\AbstractDriver;
|
||||
use humhub\modules\content\search\driver\ZendLucenceDriver;
|
||||
use humhub\modules\content\search\SearchRequest;
|
||||
use humhub\modules\content\services\ContentSearchService;
|
||||
use humhub\modules\search\jobs\RebuildIndex;
|
||||
use humhub\modules\queue\helpers\QueueHelper;
|
||||
use humhub\modules\user\models\User;
|
||||
use Yii;
|
||||
|
||||
@ -55,8 +56,8 @@ class SearchController extends \yii\console\Controller
|
||||
*/
|
||||
public function actionQueueRebuild()
|
||||
{
|
||||
$job = new RebuildIndex();
|
||||
if (\humhub\modules\queue\helpers\QueueHelper::isQueued($job)) {
|
||||
$job = new SearchRebuildIndex();
|
||||
if (QueueHelper::isQueued($job)) {
|
||||
print "Rebuild process is already queued or running!\n";
|
||||
return;
|
||||
}
|
||||
|
35
protected/humhub/modules/content/jobs/SearchRebuildIndex.php
Normal file
35
protected/humhub/modules/content/jobs/SearchRebuildIndex.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2024 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
namespace humhub\modules\content\jobs;
|
||||
|
||||
use humhub\modules\content\models\Content;
|
||||
use humhub\modules\content\services\ContentSearchService;
|
||||
use humhub\modules\queue\interfaces\ExclusiveJobInterface;
|
||||
use humhub\modules\queue\LongRunningActiveJob;
|
||||
|
||||
class SearchRebuildIndex extends LongRunningActiveJob implements ExclusiveJobInterface
|
||||
{
|
||||
/**
|
||||
* @inhertidoc
|
||||
*/
|
||||
public function getExclusiveJobId()
|
||||
{
|
||||
return 'content-search.rebuild-index';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inhertidoc
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
foreach (Content::find()->each() as $content) {
|
||||
(new ContentSearchService($content))->update(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,6 @@ use yii\web\IdentityInterface;
|
||||
|
||||
class SearchRequest extends Model
|
||||
{
|
||||
|
||||
public const ORDER_BY_CREATION_DATE = 'content.created_at';
|
||||
public const ORDER_BY_SCORE = 'score';
|
||||
|
||||
|
@ -53,7 +53,10 @@ class ZendLucenceDriver extends AbstractDriver
|
||||
array_map(function (ContentTag $tag) {
|
||||
return $tag->name;
|
||||
}, $content->tags))));
|
||||
$document->addField(Field::keyword('content.container_id', $content->container->id));
|
||||
|
||||
if ($content->container) {
|
||||
$document->addField(Field::keyword('content.container_id', $content->container->id));
|
||||
}
|
||||
$document->addField(Field::keyword('content.created_at', strtotime($content->created_at)));
|
||||
|
||||
$document->addField(Field::keyword('content.created_by', $content->created_by));
|
||||
|
@ -35,7 +35,7 @@ class ContentSearchService
|
||||
$this->getSearchDriver()->update($this->content);
|
||||
}
|
||||
} else {
|
||||
$this->delete();
|
||||
$this->delete($asActiveJob);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user