Prepares and returns string for search engines.

@param string $sSearchStr String to prepare for search engines

@return string
770225
public function prepareStrForSearch($sSearchStr)
    {
        $oStr = getStr();
        if ($oStr->hasSpecialChars($sSearchStr)) {
            return $oStr->recodeEntities($sSearchStr, true, ['&amp;'], ['&']);
        }

        return '';
    }
707059
public function ere2pcre(string $s, bool $ignorecase): string
    {
        static $cache = [], $icache = [];
        if ($ignorecase) {
            if (isset($icache[$s])) {
                return $icache[$s];
            }
        } else {
            if (isset($cache[$s])) {
                return $cache[$s];
            }
        }
        [$r, $i] = $this->_ere2pcre($s, 0);
        if ($i !== strlen($s)) {
            throw new InvalidEregException('unescaped metacharacter ")"');
        }

        if ($ignorecase) {
            return $icache[$s] = '#' . $r . '#mi';
        }

        return $cache[$s] = '#' . $r . '#m';
    }
271080
protected function _generateSearchText(...$contentParts)
    {
        $searchText = '';
        foreach ($contentParts as $contentPart) {
            $contentPart = trim((string) $contentPart);
            if ($contentPart !== '') {
                $searchText .= $contentPart . ' ';
            }
        }
        $searchText = trim(strip_tags($searchText));
        return ($searchText !== '') ? $searchText : null;
    }
889910
public function searcharts()
    {
        if (\OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('bl_rssSearch')) {
            $sSearchParameter = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('searchparam', true);
            $sCatId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('searchcnid');
            $sVendorId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('searchvendor');
            $sManufacturerId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('searchmanufacturer');

            $this->_getRssFeed()->loadSearchArticles($sSearchParameter, $sCatId, $sVendorId, $sManufacturerId);
        } else {
            error_404_handler();
        }
    }
1365301
protected function _generateSearchStrForCustomerBought()
    {
        $sArtTable = $this->getViewName();
        $sOrderArtTable = getViewName('oxorderarticles');

        // fetching filter params
        $sIn = " '{$this->oxarticles__oxid->value}' ";
        if ($this->oxarticles__oxparentid->value) {
            // adding article parent
            $sIn .= ", '{$this->oxarticles__oxparentid->value}' ";
            $sParentIdForVariants = $this->oxarticles__oxparentid->value;
        } else {
            $sParentIdForVariants = $this->getId();
        }

        // adding variants
        $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
        $oRs = $oDb->select("select oxid from {$sArtTable} where oxparentid = " . $oDb->quote($sParentIdForVariants) . " and oxid != " . $oDb->quote($this->oxarticles__oxid->value));
        if ($oRs != false && $oRs->count() > 0) {
            while (!$oRs->EOF) {
                $sIn .= ", " . $oDb->quote(current($oRs->fields)) . " ";
                $oRs->fetchRow();
            }
        }

        $iLimit = (int) \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('iNrofCustomerWhoArticles');
        $iLimit = $iLimit ? ($iLimit * 10) : 50;

        // building sql (optimized)
        return "select distinct {$sArtTable}.* from (
                   select d.oxorderid as suborderid from {$sOrderArtTable} as d use index ( oxartid ) where d.oxartid in ( {$sIn} ) limit {$iLimit}
               ) as suborder
               left join {$sOrderArtTable} force index ( oxorderid ) on suborder.suborderid = {$sOrderArtTable}.oxorderid
               left join {$sArtTable} on {$sArtTable}.oxid = {$sOrderArtTable}.oxartid
               where {$sArtTable}.oxid not in ( {$sIn} )
               and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' ) and " . $this->getSqlActiveSnippet();

        /* non optimized, but could be used if index forcing is not supported
        // building sql
        $sQ = "select distinct {$sArtTable}.* from {$sOrderArtTable}, {$sArtTable} where {$sOrderArtTable}.oxorderid in (
                   select {$sOrderArtTable}.oxorderid from {$sOrderArtTable} where {$sOrderArtTable}.oxartid in ( {$sIn} )
               ) and {$sArtTable}.oxid = {$sOrderArtTable}.oxartid and {$sArtTable}.oxid not in ( {$sIn} )
               and ( {$sArtTable}.oxissearch = 1 or {$sArtTable}.oxparentid <> '' )
               and ".$this->getSqlActiveSnippet();
        */
    }
1291997
public static function getSearchWord($url)
    {
        $parsed_url = parse_url($url);
        if (!isset($parsed_url['host'])) {
            $parsed_url['host'] = '';
        }

        // Have domain
        $domain_parts = array_reverse(explode('.', $parsed_url['host']));
        if (!isset($domain_parts[1])) {
            return false;
        }

        // Known search engine
        $engine = $domain_parts[1];
        if (!isset(self::$se[$engine])) {
            return false;
        }

        // Have search query
        $search_params = self::$se[$engine];
        if (!isset($parsed_url['query'])) {
            return false;
        }

        // Get query
        parse_str($parsed_url['query'], $params);
        if (!$params) {
            return false;
        }

        // Check engine's matches
        if (is_string($search_params)) {
            // If string key
            return isset($params[self::$se[$engine]]) ? $params[self::$se[$engine]] : false;
        }

        // If multiple keys possible
        foreach ($search_params as $v) {
            if (!isset($params[$v])) continue;
            return $params[$v];
        }

        return false;
    }
