EGOCMS  24.0
EGOTEC Content-Managament-System
Ego_Search_Factory.php
gehe zur Dokumentation dieser Datei
1 <?php
15 {
29  static public function start($table = '', $param = [], $checkHealthy = false) {
30  if (empty($table)) {
31  $table = $GLOBALS['site'] ? $GLOBALS['site']->pageTable : '';
32  }
33  switch ($GLOBALS['egotec_conf']['search_engine']) {
34  case 'mysql':
35  require_once('base/Ego_Search_Mysql.php');
36  return new Ego_Search_Mysql($table);
37  case 'simple':
38  require_once('base/Ego_Search_Simple.php');
39  return new Ego_Search_Simple($table);
40  case 'lucene':
41  require_once('base/Ego_Search_Lucene.php');
42  return new Ego_Search_Lucene($table, $param);
43  case 'elastic':
44  require_once('base/Ego_Search_Elastic.php');
45  return new Ego_Search_Elastic($table, $param, $checkHealthy);
46  case 'sql':
47  default:
48  require_once('base/Ego_Search_Sql.php');
49  return new Ego_Search_Sql($table);
50  }
51  }
52 
62  public static function updateIndex($sites = [], $lang = '', $output = true) {
63  $db = new_db_connection();
64  if (empty($sites)) {
65  $sites = Ego_System::getAllSites();
66  }
67  foreach ($sites as $site) {
68  if ($lang) {
69  $langs = [$lang];
70  } else {
71  $langs = $site->getLanguages();
72  }
73  foreach ($langs as $l) {
74  $site->setLanguage($l);
75  $site->clearCache();
76  if ($output) {
77  Ego_System::flush("<br/>\nBearbeite Mandant '" . $site->name . "' mit Sprache '$l'");
78  }
79 
80  $search_engine = self::start($site->pageTable);
81  if (!$_REQUEST['start']) {
82  if ($output) {
83  Ego_System::flush("<br/>\nVolltextindex komplett löschen!\n\n");
84  }
85  $search_engine->reset();
86  }
87 
88  $query = [];
89  if ($_REQUEST['limit']) {
90  $query['limit'] = $_REQUEST['start'] . ',' . $_REQUEST['limit'];
91  $query['order'] = 'id ASC';
92  }
93  $pages = $site->getPages(
94  $query,
95  ['no_cache' => 1]
96  );
97  $next = false; // Ein weiteres Update nur durchführen,
98  $bulk_pages = [];
99 
100  $search = Ego_Search_Factory::start($site->pageTable);
101 
102 
103  foreach ($pages as $page) {
104  set_time_limit(0);
105  if ($output) {
106  Ego_System::flush("<br/>\n" . $page->field['id']);
107  }
108 
109  if ($GLOBALS['egotec_conf']['search_engine'] == 'elastic') {
110  $bulk_pages[] = $page;
111  if (sizeof($bulk_pages) == 20) {
112  $search->updateBulk($bulk_pages, false);
113  $bulk_pages = [];
114  }
115  } else {
116  $page->updateIndex($search_engine, false, false);
117  $next = true; // wenn es noch Seiten für das Update gibt
118  }
119  }
120 
121  if ($GLOBALS['egotec_conf']['search_engine'] == 'elastic' && sizeof($bulk_pages) > 0) {
122  $search->updateBulk($bulk_pages, false);
123  }
124 
125  if (!in_array($GLOBALS['egotec_conf']['search_engine'], ['lucene', 'elastic'])) {
126  if ($output) {
127  Ego_System::flush("<br/>\nVolltexttabelle optimieren!\n\n");
128  }
129  $db->optimize($site->name . '_' . $l . '_fulltext');
130  }
131 
132  if ($_REQUEST['auto'] && $next && !$_REQUEST['allsites']) {
133  $request_uri = str_replace('start=' . $_REQUEST['start'], 'start=' . ($_REQUEST['start'] + $_REQUEST['limit']), $_SERVER['REQUEST_URI']);
134  if ($output) {
135  Ego_System::flush("<script type=\"text/javascript\">document.location.href = \"" . $request_uri . "\";</script>");
136  }
137  } elseif ($output) {
138  Ego_System::flush("\n\n<br>Fertig!<br/><hr/>\n");
139  }
140  $site->clearCache();
141  }
142  }
143  }
144 }
145 
146 ?>
static updateIndex($sites=[], $lang='', $output=true)
static start($table='', $param=[], $checkHealthy=false)
static getAllSites($username='', $perm='', $table=false, $type='')
static flush($string='')
Definition: Ego_System.php:934