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