Esempio n. 1
0
 public static function highlight($text, $searchString, $class, $overhang = 0)
 {
     // parse string without accesnts and lowercase for searchstring
     $stringArray = array();
     $textArray = explode(" ", $text);
     $retArray = array();
     $pattern = "~{$searchString}~";
     $string = strtolower(OLIVText::remove_accents((string) $text));
     preg_match_all($pattern, $string, $matches, PREG_OFFSET_CAPTURE);
     // split the string
     $start = 0;
     $offset = 0;
     if ($matches) {
         if (count($matches[0])) {
             return $text;
             //TODO solve the problem with the utf8 chars
             /*				foreach ($matches[0] as $match)
             				{
             					$delimitor = "";
             					
             // insert part from previous start
             					$length = $match[1] - $start;
             
             					if ($overhang)
             					{
             						if ($length > $overhang)
             						{
             	// text longer than 2 times the overhang
             	// cut away the rest
             							if ($length > 2*$overhang)
             							{
             								array_push($stringArray,$delimitor . substr((string)$text,$start,$overhang) . "... ");
             
             								$start = $match[1] - $overhang;
             								$length = $overhang;
             								$delimitor = " ...";
             							}
             						}
             					}
             
             					if ($length)
             						array_push($stringArray,$delimitor . substr((string)$text,$start,$length));
             
             // insert hightlighted searchstring
             					$length = strlen($searchString);
             					$start = $match[1];
             
             					if ($length)
             						array_push($stringArray,"{span class='$class'}" . substr((string)$text,$start,$length) . "{/span}");
             
             					$start = $start + $length;
             				}*/
         } else {
             return FALSE;
         }
         // rest of text longer than overhang
         // cut away the rest
         /*			$length = strlen($text) - $start;
         			
         			if ($overhang)
         			{
         				if ($length > $overhang)
         				{
         					$length = $overhang;
         					$delimitor = "...";
         				}
         			}
         
         			array_push($stringArray,substr((string)$text,$start,$length) . $delimitor);
         
         			return implode("",$stringArray);*/
     }
 }
Esempio n. 2
0
 public function insertText($text, $url = "", $lang = "")
 {
     // remove punctuation marks in text
     $text = preg_replace("![\\.\\,\\;\\:\\(\\)\\[\\]\\{\\}\\-\\_\\/]!", " ", strtolower($text));
     // extract words
     $wordArray = explode(" ", $text);
     $wordArray = array_unique($wordArray);
     foreach ($wordArray as $word) {
         //	 		$word = strtolower(Normalizer::normalize($word,Normalizer::FORM_C));
         $word = strtolower($word);
         //TODO replace all special characters with root
         $specialChar = array("ä", "ö");
         $replaceChar = array();
         $word = OLIVText::remove_accents($word);
         //			$this->insertWord($word,$word);
         $suffArray = $this->makeSuffArray($word);
         foreach ($suffArray as $suffix) {
             $this->insertWord($suffix, status::url() . ":" . $url . ":{$lang}:{$word}", $lang);
         }
     }
     global $_INDEX;
     //echoall($_INDEX);
     // write index to disk
     $path = session_path("");
     $name = "index.idx";
     if (file_exists($path)) {
         $fh = fopen($path . $name, "w");
         if ($fh) {
             fwrite($fh, $_INDEX->asXML());
             fclose($fh);
         } else {
             OLIVError::fire("index.php - no write permission");
         }
     } else {
         OLIVError::fire("index.php - directory {$path} don't exist");
     }
 }