[英]Sphinx search - Search with booleans
請原諒我的英語bas,我是法語!
我想將Sphinx搜索整合到我的網站中,但是我有一個或兩個問題!
因此,我有一個服裝電子商務網站(帶有codeigniter),每篇文章都有這些參數:id,標題,categoryName,大小,品牌,描述,isDeleted,isSold等。
當我使用布爾值進行搜索時,它將被忽略! 那么您能說我如何過濾已刪除和已出售的文章(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
函數對它們進行過濾:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.