I have some bugs and suggestions in search.module.

1. preg_replace of punctation characters (do_search)

Current line

  $keys = preg_replace("'(!|%|,|:|;|\(|\)|\&|\"|\'|\.|-|\/|\?|\\\)'", '', $keys);  

should be changed to - replace with space not with empty string

  $keys = preg_replace("'(!|%|,|:|;|\(|\)|\&|\"|\'|\.|-|\/|\?|\\\)'", ' ', $keys);  

Former implementation did change e.g. 'www.drupal.org' to one word 'wwwdrupalorg' not to three ones, 'end of sentence.Start of next sentence', '123456.14' to 12435614, now expansion to 2 words is not also perfect but better.

2. Remove short and empty words before for each loop otherwise search won't succesfull if term is e.g. 'word ', 'word a' etc. due to if (!$reduction[$lno][$word]) condition

  $words = explode(' ', $keys);¨

  $i = 0;                              
// If the word is too short remove from search phrase not to affect $reduction
  while ($i < count($words)) {
    if ($words[$i]=='' || (mb_strlen($words[$i], 'UTF-8') < variable_get('remove_short', 0))) 
      Unset($words[$i]);
    else
      $i++;
  }

  foreach ($words as $word) {

3. copy/paste error in update_index(), there are $key instead $wordlist (copied from do_search()), plus the same things as in cue 1)

      $wordlist = preg_replace("'(!|%|,|:|;|\(|\)|\&|\"|\'|\.|-|\/|\?|\\\)'", ' ', $wordlist); 

4. I had general UTF-8 problem in module (PHP 4.3.4 CGI Win32) so I had to prefix all strtolower, strlen with mb_ and load module php_mbstring in php.ini. PHP it not probably not compiled with native multibyte support. Maybe some string abstration library (macro like) should be implemented to change all multibyte operation from one place.

Tomas

Comments

wulff’s picture

Version: » x.y.z

ad 1) Fixed. Now uses search_keywords_split.

ad 2) Can't confirm at the moment. Need to get indexing to work first.

ad 3) Fixed. Now uses search_keywords_split.

ad 4) Still applies. Indexing and searching for strings containing multibyte characters fails with PHP 4.3.2 on Windows (probably a version built without mb support).

Testing with the string 'æblegrød' in a node, cron.php results in the following errors:

warning: Compilation failed: characters with values > 255 are not yet supported in classes at offset 52 in d:\wwwroot\drupal-cvs\modules\search.module on line 253.

warning: Compilation failed: characters with values > 255 are not yet supported in classes at offset 143 in d:\wwwroot\drupal-cvs\modules\search.module on line 261.

Searching for a string results in same errors.

Further testing seems to indicate that the errors occur even when no multibyte characters are present. I'll try with a more recent version of PHP.

damien tournoud’s picture

Status: Active » Closed (duplicate)

2. I'm pretty sure this issue doesn't apply anymore (tested on 4.6.2).

4. Is a known issue.

Merge with #26688