Closed (fixed)
Project:
Apache Solr Search
Version:
7.x-1.0-beta19
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
23 Apr 2012 at 20:46 UTC
Updated:
17 May 2012 at 07:40 UTC
I would like to create a random sort option, selectable from this module's sort block... I saw http://drupal.org/node/602152, and noticed that the current schema that comes with this module does seem to have the random_* field declared... but I couldn't figure out how to implement it in the current 7.x release... do I need to use hook_apachesolr_query_alter?
Any help is much appreciated!
Comments
Comment #1
pwolanin commentedYou probably would use both hook_apachesolr_query_prepare() and hook_apachesolr_query_alter() to add the sort as described.
Basically something like this should work (untested, though):
This relies on the fact that the prepared, but not altered, query object is cached as the current query.
Comment #2
pwolanin commentedComment #3
jordanmagnuson commentedAwesome! That works perfectly. Thank you!
Comment #4
jordanmagnuson commentedUpdated my random sorting method to work with browsing through paged results (so that results aren't randomized again on every page). Basically a random seed is cached for each user, and randomized again each time we visit the first page of results. Thought I'd post it here in case it might help someone in the future.
If anyone has feedback on a better way to do this, please let me know.
Comment #5
pwolanin commentedYou should use the session for this sort of thing, not the cache.
Comment #6
jordanmagnuson commentedYes, that makes a lot more sense! Thank you. Here's my updated code: