openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 69d996660296b62f06852c6b9bf069b5df3cfc87
parent 7ed0aa11a70ac02e00fdcf3f9965d9287238b77e
Author: Jan Dankert <devnull@localhost>
Date:   Thu, 13 Dec 2018 22:07:24 +0100

Suchindex aufräumen, Suchfelder nach 300 Zeichen abschneiden.

Diffstat:
modules/cms-macros/macro/SearchIndex.class.php | 20++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/modules/cms-macros/macro/SearchIndex.class.php b/modules/cms-macros/macro/SearchIndex.class.php @@ -15,10 +15,13 @@ class SearchIndex extends Macro { /** * Beschreibung dieser Klasse + * * @type String */ var $description = ''; + public $maxLength = 300; + /** * Creates a search index for alle pages in the current project. @@ -52,14 +55,14 @@ class SearchIndex extends Macro 'title' => $name->name, 'filename'=> $page->filename, 'url' => $this->page->path_to_object( $pageid ), - 'content' => array_reduce( + 'content' => $this->truncate(array_reduce( $page->values, function($act, $value) { return $act.' '.$value->value; }, '' - ) + )) ); } } @@ -69,4 +72,17 @@ class SearchIndex extends Macro $this->output( $json->encode( $searchIndex ) ); } + + private function truncate( $text) { + $text = str_replace('&quot;','',$text); + $text = str_replace('&lt;' ,'',$text); + $text = str_replace('&rt;' ,'',$text); + $text = strtr($text,';,:.\'"',' '); + $text = strtr($text,' ',' '); + if ( strlen($text) > $this->maxLength ) + $text = mb_substr($text,0,$this->maxLength,'UTF-8'); + + return $text; + } + } \ No newline at end of file