0

I just installed on my server SphinxQL Vendor (I'm new to this) and I have a problem - I can't find a way to make the script work via random select.

This is my code:

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);

I have tried many ways to make it random but no luck.

halfer
  • 19,824
  • 17
  • 99
  • 186
Matei Zoc
  • 3,739
  • 3
  • 16
  • 18

1 Answers1

0

SphinxQL supports only asc and desc options and not rand direction. See https://github.com/FoolCode/SphinxQL-Query-Builder#group-within-group-order-offset-limit-option for more details.

However, you can do it in PHP instead:

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);
MartyIX
  • 27,828
  • 29
  • 136
  • 207