Exemplo n.º 1
0
 def test_vector_add_multi(self):
     searched = Line.objects.annotate(
         search=(
             SearchVector('scene__setting') +
             SearchVector('character__name') +
             SearchVector('dialogue')
         ),
     ).filter(search='bedemir')
     self.assertEqual(set(searched), {self.bedemir0, self.bedemir1, self.crowd, self.witch, self.duck})
Exemplo n.º 2
0
 def test_terms_adjacent(self):
     searched = Line.objects.annotate(
         search=SearchVector('character__name', 'dialogue'),
     ).filter(search='minstrel')
     self.assertCountEqual(searched, self.verses)
     searched = Line.objects.annotate(
         search=SearchVector('scene__setting', 'dialogue'),
     ).filter(search='minstrelbravely')
     self.assertSequenceEqual(searched, [])
Exemplo n.º 3
0
    def test_query_multiple_and(self):
        searched = Line.objects.annotate(
            search=SearchVector('scene__setting', 'dialogue'),
        ).filter(search=SearchQuery('bedemir') & SearchQuery('scales') & SearchQuery('nostrils'))
        self.assertSequenceEqual(searched, [])

        searched = Line.objects.annotate(
            search=SearchVector('scene__setting', 'dialogue'),
        ).filter(search=SearchQuery('shall') & SearchQuery('use') & SearchQuery('larger'))
        self.assertSequenceEqual(searched, [self.bedemir0])
Exemplo n.º 4
0
    def test_weights_in_vector(self):
        vector = SearchVector('dialogue', weight='A') + SearchVector('character__name', weight='D')
        searched = Line.objects.filter(scene=self.witch_scene).annotate(
            rank=SearchRank(vector, SearchQuery('witch')),
        ).order_by('-rank')[:2]
        self.assertSequenceEqual(searched, [self.crowd, self.witch])

        vector = SearchVector('dialogue', weight='D') + SearchVector('character__name', weight='A')
        searched = Line.objects.filter(scene=self.witch_scene).annotate(
            rank=SearchRank(vector, SearchQuery('witch')),
        ).order_by('-rank')[:2]
        self.assertSequenceEqual(searched, [self.witch, self.crowd])
Exemplo n.º 5
0
 def test_ranking_chaining(self):
     searched = Line.objects.filter(character=self.minstrel).annotate(
         rank=SearchRank(SearchVector('dialogue'), SearchQuery('brave sir robin')),
     ).filter(rank__gt=0.3)
     self.assertSequenceEqual(searched, [self.verse0])
Exemplo n.º 6
0
 def test_query_and(self):
     searched = Line.objects.annotate(
         search=SearchVector('scene__setting', 'dialogue'),
     ).filter(search=SearchQuery('bedemir') & SearchQuery('scales'))
     self.assertSequenceEqual(searched, [self.bedemir0])
Exemplo n.º 7
0
 def test_config_from_field_implicit(self):
     searched = Line.objects.annotate(
         search=SearchVector('scene__setting', 'dialogue', config=F('dialogue_config')),
     ).filter(search='cadeaux')
     self.assertSequenceEqual(searched, [self.french])
Exemplo n.º 8
0
 def test_config_query_explicit(self):
     searched = Line.objects.annotate(
         search=SearchVector('scene__setting', 'dialogue', config='french'),
     ).filter(search=SearchQuery('cadeaux', config='french'))
     self.assertSequenceEqual(searched, [self.french])
Exemplo n.º 9
0
 def test_search_with_non_text(self):
     searched = Line.objects.annotate(
         search=SearchVector('id'),
     ).filter(search=str(self.crowd.id))
     self.assertSequenceEqual(searched, [self.crowd])
Exemplo n.º 10
0
 def test_search_with_null(self):
     searched = Line.objects.annotate(
         search=SearchVector('scene__setting', 'dialogue'),
     ).filter(search='bedemir')
     self.assertEqual(set(searched), {self.bedemir0, self.bedemir1, self.crowd, self.witch, self.duck})
Exemplo n.º 11
0
 def test_search_two_terms(self):
     searched = Line.objects.annotate(
         search=SearchVector('scene__setting', 'dialogue'),
     ).filter(search='heart forest')
     self.assertSequenceEqual(searched, [self.verse2])
Exemplo n.º 12
0
 def test_non_exact_match(self):
     searched = Line.objects.annotate(
         search=SearchVector('scene__setting', 'dialogue'),
     ).filter(search='heart')
     self.assertSequenceEqual(searched, [self.verse2])
Exemplo n.º 13
0
 def test_simple_on_scene(self):
     searched = Line.objects.annotate(
         search=SearchVector('scene__setting', 'dialogue'),
     ).filter(search='Forest')
     self.assertCountEqual(searched, self.verses)
Exemplo n.º 14
0
 def test_simple_on_dialogue(self):
     searched = Line.objects.annotate(
         search=SearchVector('scene__setting', 'dialogue'),
     ).filter(search='elbows')
     self.assertSequenceEqual(searched, [self.verse1])
Exemplo n.º 15
0
 def test_existing_vector_config_explicit(self):
     Line.objects.update(dialogue_search_vector=SearchVector('dialogue'))
     searched = Line.objects.filter(dialogue_search_vector=SearchQuery('cadeaux', config='french'))
     self.assertSequenceEqual(searched, [self.french])
Exemplo n.º 16
0
 def test_existing_vector(self):
     Line.objects.update(dialogue_search_vector=SearchVector('dialogue'))
     searched = Line.objects.filter(dialogue_search_vector=SearchQuery('Robin killed'))
     self.assertSequenceEqual(searched, [self.verse0])