2015-06-16 30 views
2

我正在使用django1.8和haystack 2.4和solr 4.10。不知何故預期ORDER_BY不能正常工作,請看看下面的代碼,haystack order_by不正確

>>> sqs = SearchQuerySet() 
>>> sqs = sqs.using('entry').filter(status=0) 
>>> for b in sqs.filter(content="see").order_by('title'): print b.title 
501 Must-See Movies 
Look See, Look at Me! 
Last Chance to See 
1,000 Places to See Before You Die 
Pretend You Don't See Her 
Learning to See Creatively : Design, Color and Composition in Photography 
Behavior Solutions for the Inclusive Classroom : See a Behavior? Look It Up! 
See No Evil 
Last Chance to See 
See It and Sink It : Mastering Putting Through Peak Visual Performance 
See No Evil : The True Story of a Ground Soldier in the CIA's War on Terrorism 
Voice for Now : Changing the Way We See Ourselves As Women 
See Jane Win : The Rimm Report on How 1,000 Girls Became Successful Women 
Kaplan Medical USMLE Medical Ethics : The 100 Cases You Are Most Likely to See on the Exam 
I See You 
You'll See It When You Believe It : The Way to Your Personal Transformation 
Body Code : Diet and Fitness Programme: Master Your Metabolism and See the Weight Fall Off 

降序排列

>>> sqs = SearchQuerySet() 
>>> sqs = sqs.using('entry').filter(status=0) 
>>> for b in sqs.filter(content="see").order_by('-title'): print b.title 
You'll See It When You Believe It : The Way to Your Personal Transformation 
Body Code : Diet and Fitness Programme: Master Your Metabolism and See the Weight Fall Off 
Kaplan Medical USMLE Medical Ethics : The 100 Cases You Are Most Likely to See on the Exam 
I See You 
Voice for Now : Changing the Way We See Ourselves As Women 
See Jane Win : The Rimm Report on How 1,000 Girls Became Successful Women 
See No Evil : The True Story of a Ground Soldier in the CIA's War on Terrorism 
See It and Sink It : Mastering Putting Through Peak Visual Performance 
Last Chance to See 
See No Evil 
Behavior Solutions for the Inclusive Classroom : See a Behavior? Look It Up! 
Learning to See Creatively : Design, Color and Composition in Photography 
Pretend You Don't See Her 
1,000 Places to See Before You Die 
Last Chance to See 
Look See, Look at Me! 
501 Must-See Movies 

爲什麼odering不工作像A - > Z和Z - >一個

+0

你如何填充標題?這裏似乎有些不妥。 –

+0

@LegoStormtroopr你的意思是索引?我無法遵循你的qiestion。 –

+0

是的,你是如何創建你的索引? –

回答

0

最近我有同樣的問題乾草堆order_by標題。我用python lambda函數對對象列表進行排序。

升序使用標題:

sqs = sqs.using('entry').filter(status=0) 
sorted_list = sorted([s.object for s in sqs], key=lambda x: x.title, reverse=False) 

降序排列:

sqs.order_by工作得很好整型字段。