Skip to content

How to build sorting query with RAND() as the second attribute #176

Closed Answered by manticoresearch
d47081 asked this question in Q&A
Discussion options

You must be logged in to vote

Use the expression() function:

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

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@d47081
Comment options

Answer selected by d47081
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants