27 abstract function delete( $index );
63 abstract function update($index, $page);
84 abstract function search($search, $relation, $query);
104 public function globalSearch($search, $sites = array(), $query = array(), $param = array(), $sort = array(), $filter =
'') {
111 foreach ($sites as $site) {
112 if (is_string($site)) {
113 $site =
new Site($site);
116 $lang = $_REQUEST[
'lang'] ? $_REQUEST[
'lang'] : ($GLOBALS[
'site'] ? $GLOBALS[
'site']->language :
null);
118 $site->setLanguage($lang);
120 }
catch (Exception $e) {
124 foreach ($site->getPages($query, array_merge($param, array(
'fulltext' => $search,
'filter' => $filter))) as $page) {
128 return $this->
sortPages($pages, $query[
'order'], $sort);
150 protected function sortPages($pages, $order =
'', $sort = array()) {
151 if (!empty($order) && preg_match(
'/^([^ ]+) ?(asc|desc)?/i', $order, $match)) {
153 } elseif (!empty($sort)) {
170 $content = str_replace(
',',
' ', $page->getKeywords($page->getSite()->language,
true));
171 if ($page->getSite()->admin[
'keyword_register_own_site']) {
172 $keyword_parents = $page->getParents(array(
173 'fields' =>
'name,extra',
174 'where' =>
"type='_keywords/entry'"
178 foreach ($keyword_parents as $keyword) {
179 $content .=
' '.$keyword->field[
'name'];
182 require_once
'base/Ego_Combo.php';
183 $combo =
new Ego_Combo($keyword->extra[
'synonym']);
184 foreach ($combo->getText() as $text) {
185 $content .=
' '.$text;
194 $content = implode(
' ', $extra);
199 $content = !$page->extra[
'quarantine'] ? $page->field[
'content'] :
'';
202 $content .=
' ' . (is_array($page->extra[
'_contents'])
208 return trim(strip_tags(implode(
' ', $value)));
211 $page->extra[
'_contents'],
214 preg_match(
'/^(index\.php\?|https?:\/\/|[^@ ]+@[^ ]+|\d{4}-\d{2}-\d{2}|\d{2}:\d{2}:?)/si', $value)
215 || preg_match(
'/^\{.*?\}$/si', $value)
220 $value = preg_replace(
'/(\r\n|\r|\n)/s',
' ', $value);
231 if ($page->getSite()->admin[
'mediapool'][
'active']) {
232 $files = $page->getMediapool()->list();
233 foreach ($files as $file) {
234 if (($file[
'nav_hide']&1) === 0) {
236 if (!$file[
'quarantine'] && !$file[
'isImage'] && !$file[
'isVideo'] && !$file[
'isArchive']) {
237 if (method_exists($this,
'indexFile')) {
239 $file_content = $this->indexFile($page, $file[
'file']);
240 }
else if ($GLOBALS[
'egotec_conf'][
'openoffice'][
'active']) {
242 require_once
'openoffice/converter.php';
243 $file_content = convert_content($file[
'file'], $file[
'suffix'], $file[
'mime']);
246 $content .=
' ' . implode(
' ', array_filter([
249 strip_tags($file[
'description']),
268 $content = $page->field[$k];
286 $content = preg_replace(
'/(?<!\d)(0|1)(?!\d)/',
'', $content);
301 in_array($k, array(
'short',
'content',
'extra'))
302 && is_string($content)
303 && preg_match_all(
'/(title|alt)=(["\'])(.*?)\\2/ims', $content, $matches)
306 foreach ($matches[3] as $match) {
307 $content .=
" $match";
311 $content = preg_replace(
'/index\.php\?[^ \'"]+/',
'', $content);
312 $content = preg_replace(
'/<[^>]*>/',
' ', $content);
313 $content = preg_replace(
'/&[^ ;]+;/',
' ', $content);
314 $content = preg_replace(
'/\s+/',
' ', $content);
315 $content = strtr($content,
"\"\n\r\t",
' ');
316 return trim($content);
326 $extra = $page->extra;
327 if (!is_array($extra)) {
331 if (isset($extra[
'mediapool']) && stristr(json_encode($extra[
'mediapool']),
'"quarantine"')) {
332 $extra[
'quarantine'] = 1;
337 $extra[
'language_link'],
338 $extra[
'language_standard'],
339 $extra[
'origImgWidth'],
340 $extra[
'origImgHeight'],
341 $extra[
'origFileSize'],
343 $extra[
'clone_original'],
352 $site = $page->getSite();
353 if ($file = $site->getSiteFile(
'admin/search_index.php')) {
355 $extra = search_index($page, $extra);
359 if (isset($extra[
'workflow_reminder'][
'r_date'])) {
360 $extra[
'workflow_reminder'][
'r_date'] = strtotime($extra[
'workflow_reminder'][
'r_date']);
394 foreach (preg_split(
'/\s+(and|or)\s+/si', $query) as $sub_query) {
395 if (preg_match(
'/(!?extra\.[^ !=<>]+)(\s*(!=|=)\s*(.*?))?$/si', trim($sub_query,
'() '), $matches)) {
396 $param = $matches[1];
397 $operator = mb_strtolower($matches[3]);
398 $value = trim($matches[4],
'\'"');
399 if (is_numeric($value)) {
400 $value = (int) $value;
403 // Wert darf nicht im Extrafeld gesetzt sein
405 if ($param[0] == '!') {
407 $param = substr($param, 1);
410 if (!in_array($GLOBALS['egotec_conf']['search_engine'], ['lucene', 'elastic'])) {
411 $param = substr($param, 6);
414 // Für die Extra Suche mit den SQL Treibern gibt es keine Binds
415 if (is_array($bind) && strpos($value, ':') === 0 && isset($bind[substr($value, 1)])) {
416 $value = $bind[substr($value, 1)];
421 $replace = "extra NOT LIKE
'%s:" . strlen($param) . ":" . $param . ";%'";
423 // SQL Syntax schreiben
425 if (is_string($value)) {
426 $value = "'%s:" . strlen($param) . ":\"" . $param . "\";s:" . strlen($value) . ":\"" . $value . "\"%'";
428 $value = "'%s:" . strlen($param) . ":\"" . $param . "\";_:" . $value . "%'";
434 $replace .= "LIKE $value
";
437 $replace .= "NOT LIKE $value
";
440 $replace .= "LIKE $value
";
444 $sql_query = str_replace($matches[0], $replace, $sql_query);
448 $this->extraQuery = $sql_query;
460 protected function prepareSearch($search, $filter = '', $original = false, $fuzzy = false) {
461 $search = mb_strtolower(trim($search));
462 foreach (array('+', '-', '~', '&') as $char) {
463 // Diese Zeichen dürfen nicht mehrmals nacheinander vorkommen
464 $search = preg_replace('/[' . $char . ']{2,}/', $char, $search);
466 // Andere Lucene Query Zeichen escapen
467 $search = preg_replace('%([\|!(){}[\]^*?:/]+)%', '\\\\$1', $search);
469 // Hotfix: Punkt am Ende funktioniert nicht
470 $search = rtrim($search, '.');
472 $search_asterix = ''; // Die Suche mit * erweitern
473 $search_fuzzy = ''; // Die Suche mit ~ erweitern
478 // Fuzzy Einstellung setzen
480 if ($GLOBALS['egotec_conf']['search']['fuzzy_num']) {
481 $fuzzy_num = $GLOBALS['egotec_conf']['search']['fuzzy_num'];
484 for ($i = 0; $i < strlen($search); $i++) {
485 $character = $search[$i];
486 switch ($character) {
488 if ($in_string == '"') {
493 $search_asterix .= $character;
494 $search_fuzzy .= $character;
496 $search_fuzzy .= '~
' . $fuzzy_num;
504 && !in_array(substr($search_asterix, -1), array('"', '*'))
506 $search_asterix .= '*';
507 $search_fuzzy .= '~' . $fuzzy_num;
509 $search_asterix .= $character;
510 $search_fuzzy .= $character;
511 $in_word = $in_fuzzy = '';
514 // Suche mit Bindestrichen ermöglichen
515 if ($search_asterix != '' && substr($search_asterix, -1) != ' ') {
516 $search_asterix .= ' '; // @TODO Workaround, nicht die Lösung.
518 $search_asterix .= $character;
522 // Suche mit Tilde (Fuzzy Search)
523 $search_asterix = substr_replace($search_asterix, '', strrpos($search_asterix, '*'), 1);
524 $search_asterix .= $character;
525 $search_fuzzy .= $character;
526 $in_fuzzy = $character;
529 if ($this->config['leading_wildcard'] && !$in_word) {
530 // Asterix vor einem Wort
531 if (!$in_string && !in_array($character, array('+', '-', '*')) && $search_asterix[strlen($search_asterix) - 1] != '-') {
532 $search_asterix .= '*';
534 $in_word = $character;
536 $search_asterix .= $character;
537 $search_fuzzy .= $character;
540 if ($character != '"' && !$in_fuzzy) {
541 if ($character != '*
') {
542 // Am Ende noch einen Asterix hinzufügen
543 $search_asterix .= '*
';
545 if ($search_asterix != '*
' && $character != '~
') {
546 // Am Ende noch eine Tilde hinzufügen
547 $search_fuzzy .= '~
' . $fuzzy_num;
551 $search_string = $search_asterix;
553 $search_string .= " $search_fuzzy";
557 // Lucene Filter hinzufügen
558 if (is_string($filter) && !empty($filter)) {
559 if ($search_string == '*
') {
560 $search_string = $filter;
562 $search_string = "($search_string) AND ($filter)";
566 // Zusätzlicher Query für die Extra Suche
567 if (!empty($this->extraQuery)) {
568 if ($search_string == '*
') {
569 $search_string = $this->extraQuery;
571 $search_string = "($search_string) AND ({$this->extraQuery})";
575 // Ausrufezeichen maskieren
576 $search_string = str_replace('!
', '\!
', $search_string);
579 return $search_string;
585 function clearCache() {
595 protected function checkSearch($search) {
596 $maxlength = $GLOBALS['egotec_conf
']['search']['maxlength
']
597 ? $GLOBALS['egotec_conf
']['search']['maxlength
']
599 if (mb_strlen($search) > $maxlength) {
600 Ego_System::header(400);
614 public function getSuggestions($query, $sites = [], $max = 5) {
627 public function getCorrections($query, $sites = [], $max = 3) {
sortPages($pages, $order='', $sort=array())
_getExtra($page, $clean=false)
setExtraQuery($query, $bind=array())
filterContent($content, $k='extra')
globalSearch($search, $sites=array(), $query=array(), $param=array(), $sort=array(), $filter='')
search($search, $relation, $query)
static sortPages($pages, $sorttype='field', $sortby='id', $sortdirection="asc")
static arrayFlatRecursive($array, $callback=null)
static getAllSites($username='', $perm='', $table=false, $type='')
static arrayValuesRecursive($array)