Haystack queryset contains None elements

℡╲_俬逩灬. 提交于 2019-12-22 04:17:12

问题


I'm using Haystack for search, and the resulting SearchQuerySet returned contains None elements:

>> SearchQuerySet().models(Question, Document, Idea)
>> [<SearchResult: idea.idea (pk=3875)>, None, None, None]

Running rebuild_index doesn't help. If I remove the .models() call from the first line, the problem goes away. I could just filter out None elements from the results, but I wanted to know if this is intended behaviour?

I am using Django 1.4, Whoosh, and Haystack 2.0.0-beta


回答1:


I had this problem when haystack index had records without corresponding records in DB.




回答2:


No, it is definitly not the intended behaviour, and as I can see, seems to be related to a design decision in Whoosh. And, as of December 2015, this still seems to be an issue, as can be seen here. Also, I can reproduce it with my setup (django 1.8.5, haystack 2.4.1, Whoosh 2.7.0) - that's why I came here.

Quick and dirty solution that worked for me: Define a new field on your index (type/model/tomato), set it the same for each model, and filter against that value:

.filter(type='my_modelname')

instead of

.models(MyModel).

I don't know (yet) how this scales, but seems to work ok.




回答3:


Had the same problem using Whoosh, installed Elasticsearch and the None elements went away.



来源:https://stackoverflow.com/questions/10454367/haystack-queryset-contains-none-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!