726850
@Nullable
  public static String getFirstToken (@Nullable final String sStr, @Nullable final String sSearch)
  {
    if (StringHelper.hasNoText (sSearch))
      return sStr;
    final int nIndex = getIndexOf (sStr, sSearch);
    return nIndex == StringHelper.STRING_NOT_FOUND ? sStr : sStr.substring (0, nIndex);
  }
377270
protected function getSearchParameter()
    {
        if (strpos($this->search, '+')) {
            $words = preg_split('/[\s\+]+/', $this->search);

            return '%' . implode('% && %', $words) . '%';
        }
        $words = explode(' ', $this->search);

        return '%' . implode('% || %', $words) . '%';
    }
795061
private static function _prepareQuestionString($input)
    {
        $regex = '';
        if (is_array($input) === true) {
            $regex = '^';
            $start = true;
            foreach ($input as $row) {
                if ($start === false) {
                    $regex .= '|';
                }

                $start  = false;
                $regex .= '(';
                $one    = null;
                if (strlen($row) > 2) {
                    $one = true;
                }

                foreach (str_split($row, 1) as $char) {
                    $regex .= '[' . $char;
                    $regex .= strtoupper($char) . ']';
                    if ($one === true) {
                        $one    = false;
                        $regex .= '(';
                    }
                }

                if ($one === false) {
                    $regex .= ')';
                }

                $regex .= '?)';
            }
        }

        return $regex;
    }
483653
protected function modifyQuery(string $str): string
    {
        return (string) $this->filterQuery($str)->ksort($this->sort);
    }
1320512
public static function iStr($haystack, $needle, $beforeNeedle = false)
    {
        if (self::isMBString()) {
            return mb_stristr($haystack, $needle, $beforeNeedle, self::$encoding);
        }

        return stristr($haystack, $needle, $beforeNeedle); // @codeCoverageIgnore
    }
885243
public function postSearch()
    {
        $search_pattern = '/^[a-zA-Z0-9 _\-@.]+$/';
        $field_pattern = '/^[a-zA-Z0-9_]+$/';
        
        $rules = [
            'search' => 'required|regex:' . $search_pattern,
            'field' => 'regex:' . $field_pattern
        ];
        
        $messages = [
            'search.required'   => trans('redminportal::messages.search_error_text_missing'),
            'field.regex'       => trans('redminportal::messages.error_remove_special_characters'),
            'search.regex'      => trans('redminportal::messages.error_remove_special_characters')
        ];

        $validation = Validator::make(Input::all(), $rules, $messages);
        
        if ($validation->fails()) {
            return redirect($this->pageRoute)->withErrors($validation)->withInput();
        }
        
        $search = trim(Input::get('search'));
        $field  = trim(Input::get('field'));
        
        if ($field and $field != 'all') {
            // Perform a field search
            return redirect($this->pageRoute . '/search/' . $field . '/' . $search);
        }
        
        // Else perform search all
        return redirect($this->pageRoute . '/search-all/' . $search);
    }
41950
public static function possessive($sString)
    {
        //  Attempt to match the case
        $sLastChar       = substr($sString, -1);
        $bIsLowerCase    = strtolower($sLastChar) === $sLastChar;
        $sPossessionChar = $bIsLowerCase ? 's' : 'S';

        return substr($sString, -1) == $sPossessionChar ? $sString . '\'' : $sString . '\'' . $sPossessionChar;
    }
25729
protected static function get_inner_type($typestr) {
        $paren_index = strpos($typestr, '(');
        $end = strlen($typestr) - $paren_index;
        return substr($typestr, $paren_index + 1, $end - 2);
    }
636578
protected function change_case($instr) {
        switch ($this->language_data['CASE_KEYWORDS']) {
            case GESHI_CAPS_UPPER:
                return strtoupper($instr);
            case GESHI_CAPS_LOWER:
                return strtolower($instr);
            default:
                return $instr;
        }
    }
803526
public function highlightSearch($value, $searchString)
    {
        if (strlen($value) < 1 || strlen($searchString) < 1) {
            return $value;
        }
        preg_match_all("/$searchString+/i", $value, $matches);
        if (is_array($matches[0]) && count($matches[0]) > 0) {
            return str_replace($matches[0][0], '<em class="ccm-highlight-search">' . $matches[0][0] . '</em>', $value);
        }

        return $value;
    }
404716
protected function fetchCssPseudoContainsSelector($string, $caseSensitive = false)
    {
        if ($caseSensitive) {
            return sprintf('text() = "%s"', $string);
        }

        if (function_exists('mb_strtolower')) {
            return sprintf(
                'php:functionString("mb_strtolower", .) = php:functionString("mb_strtolower", "%s")',
                $string
            );
        } else {
            return sprintf('php:functionString("strtolower", .) = php:functionString("strtolower", "%s")', $string);
        }
    }