sphinx для поиска, БД - для данных. sphinx даёт id документов, из базы по ним тянем все что касается этих id.
Код | <?php require 'sphinxapi.php'; if($oRequest->isPost){ $oSphinx = new SphinxClient(); $oSphinx->SetServer('localhost', 3312); $oSphinx->setSortMode(SPH_SORT_RELEVANCE); $oSphinx->SetMatchMode(SPH_MATCH_EXTENDED); $sSearch = $aResults = false; foreach($oRequest->get(null) AS $k => $v){ switch($k){ case 'search': $sSearch = $v; break; case 'period': if($v > 0){ $iTime = time(); $oSphinx->->setFilterRange('created', $iTime - $v*86400, $iTime + $v*86400); } break; case 'limit': $oSphinx->SetLimits(0, (int)$v); break; } } if(null !== $oRequest->nick){ $sSearch .= ' @nick '.$oRequest->nick; } if(!empty($sSearch)){ $aSphinx = $oSphinx->Query($sSearch, 'album'); // extend results if($aSphinx['total'] > 0){ $aRecords = Component::get('Album')->getByIds(array_keys($aSphinx['matches'])); $aRecordsById = array(); foreach($aRecords AS $k => $aRecord){ $aRecordsById[$aRecord['id']] = $aRecord; } $aResult = array(); foreach($aSphinx['matches'] AS $id => $aRecord){ $aResult[] = $aRecordsById[$id]; } } } } ?>
|
|