How to build sorting query with RAND() as the second attribute #176
-
I need to randomize search results with same sorting attribute in results: on my case it's web crawler, that scan older collected links first by timestamp (or with zero time value when row not indexed yet) so crawler stuck on huge resource, and indexing only it documents in queue. The here is code construction to extend
no success by appending this one for example
My goal is the query like this but using
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Use the <?php
$config = ['host'=>'127.0.0.1','port'=>9308];
$client = new \Manticoresearch\Client($config);
$index = $client->index('t');
$index->drop(true);
$index->create([
'a' => ['type' => 'int'],
]);
$index->addDocument(['a' => 1]);
$index->addDocument(['a' => 1]);
print_r($index->search('')->expression('r', "rand()")->sort('a', 'asc')->sort('r', 'asc')->get()); |
Beta Was this translation helpful? Give feedback.
Use the
expression()
function: