狮身人面像搜索-使用布尔搜索


Sphinx search - Search with booleans

请原谅我英语不好,我是法国人!

我想在我的网站上集成Sphinx搜索,但我有一两个问题!

所以,我有一个服装电子商务网站(带代码点火器),每篇文章都有这些参数:id,title,categoryName,size,brand,description,isDeleted,isSold,etc.

当我用布尔值进行搜索时,它被忽略了!那么你能告诉我如何过滤已删除和已售出的文章(isDeleted和isSold字段)吗?

这是我的代码

function sphinx_search($fields, $order_by, $order_order, $position, $offset, $limit){
$CI =& get_instance();
$CI->load->library('SphinxClient');
$ids = array();
$CI->sphinxclient->SetServer("localhost" , 9312);
$CI->sphinxclient->SetMatchMode(SPH_MATCH_ANY);
$CI->sphinxclient->SetFieldWeights(array('title' => 300, 'categoryName' => 200,     'size' => 150, 'brand' => 100, 'description' => 30));
$CI->sphinxclient->SetLimits($offset, $limit);
$CI->sphinxclient->SetSortMode(SPH_SORT_EXTENDED, $order_by.' '.$order_order);
if (!empty($position)) {
    $CI->sphinxclient->SetGeoAnchor('latitude', 'longitude', (float) deg2rad($position['latitude']), (float) deg2rad($position['longitude']));
    $CI->sphinxclient->setSelect("*, IF(@geodist<50000,30,0)+IF(@geodist<20000,80,0)+IF(@geodist<5000,150,0)+@weight AS performance");
}
$query='';
foreach ($fields as $key => $value) {
    if ($key == 'q') {
        $query .= ' '.$value.' ';
    } else {
        $query .= ' @'.$key.' '.$value.' ';
    }
}

$result = $CI->sphinxclient->Query( $query, 'catalog' );
if ( $result === false )
    var_dump('[SPHINX]Query failed: ' . $CI->sphinxclient->GetLastError());
elseif ( $CI->sphinxclient->GetLastWarning() )
    var_dump('[SPHINX]WARNING: ' .  $CI->sphinxclient->GetLastWarning());
if ( !empty($result["matches"]) ){
    foreach ( $result["matches"] as $doc => $docinfo )
        $ids[] = $doc;
} else {
    return false;
}
return array( 'ids' => $ids, 'total' => $result['total'], 'docs' => count($result["matches"])  );
}

谢谢。

您应该在配置文件中将布尔值定义为属性

然后可以使用SetFilter函数对它们进行过滤:)