RebuildIndex.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * This file is part of the ForkBB <https://github.com/forkbb>.
  4. *
  5. * @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
  6. * @license The MIT License (MIT)
  7. */
  8. declare(strict_types=1);
  9. namespace ForkBB\Models\Post;
  10. use ForkBB\Models\Action;
  11. use ForkBB\Models\Topic\Topic;
  12. class RebuildIndex extends Action
  13. {
  14. /**
  15. * Перестройка поискового индекса
  16. */
  17. public function rebuildIndex(int $start, int $limit, string $mode): int
  18. {
  19. $vars = [
  20. ':start' => $start,
  21. ':limit' => $limit,
  22. ];
  23. $query = 'SELECT p.id, p.message, t.id as topic_id, t.subject, t.first_post_id, t.forum_id
  24. FROM ::posts AS p
  25. INNER JOIN ::topics AS t ON t.id=p.topic_id
  26. WHERE p.id>=?i:start
  27. ORDER BY p.id ASC
  28. LIMIT ?i:limit';
  29. $stmt = $this->c->DB->query($query, $vars);
  30. $number = 0;
  31. while ($row = $stmt->fetch()) {
  32. $number = $row['id'];
  33. $post = $this->manager->create([
  34. 'id' => $row['id'],
  35. 'message' => $row['message'],
  36. 'topic_id' => $row['topic_id'],
  37. ]);
  38. if (! $this->c->topics->get($row['topic_id']) instanceof Topic) {
  39. $topic = $this->c->topics->create([
  40. 'id' => $row['topic_id'],
  41. 'subject' => $row['subject'],
  42. 'first_post_id' => $row['first_post_id'],
  43. 'forum_id' => $row['forum_id'],
  44. ]);
  45. $this->c->topics->set($topic->id, $topic);
  46. }
  47. //????????????????????????????????????
  48. $this->c->Parser->parseMessage($row['message']);
  49. $this->c->search->index($post, $mode);
  50. }
  51. return $number;
  52. }
  53. }