Solr - Return random results (Sort by Random)

前端 未结 2 978
无人及你
无人及你 2020-12-07 02:03

In Solr, Whats the best approach to order results by random?, basically needs to pick some records at random.

2条回答
  •  鱼传尺愫
    2020-12-07 02:14

    In latest Solr, nothing need to do with schema. Just add below sorting and it will give random result set.

    ...
    ...
    
    //Below is to get rendom string
    $randString = mt_rand();        
    $query->addSort('random_'.$randString, $query::SORT_DESC);
    
    ...
    ...
    

提交回复
热议问题