I have been struggling with full-text search with MySQL but always have some issues, I have 2 columns first_name
and last_name
,
my app is built on php codeigniter framework, at first i was searching name with mysql LIKE.
$this->db->like("CONCAT(TRIM(co.first_name),' ',(co.last_name))", trim($search_firstname.' '.$search_lastname));
problem with searching like this is when someone enter last name first and then enter half of first name then the search return 0 results, for example if the name is Arthur Peglow
and when i enter last name 'peglow' and then enter Art
the search return 0 results.
i decided to create full text index
ALTER TABLE contacts ADD FULLTEXT INDEX `FullText` (`first_name` ASC, `last_name` ASC);
$this->db->where('MATCH (co.first_name, co.last_name) AGAINST ("'.$search_name.'")', NULL, FALSE);
the first problem i faced was, it returned 0 results with less than 3 characters, i fixed this by changing ft_min_word_len to 2, i still notice sometimes it doesnt return any results with 2 characters entered the problem is still not solved, it shows results when entered min 3 characters, when entered name 'arth' it doesnt return the record with name 'Arthur Peglow' but just return the result with name 'Arth' only
adding another character 'Arthu' returned 0 results, entering full name 'Arthur' returned the expected result, it is clearly not returning the expected results
my question is clear, what am i doing wrong? any suggestions?