eZ\Publish\Core\Persistence\TransformationProcessor::transformByGroup PHP Method

transformByGroup() public method

Transform the given string using a rule group.
public transformByGroup ( string $string, string $ruleGroup ) : string
$string string
$ruleGroup string
return string
    public function transformByGroup($string, $ruleGroup)
    {
        $rules = $this->getRules();
        foreach (array_keys($rules) as $ruleName) {
            if (strpos($ruleName, $ruleGroup) === false) {
                continue;
            }
            foreach ($rules[$ruleName] as $rule) {
                $string = preg_replace_callback($rule['regexp'], $rule['callback'], $string);
            }
        }
        return $string;
    }

Usage Example

 /**
  * Build WordIDArray and update ezsearch_word table.
  *
  * Ported from the legacy code
  *
  * @see https://github.com/ezsystems/ezpublish-legacy/blob/master/kernel/search/plugins/ezsearchengine/ezsearchengine.php#L155
  *
  * @param array $indexArrayOnlyWords words for object to add
  *
  * @return array wordIDArray
  */
 private function buildWordIDArray(array $indexArrayOnlyWords)
 {
     $wordCount = count($indexArrayOnlyWords);
     $wordIDArray = [];
     $wordArray = [];
     // store the words in the index and remember the ID
     $this->dbHandler->beginTransaction();
     for ($arrayCount = 0; $arrayCount < $wordCount; $arrayCount += 500) {
         // Fetch already indexed words from database
         $wordArrayChuck = array_slice($indexArrayOnlyWords, $arrayCount, 500);
         $wordRes = $this->searchIndex->getWords($wordArrayChuck);
         // Build a has of the existing words
         $wordResCount = count($wordRes);
         $existingWordArray = [];
         for ($i = 0; $i < $wordResCount; ++$i) {
             $wordIDArray[] = $wordRes[$i]['id'];
             $existingWordArray[] = $wordRes[$i]['word'];
             $wordArray[$wordRes[$i]['word']] = $wordRes[$i]['id'];
         }
         // Update the object count of existing words by one
         if (count($wordIDArray) > 0) {
             $this->searchIndex->incrementWordObjectCount($wordIDArray);
         }
         // Insert if there is any news words
         $newWordArray = array_diff($wordArrayChuck, $existingWordArray);
         if (count($newWordArray) > 0) {
             $this->searchIndex->addWords($newWordArray);
             $newWordRes = $this->searchIndex->getWords($newWordArray);
             $newWordCount = count($newWordRes);
             for ($i = 0; $i < $newWordCount; ++$i) {
                 $wordLowercase = $this->transformationProcessor->transformByGroup($newWordRes[$i]['word'], 'lowercase');
                 $wordArray[$wordLowercase] = $newWordRes[$i]['id'];
             }
         }
     }
     $this->dbHandler->commit();
     return $wordArray;
 }
All Usage Examples Of eZ\Publish\Core\Persistence\TransformationProcessor::transformByGroup