[英]Non-deterministic results when testing django haystack with elasticsearch
我是通过返回功能测试结果django-haystack
与elasticsearch
。
运行测试时,我得到不同的结果。 有时测试通过,有时则没有。
我不知道为什么会这样。
我的测试类首先在测试数据库中创建条目,然后使用StaticLiveServerTestCase setUp方法调用manage.py rebuild_index
。 最后,我调用manage.py clear_index
。
我不会在这里复制所有用于搜索索引的django代码,_text.txt,因为django-haystack / elasticsearch代码正在工作。
我想知道这是否是创建的数据库条目和对rebuild_index
的调用之间的同步问题。
基本上,在我的测试中
class SearchTest(FunctionalTest):
def setUp(self):
super(SearchTest, self).setUp() # this make the entries in database
self.rebuild_index()
def tearDown(self):
super(SearchTest, self).tearDown()
call_command('clear_index', interactive=False)
打印索引的对象有时会得到错误的结果:
<QuerySet [<Step: emg>]>
<QuerySet [<Step: emg>]>
<QuerySet [<Step: emg>]>
有时是正确的:
<QuerySet [<Step: emg>]>
<QuerySet [<Step: emg>]>
<QuerySet [<Step: emg>]>
<QuerySet [<Step: eeg>, <Step: emg>]>
<QuerySet [<Step: eeg>, <Step: emg>]>
那么,可能会发生什么?
您在标题上说答案。 “ 非确定性 ”,首先您需要了解这是什么。 对于相同的输入,不确定性算法可以获得不同的答案。 但是为什么呢?
如果您还记得为什么我们使用非确定性算法,那么您会找到解决方案。 通常,非确定性算法需要比确定性算法更快,为此,它们可以“泛化”某些事物(例如数学中的近似值),并且这种泛化可能导致不同的结果。 但是,真的很快:)
阅读有关非确定性算法的更多信息
编辑:也许elasticsearch或django-haystack具有确定性搜索的一些配置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.