Created
May 18, 2014 04:17
-
-
Save dedy-purwanto/0122e1c67f47119a13a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""It's a hack for solr backend to apply django-style random ordering | |
with '?'. Change haystack/backends/solr_backend.py | |
""" | |
# .. Somewhere in the beginning | |
import random | |
# .. Somewhere in :638, replace content of for-loop into these: | |
if order_by.startswith('-'): | |
order_by_list.append('%s desc' % order_by[1:]) | |
elif order_by.startswith('?'): | |
order_by_list.append('random_%04d desc' % random.randint(0, 9999)) | |
else: | |
order_by_list.append('%s asc' % order_by) | |
"""In solr schema, make sure you have: | |
Inside <types>: | |
<fieldType name="random" class="solr.RandomSortField" /> | |
Inside <fields>: | |
<dynamicField name="random*" type="random" indexed="true" | |
stored="false"/> | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment