Индексирование всех постов и комментариев из CLI
parent
b22ca8ca90
commit
e0baa197bf
|
@ -58,6 +58,14 @@ php-fpm
|
|||
|
||||
vagga _load_fixture my/patches/31337_info.sql
|
||||
|
||||
ElasticSearch
|
||||
-------------
|
||||
|
||||
```bash
|
||||
docker-compose exec app php /app/engine/console/ls.php reindex topics
|
||||
docker-compose exec app php /app/engine/console/ls.php reindex comments
|
||||
```
|
||||
|
||||
Фикстуры
|
||||
--------
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use Predis\Connection\ConnectionException;
|
|||
class Reindex extends LSC
|
||||
{
|
||||
private $celeryClient;
|
||||
private $databaseHandler;
|
||||
private $oDb;
|
||||
private $sIndex;
|
||||
private $sComment;
|
||||
private $sTopic;
|
||||
|
@ -25,21 +25,13 @@ class Reindex extends LSC
|
|||
);
|
||||
} catch (ConnectionException $exc) {
|
||||
echo $exc->getMessage();
|
||||
exit();
|
||||
}
|
||||
try {
|
||||
$this->databaseHandler = new PDO(
|
||||
sprintf(
|
||||
"%s:host=%s;port=%d;dbname=%s",
|
||||
Config::Get("db.params.type"),
|
||||
Config::Get("db.params.host"),
|
||||
Config::Get("db.params.port"),
|
||||
Config::Get("db.params.dbname")
|
||||
),
|
||||
Config::Get("db.params.user"),
|
||||
Config::Get("db.params.pass")
|
||||
);
|
||||
} catch (PDOException $exc) {
|
||||
$this->oDb = Engine::getInstance()->Database_GetConnect();
|
||||
} catch (Exception $exc) {
|
||||
echo $exc->getMessage();
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->sIndex = Config::Get('module.search.index');
|
||||
|
@ -73,20 +65,31 @@ class Reindex extends LSC
|
|||
ls_topic.topic_id = ls_topic_content.topic_id
|
||||
";
|
||||
|
||||
$statement = $this->databaseHandler->prepare($sql, [PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY]);
|
||||
$statement->execute();
|
||||
|
||||
while ($row = $statement->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT)) {
|
||||
$this->celeryClient->PostTask(
|
||||
'tasks.topic_index',
|
||||
array_merge(
|
||||
$topics = $this->oDb->select($sql);
|
||||
if(is_array($topics) && count($topics)) {
|
||||
// Очистка всех топиков в ElasticSearch
|
||||
// TODO: Очистка всех топиков
|
||||
// Маппинг
|
||||
// TODO: Маппинг
|
||||
// Добавление постов в ElasticSearch
|
||||
foreach ($topics as $topic) {
|
||||
$this->celeryClient->PostTask(
|
||||
'tasks.topic_index',
|
||||
[
|
||||
'index' => $this->sIndex,
|
||||
'key' => $this->sTopic
|
||||
],
|
||||
$row
|
||||
)
|
||||
);
|
||||
'key' => $this->sTopic,
|
||||
'topic_id' => $topic['topic_id'],
|
||||
'topic_blog_id' => $topic['topic_blog_id'],
|
||||
'topic_user_id' => $topic['topic_user_id'],
|
||||
'topic_type' => $topic['topic_type'],
|
||||
'topic_title' => $topic['topic_title'],
|
||||
'topic_text' => $topic['topic_text'],
|
||||
'topic_tags' => $topic['topic_tags'],
|
||||
'topic_date' => $topic['topic_date'],
|
||||
'topic_publish' => $topic['topic_publish']
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,6 +99,7 @@ class Reindex extends LSC
|
|||
SELECT
|
||||
comment_id,
|
||||
target_id AS comment_target_id,
|
||||
target_parent_id AS comment_blog_id,
|
||||
target_type AS comment_target_type,
|
||||
user_id AS comment_user_id,
|
||||
comment_text,
|
||||
|
@ -105,21 +109,30 @@ class Reindex extends LSC
|
|||
ls_comment
|
||||
";
|
||||
|
||||
$statement = $this->databaseHandler->prepare($sql, [PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY]);
|
||||
$statement->execute();
|
||||
|
||||
while ($row = $statement->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT)) {
|
||||
$this->celeryClient->PostTask(
|
||||
'tasks.comment_index',
|
||||
array_merge(
|
||||
$comments = $this->oDb->select($sql);
|
||||
if(is_array($comments) && count($comments)) {
|
||||
// Очистка всех комментариев в ElasticSearch
|
||||
// TODO: Очистка всех комментариев
|
||||
// Маппинг
|
||||
// TODO: Маппинг
|
||||
// Добавление комментариев в ElasticSearch
|
||||
foreach ($comments as $comment) {
|
||||
$this->celeryClient->PostTask(
|
||||
'tasks.comment_index',
|
||||
[
|
||||
'index' => $this->sIndex,
|
||||
'key' => $this->sTopic
|
||||
],
|
||||
$row
|
||||
)
|
||||
);
|
||||
var_dump($row);
|
||||
'key' => $this->sComment,
|
||||
'comment_id' => $comment['comment_id'],
|
||||
'comment_target_id' => $comment['comment_target_id'],
|
||||
'comment_blog_id' => $comment['comment_blog_id'],
|
||||
'comment_target_type' => $comment['comment_target_type'],
|
||||
'comment_user_id' => $comment['comment_user_id'],
|
||||
'comment_text' => $comment['comment_text'],
|
||||
'comment_date' => $comment['comment_date'],
|
||||
'comment_publish' => $comment['comment_publish']
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
// Для эмуляции работы, т.к используется в конфиге
|
||||
$_SERVER['HTTP_HOST']='localhost';
|
||||
|
||||
require_once("./../../config/loader.php");
|
||||
require_once(dirname(__FILE__)."/../../settings/loader.php");
|
||||
require_once(Config::Get('path.root.engine')."/classes/Engine.class.php");
|
||||
require_once(dirname(__FILE__).'/lsc.php');
|
||||
|
||||
|
||||
|
|
|
@ -299,8 +299,8 @@ $config['misc']['simplify_comments_pagination'] = false;
|
|||
$config['page']['show_block_structure'] = false;
|
||||
|
||||
// Include configs
|
||||
foreach (glob("settings/parts.d/*") as $file) {
|
||||
$name = explode('.', str_replace('settings/parts.d/', '', $file));
|
||||
foreach (glob(dirname(__FILE__).'/parts.d/*') as $file) {
|
||||
$name = explode('.', str_replace(dirname(__FILE__).'/parts.d/', '', $file));
|
||||
array_pop($name); // Remove extension
|
||||
|
||||
$conf = &$config;
|
||||
|
|
Loading…
Reference in New Issue