Search string by exact word in Mysql

后端 未结 8 1176
广开言路
广开言路 2021-01-18 07:11

I have a system that searches for company. I want that when a user searches for \"Demo\", all records that have \"Demo\" will be returned, like \"The Demo\", \"Demo Inc.\",

8条回答
  •  醉话见心
    2021-01-18 07:21

    I dont see why 1M is a problem I just tested on my laptop MySQL MyISAM that has also a company but it is 250K rows and it took 3.3 ms , and the field is not indexed. can you try folowing

    $search='Demo';
    $regex="/\b$search\b/i";
    $sql = "select * from table where company like '%$search%';
    //... get the results
    foreach($results as $companyName){
     if(preg_match($regex,$companyName,$match)){
        //here you got a match 
     }
    }
    

提交回复
热议问题