我刚刚在我的服务器上安装了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);我尝试了许多方法来使其随机化,但没有成功。
发布于 2015-10-21 18:55:05
SphinxQL仅支持asc和desc选项,不支持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);https://stackoverflow.com/questions/33031954
复制相似问题