这是我第一次愿意添加多重搜索。我不知道该怎么做。我应该在搜索中使用每个单词的循环吗?或者有没有mysql内置的功能?
我在想应该是什么样子?
$strSearch = $this->input->post("search"); // would hold words etc hello word
$arry = explode(" ", $strSearch);
foreach($arry as $item){
$this->db->query("select * from tbl where item like '%$item%');
}
请提供建议。
谢谢
有很多东西需要搜索。
反复阅读你的话只是战斗的一小部分。有语序(Mac Office与Office Mac),忽略常用词(a,the),单词变体如复数。不要忘记权衡和评分你的搜索。
尝试一个已经完成繁重工作的库,比如ZendSearch-Lucene。请参阅:http://codeigniter.com/forums/viewthread/207865/或http://www.cmjackson.net/2009/02/17/how-to-use-zend_search_lucene-with-the-php-framework-codeigniter/.
的工作原理
我将单词拆分,并为每个单词循环生成一个额外的字符串,然后通过mysql查询执行该字符串。它按照我的意愿工作。
$strSearch = $this->input->post("search"); // would hold words etc hello word
$arry = explode(" ", $strSearch);
foreach($arry as $item){
$xQuery .= " or name like '%$item%' or location like '%item'";
}
$this->db->query("select * from tbl where name like '$strSearch' or location like '$strSearch' .$xQuery ");
您可以查看MySQL自然语言搜索。
http://dev.mysql.com/doc/refman/5.5/en/fulltext-search.html