简体   繁体   中英

Sphinx search - Search with booleans

Please excuse my bas english, i'm french !

I want to integrate Sphinx search in my website, but I've got one or two questions !

So, I've got a clothes ecommerce website (with codeigniter) and every article have those params : id, title, categoryName, size, brand, description, isDeleted, isSold, etc.

When I made a search with a boolean, it is ignored ! So can you say me how can I filter deleted and sold articles (isDeleted and isSold field) ?

Here my code

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"])  );
}

Thanks.

You should define the booleans as attributes in the config file.

Then can use SetFilter function to, well, filter on them :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM