Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
"""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
You can’t perform that action at this time.