def test_filtering(self): self.assertTrue(Video.objects.count()) for video in Video.objects.all(): video_changed_tasks.delay(video.pk) reset_solr() rpc = SearchApiClass() rdata = RpcMultiValueDict(dict(q=u' ', video_lang='en')) result = rpc.search(rdata, self.user, testing=True)['sqs'] self.assertTrue(len(result)) for video in VideoIndex.public(): if video.video_language == 'en': self.assertTrue( video.object in [item.object for item in result]) rdata = RpcMultiValueDict(dict(q=u' ', langs='en')) result = rpc.search(rdata, self.user, testing=True)['sqs'] self.assertTrue(len(result)) for video in VideoIndex.public(): if video.languages and 'en' in video.languages: self.assertTrue( video.object in [item.object for item in result])
def test_empty_query(self): rpc = SearchApiClass() rdata = RpcMultiValueDict(dict(q=u'')) rpc.search(rdata, self.user, testing=True)['sqs'] rdata = RpcMultiValueDict(dict(q=u' ')) rpc.search(rdata, self.user, testing=True)['sqs']
def test_query_clean(self): video = Video.objects.all()[0] video.title = u"Cher BBC and Dawn French's Lookalikes" video.save() reset_solr() rpc = SearchApiClass() rdata = RpcMultiValueDict(dict(q=u'?BBC')) result = rpc.search(rdata, self.user, testing=True)['sqs'] self.assertTrue(len(result))
def test_rpc(self): rpc = SearchApiClass() rdata = RpcMultiValueDict(dict(q=u'BBC')) for title in self.titles: video = Video.objects.all()[0] video.title = title video.save() reset_solr() result = rpc.search(rdata, self.user, testing=True)['sqs'] self.assertTrue(video in [item.object for item in result], title)
def test_search_relevance(self): reset_solr() rpc = SearchApiClass() rdata = RpcMultiValueDict(dict(q=u'unique')) result = rpc.search(rdata, self.user, testing=True)['sqs'] videos = [item.object for item in result] # by default, title is more important than description self.assertEquals(videos[0].title, u"This is my unique title") self.assertEquals(videos[1].title, u"Default") self.assertEquals(videos[1].description, u"this is my unique description") rdata = RpcMultiValueDict(dict(q=u'unique', sort="total_views")) result = rpc.search(rdata, self.user, testing=True)['sqs'] videos = [item.object for item in result] self.assertEquals(videos[0].title, u"Default") self.assertEquals(videos[1].title, u"This is my unique title")
def test_search_index_updating(self): reset_solr() rpc = SearchApiClass() for title in self.titles: rdata = RpcMultiValueDict(dict(q=title)) video = Video.objects.all()[0] video.title = title video.save() video.update_search_index() result = rpc.search(rdata, self.user, testing=True)['sqs'] self.assertTrue(video in [item.object for item in result], title)
def test_filtering(self): self.assertTrue(Video.objects.count()) for video in Video.objects.all(): video_changed_tasks.delay(video.pk) reset_solr() rpc = SearchApiClass() rdata = RpcMultiValueDict(dict(q=u' ', video_lang='en')) result = rpc.search(rdata, self.user, testing=True)['sqs'] self.assertTrue(len(result)) for video in SearchQuerySet().models(Video): if video.video_language == 'en': self.assertTrue(video.object in [item.object for item in result]) rdata = RpcMultiValueDict(dict(q=u' ', langs='en')) result = rpc.search(rdata, self.user, testing=True)['sqs'] self.assertTrue(len(result)) for video in SearchQuerySet().models(Video): if video.languages and 'en' in video.languages: self.assertTrue(video.object in [item.object for item in result])