The schema.xml that comes with this module doesn't declare the random_* field compared to the default that comes when you download apachesolr. I guess you left that out, especially with the random_seed which is pretty hard to detect in the default_sorts() in Solr_Base_Query.php. However, with hook_apachesolor_modify_query, it's pretty easy to add a random sort order.
see http://lucene.apache.org/solr/api/org/apache/solr/schema/RandomSortField...
Note, the documents seem to be wrong, in my testing following works:
<!-- goes in types -->
<fieldType name="rand" class="solr.RandomSortField" indexed="true" />
<!-- goes in fields -->
<dynamicField name="random*" type="rand" indexed="true" stored="true"/>
Adding following to the url to test:
http://localhost:port/solr/select?q=whatever&morekeyshere&sort=random_127789 desc
And in php code:
function hook_apachesolr_modify_query(&$query, &$params, $caller) {
if ($caller == 'whatever') {
$seed = rand(1, 200);
$params['qt'] = 'standard';
$params['sort'] = 'random_'. $seed .' asc';
}
}
This works pretty fine. I'm aware it's probably hard to implement this by default, but simply adding it to the schema.xml would be fine, so we don't need to alter it every time. This might go into documentation if anyone is looking for this sort of solution.
Comments
Comment #1
pwolanin commentedThe schema.xml has not been kept in sync with all the Solr project changes to that file - so we can certainly consider adding this if there is a use case.
Comment #2
pwolanin commentedI'm a little unclear - do you have to reindex to change the random ordering?
Comment #3
swentel commentedThis works like in MySQL. If you always give the same integer in the MySQL RAND() function, the random ordering will always be the same. Changing that number alters it. Same goes for the dynamic random* field in Apache Solr. So random_1 vs random_2 will give you another random order which why don't need to reindex it if you want to have a random order. I haven't tested it yet with simply using 'random' all the time, but I think that will give you the same results over and over.
Comment #4
pwolanin commentedsee: http://drupal.org/node/641954
let's combine all reasonable BC changes there asap.
this iss will be marked duplicate.
Comment #5
pwolanin commented