Full text search in MySQL (PHP) with letters under ft_min_word_len -
my ft_min_word_len in mysql set 4. when try full text search 2 or 3 letters, no results. i'm using code full-text search these short words:
$table = $this->db->shop_products();  $where = ''; preg_match_all("~[\\pl\\pn_]+('[\\pl\\pn_]+)*~u", stripslashes($find), $matches);  foreach($matches[0] $part) {     $isfirst = empty($where);     $regexp = "regexp '" . addslashes($part) . "'";      if(!$isfirst) $where .= " , (";     $where .= "name {$regexp} or content {$regexp}";     if(!$isfirst) $where .= ")"; }  return $table->where($where)->limit(5)->fetchall(); this code works fine, has problem diacritic, č, á, é, í.... example, have product called bé , when want find be, not show me product, because doesn't have same letters.
note: i'm using notorm mysql queries, hope know how work $table->where(....
so found solution, php, not mysql. right in foreach put line $part = diagritictonormal($part); - change special characters classic ones, or how name it. under answer there function. know lame, not performance etc... start enought.
function diagritictonormal($text) {     $charsmap = array(         'a' => array('á', 'ä'),         'c' => array('č'),         'd' => array('ď'),         'e' => array('é', 'ě'),         'i' => array('í'),         'l' => array('ľ', 'ĺ'),         'n' => array('ň'),         'o' => array('ô', 'ó'),         'r' => array('ŕ', 'ř'),         's' => array('š'),         't' => array('ť'),         'u' => array('ú', 'ů'),         'y' => array('ý'),         'z' => array('ž'),     );      foreach($charsmap $real => $alt) {         $alt = implode('|', $alt);         $text = str_replace(array(strtolower($real), strtoupper($real)), '[' . $real . '|' . $alt . ']', $text);     }      return $text; } 
Comments
Post a Comment