我是使用elasticsearch
的django-haystack
返回的功能测试结果。
在运行测试时,我得到了不同的结果。有时测试通过,有时不通过。
我不明白为什么会这样。
我的测试类首先在测试数据库中创建条目,然后使用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>]>
那么,会发生什么呢?
发布于 2017-09-05 04:05:20
你在标题中说出答案。"Non deterministic",首先你需要了解这是什么。对于相同的输入,不确定算法可以得到不同的结果。但是为什么是这样呢?
如果你记得为什么我们使用非确定性算法,你会找到解决方案。但是,它真的很快:)
阅读有关Nondeterministic algorithms的更多信息
编辑:也许elasticsearch或django-haystack有一些确定性搜索的配置
https://stackoverflow.com/questions/46043011
复制相似问题