Coroico / AdvSearch

Dynamic content search add-on for MODx Revolution that supports results highlighting, faceted search and search in custom packages
21 stars 14 forks source link

Empty search string Error #26

Closed Coroico closed 11 years ago

Coroico commented 12 years ago

Warning: mb_strpos() [function.mb-strpos]: Offset not contained in string in ..../core/components/advsearch/model/advsearch/advsearch.class.php on line 702

This warning occurs inside the getExtracts() function inside the advSearch.class.php file:

        if (!empty($text)) {
            $pos = min(mb_strpos($text, ' ', $extractLength - 1, $encoding), mb_strpos($text, '.', $extractLength - 1, $encoding));
            if ($pos) $intro = rtrim(mb_substr($text,0,$pos,$encoding), $trimchars) . $ellipsis;
            else $intro = $text;
        }
        else $intro = '';

The line 702 is: $pos = min(mb_strpos($text, ' ', $extractLength - 1, $encoding), mb_strpos($text, '.', $extractLength - 1, $encoding));

Coroico commented 12 years ago

See commit 52fee23 for the fix of this issue.

Coroico commented 11 years ago

The fix provided is not relevant. When you have a text with multibyte characters and a text length < extract length, then you get a warning:

Warning: mb_strpos() [function.mb-strpos]: Offset not contained in string in ..../core/components/advsearch/model/advsearch/advsearch.class.php

The textlength returned by : $textLength = mb_strlen($text);

is the length with the default internal encoding (ascii). So If you have some multibyte characters, the text length provided > true length.

To fix it add mb_internal_encoding($this->config['charset']); at the beginning of the getExtract function and remove the use of $encoding inside multi-bytes function.