搜索实现

  //拆分关键字 提取的时候 注意使用 trim($result[i] ) 把前后空格去掉
    function   text_explode($strTemp)
    {
          
$oldArray=array"    ","  "," "," "," ","," );
                 
$newArray=array("|","|","|","|","|","|");
            
$newphrase=str_replace($oldArray,$newArray,$strTemp);
            
$newphrase=str_replace("|||","|",   $newphrase);
            
$newphrase=str_replace("||","|",    $newphrase);
         
//   echo $newphrase;
            $result=explode("|",$newphrase);

           
//  echo "<br />";
          //  print_r($result);

            return $result;
    }
    
// 应用在 select * from tbl_user where id in('1','2','3')
    //同理 也可用于 多个删除 delete from tbl_user where id in('1','2','3')

    function implodeids($array)
     {
        
if(!empty($array)) {
            
return "'".implode("','", is_array($array? $array : array($array))."'";
        } 
else {
            
return '';
        }
    }

 建立 searchIndex 中间表 用于存储 搜索关键字。中对应的 要搜索 物品的id,

在搜索的时候先 查询该关键字 是否在 tbl_searchindex表中存在 如果有 就直接通过searchid来去 物品Id,

再生产物品列表.、

如果没有就 先搜索物品列表 把物品列表 和关键字 放入searchindex 起到了搜索缓存效果。

在搜索中 使用(   or     ) and (  or  )

每个or 语句尽量要考虑是否可以用union 语句

还要把 基本上用的 标签 搜索添加到热门搜索 列表中去

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值