2015-10-09 40 views
0

我刚刚安装在我的服务器SphinxQL供应商(我是新来的),我有一个问题 - 我找不到一种方法使脚本通过随机选择工作。SphinxQL供应商订单随机

这是我的代码:

require "./classes/vendor/autoload.php"; 
use Foolz\SphinxQL\SphinxQL; 
use Foolz\SphinxQL\Connection; 


// create a SphinxQL Connection object to use with SphinxQL 
$conn = new Connection(); 
$conn->setParams(array('host' => '127.0.0.1', 'port' => 9306)); 
$query = SphinxQL::create($conn)->select('*') 
    ->from('documents_titles') 
    ->match('title','welcome') 
    ->orderBy('title', $direction = 'RAND()'); 
$result = $query->execute(); 
var_dump($result); 

我已经尝试了许多办法让它随机的,但没有运气。希望有人能帮助我。

回答

0

SphinxQL仅支持ascdesc选项,而不支持rand方向。有关更多详细信息,请参阅https://github.com/FoolCode/SphinxQL-Query-Builder#group-within-group-order-offset-limit-option

然而,你可以在PHP中做到这一点,而不是:

require "./classes/vendor/autoload.php"; 
use Foolz\SphinxQL\SphinxQL; 
use Foolz\SphinxQL\Connection; 


// create a SphinxQL Connection object to use with SphinxQL 
$conn = new Connection(); 
$conn->setParams(array('host' => '127.0.0.1', 'port' => 9306)); 
$query = SphinxQL::create($conn)->select('*') 
    ->from('documents_titles') 
    ->match('title','welcome'); 

$result = $query->execute(); 
shuffle($result); // <-- ADD THIS LINE 
var_dump($result);