0

我刚刚在我的服务器上安装了 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);

我尝试了很多方法让它随机但没有运气。

4

1 回答 1

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);
于 2015-10-21T10:55:05.450 回答