广州传奇网络

地址:广州市天河区东圃大马路富华楼C座

电话:13808825895

邮箱:gz020wbs@163.com

QQ:1564443073

网址:http://www.020wbs.com/

首页 > 二次开发 > xunsearch模糊搜索按字段分组统计

二次开发

二次开发

xunsearch模糊搜索按字段分组统计

 xunsearch模糊搜索按字段分组统计,我们在使用xunsearch做ecshop商品的搜索引擎的过程中,有时候需要把结果进行分组统计,而且实现分组排序和数量统计,还要实现xunsearch的精确搜索,还需要兼顾模糊搜索。xunsearch的模糊搜索很简单,设置setFuzzy就可以了。

                        $xs   = new XS('ec');

$search = $xs->search;
$search->setCharset('UTF-8');
$this->xs_search = $search;    //初始化xs对象,供其他地方调用
$search->setFuzzy (true);   //模糊匹配
$where = "  goods_name:$filter[keywords]";//查询条件
if ($filter['brand_id']) {
$where.=" AND brand_id:{$filter['brand_id']}";
}
if ($filter['cat_id']) {
$where.=" AND cat_id:{$filter['cat_id']}";
}
$res['matches'] = $search->setQuery($where)->setFacets(array('brand_id','cat_id'),true)->setLimit($filter['pagesize'],$filter['start'])->search();
$res['brand_id'] = $search->getFacets('brand_id'); 
$res['cat_id'] = $search->getFacets('cat_id'); 
$res['total'] = $search->getLastCount();