def reindex_redis_search(sender, instance, **kwargs): """ Callback function which recalculates what is searchable in redis from sender. """ logger.info("Re-creating Search Autocomplete Index ...") flush_redis() [add_model_to_redis_search(model) for model in Post.objects.all()] [add_model_to_redis_search(model) for model in PostNode.objects.all()] log_dump_redis()
def test_flush_redis(self): """ Test of flush_redis method. """ G(TestModelPost, title="This is a test post.", slug="", author=self.staff) self.assertEquals(r.zrange(ZKEY_AUTOCOMPLETE, 0, -1), ['a', 'a*', 'i', 'is', 'is*', 'p', 'po', 'pos', 'post', 'post*', 't', 'te', 'tes', 'test', 'test*', 'th', 'thi', 'this', 'this is a test post*', 'this*']) autocomplete_list = r.keys(SKEY_AUTOCOMPLETE+'*') self.assertTrue(SKEY_AUTOCOMPLETE+'this' in autocomplete_list) self.assertTrue(SKEY_AUTOCOMPLETE+'is' in autocomplete_list) self.assertTrue(SKEY_AUTOCOMPLETE+'a' in autocomplete_list) self.assertTrue(SKEY_AUTOCOMPLETE+'test' in autocomplete_list) self.assertTrue(SKEY_AUTOCOMPLETE+'post' in autocomplete_list) self.assertTrue(SKEY_AUTOCOMPLETE+'this is a test post' in autocomplete_list) self.assertEquals(r.smembers('models-tests.testmodelpost:1'), set(['title:This is a test post.', 'slug:this-is-a-test-post', 'get_absolute_url:/blog/post/this-is-a-test-post/'])) flush_redis() self.assertEquals(r.zrange(ZKEY_AUTOCOMPLETE, 0, -1), []) self.assertEquals(r.keys(SKEY_AUTOCOMPLETE+'*'), []) self.assertEquals(r.smembers('models-*'), set([]))
def reindex_redis_search(sender, instance, **kwargs): """ Callback function which recalculates what is searchable in redis from sender. """ flush_redis() [add_model_to_redis(model) for model in TestModelPost.objects.all()] dump_redis()
def tearDown(self): flush_redis()