Пример #1
0
 public function articleAction()
 {
     $posts = new PostIterator();
     $esUtil = new ElasticsearchUtil();
     foreach ($posts as $postArr) {
         foreach ($postArr as $_k => $post) {
             $post['content'] = strip_tags($post['content']);
             $post['summary'] = strip_tags($post['summary']);
             $ret = $esUtil->index('wallstreetcn', 'article', $post, $post['id']);
             $this->output->writeln('<comment>[INFO]</comment> ' . date('Y-m-d H:i') . '  <comment>Response:</comment>  ' . json_encode($ret));
             unset($post);
         }
     }
 }
Пример #2
0
 public function afterSave($event, Post $post)
 {
     if (!$post->id) {
         return;
     }
     $postArr = $post->toArray();
     $postArr['tagNames'] = $post->getTagString();
     $categoryIds = '';
     $postArr['content'] = strip_tags($post->text->content);
     $postArr['summary'] = strip_tags($post->summary);
     if ($post->categories) {
         foreach ($post->categories as $category) {
             if ($categoryIds != '') {
                 $categoryIds .= ',';
             }
             $categoryIds .= $category->id;
         }
     }
     $postArr['categoryIds'] = $categoryIds;
     $postArr['upVote'] = $postArr['upVote'] ? $postArr['upVote'] : 0;
     $es = new ElasticsearchUtil();
     $es->index('wallstreetcn', 'article', $postArr, $post->id);
     //        (json_encode($post->categories));
 }