示例#1
0
    def test_content_search(self):
        result = self.queryset.filter(content='medium this')
        self.assertEqual(sorted(pks(result)),
                         pks(Document.objects.all()))

        # documents with "medium" AND "this" have higher score
        self.assertEqual(pks(result)[:4], [1, 4, 7, 10])
示例#2
0
    def test_field_search(self):
        self.assertEqual(pks(self.queryset.filter(name='8')), [4])
        self.assertEqual(pks(self.queryset.filter(type_name='book')),
                         pks(Document.objects.filter(type_name='book')))

        self.assertEqual(pks(self.queryset.filter(text='text huge')),
                         pks(Document.objects.filter(text__contains='text huge')))
示例#3
0
 def test_non_ascii_search(self):
     """
     Regression test for #119.
     """
     self.assertEqual(
         pks(self.queryset.filter(content='corrup\xe7\xe3o')),
         pks(Document.objects.filter(summary__contains='corrup\xe7\xe3o')))
示例#4
0
    def test_field_search(self):
        self.assertEqual(pks(self.queryset.filter(name='8')), [4])
        self.assertEqual(pks(self.queryset.filter(type_name='book')),
                         pks(Document.objects.filter(type_name='book')))

        self.assertEqual(
            pks(self.queryset.filter(text='text huge')),
            pks(Document.objects.filter(text__contains='text huge')))
示例#5
0
    def test_date_range(self):
        date = datetime.date(year=2010, month=2, day=1)
        self.assertEqual(set(pks(self.queryset.filter(date__gte=date))),
                         set(pks(Document.objects.filter(date__gte=date))))

        date = datetime.date(year=2010, month=3, day=1)
        self.assertEqual(set(pks(self.queryset.filter(date__lte=date))),
                         set(pks(Document.objects.filter(date__lte=date))))
示例#6
0
    def test_date_range(self):
        date = datetime.date(year=2010, month=2, day=1)
        self.assertEqual(set(pks(self.queryset.filter(date__gte=date))),
                         set(pks(Document.objects.filter(date__gte=date))))

        date = datetime.date(year=2010, month=3, day=1)
        self.assertEqual(set(pks(self.queryset.filter(date__lte=date))),
                         set(pks(Document.objects.filter(date__lte=date))))
示例#7
0
    def test_field_contains(self):
        self.assertEqual(
            pks(self.queryset.filter(summary='huge')),
            pks(Document.objects.filter(summary__contains='huge')))

        result = self.queryset.filter(summary='huge summary')
        self.assertEqual(sorted(pks(result)), pks(Document.objects.all()))

        # documents with "huge" AND "summary" have higher score
        self.assertEqual(pks(result)[:4], [3, 6, 9, 12])
示例#8
0
    def test_field_contains(self):
        self.assertEqual(pks(self.queryset.filter(summary='huge')),
                         pks(Document.objects.filter(summary__contains='huge')))

        result = self.queryset.filter(summary='huge summary')
        self.assertEqual(sorted(pks(result)),
                         pks(Document.objects.all()))

        # documents with "huge" AND "summary" have higher score
        self.assertEqual(pks(result)[:4], [3, 6, 9, 12])
示例#9
0
 def test_field_startswith(self):
     self.assertEqual(len(self.queryset.filter(name__startswith='magaz')),
                      4)
     self.assertEqual(
         set(pks(
             self.queryset.filter(summary__startswith='This is a huge'))),
         set(
             pks(
                 Document.objects.filter(
                     summary__startswith='This is a huge'))))
示例#10
0
    def test_content_and(self):
        self.assertEqual(
            pks(self.queryset.filter(content='huge').filter(summary='medium')),
            [])

        self.assertEqual(len(self.queryset.filter(content='huge this')), 12)
        self.assertEqual(
            len(
                self.queryset.filter(content='huge this').filter(
                    summary='huge')), 4)
示例#11
0
    def test_auto_query(self):
        # todo: improve to query text only.
        self.assertEqual(
            set(pks(self.queryset.auto_query("huge OR medium"))),
            set(
                pks(
                    Document.objects.filter(
                        Q(text__contains="huge")
                        | Q(text__contains="medium")))))

        self.assertEqual(
            set(pks(self.queryset.auto_query("huge AND medium"))),
            set(
                pks(
                    Document.objects.filter(
                        Q(text__contains="huge")
                        & Q(text__contains="medium")))))

        self.assertEqual(
            set(pks(self.queryset.auto_query("text:huge text:-this"))),
            set(
                pks(
                    Document.objects.filter(
                        Q(text__contains="huge")
                        & ~Q(text__contains="this")))))

        self.assertEqual(len(self.queryset.filter(name=AutoQuery("8 OR 4"))),
                         2)
        self.assertEqual(len(self.queryset.filter(name=AutoQuery("8 AND 4"))),
                         0)
示例#12
0
    def test_private_fields(self):
        self.assertEqual(pks(self.queryset.filter(django_id=4)),
                         pks(Document.objects.filter(id__in=[4])))
        self.assertEqual(pks(self.queryset.filter(django_id__in=[2, 4])),
                         pks(Document.objects.filter(id__in=[2, 4])))

        self.assertEqual(set(pks(self.queryset.models(Document))),
                         set(pks(Document.objects.all())))
示例#13
0
    def test_private_fields(self):
        self.assertEqual(pks(self.queryset.filter(django_id=4)),
                         pks(Document.objects.filter(id__in=[4])))
        self.assertEqual(pks(self.queryset.filter(django_id__in=[2, 4])),
                         pks(Document.objects.filter(id__in=[2, 4])))

        self.assertEqual(set(pks(self.queryset.models(Document))),
                         set(pks(Document.objects.all())))
示例#14
0
    def test_order_by(self):
        # private order
        self.assertEqual(pks(self.queryset.order_by("-django_id")),
                         pks(Document.objects.order_by("-id")))

        # value order
        self.assertEqual(pks(self.queryset.order_by("number")),
                         pks(Document.objects.order_by("number")))

        # text order
        self.assertEqual(pks(self.queryset.order_by("summary")),
                         pks(Document.objects.order_by("summary")))

        # date order
        self.assertEqual(pks(self.queryset.order_by("-date")),
                         pks(Document.objects.order_by("-date")))
示例#15
0
    def test_order_by(self):
        # private order
        self.assertEqual(pks(self.queryset.order_by("-django_id")),
                         pks(Document.objects.order_by("-id")))

        # value order
        self.assertEqual(pks(self.queryset.order_by("number")),
                         pks(Document.objects.order_by("number")))

        # text order
        self.assertEqual(pks(self.queryset.order_by("summary")),
                         pks(Document.objects.order_by("summary")))

        # date order
        self.assertEqual(pks(self.queryset.order_by("-date")),
                         pks(Document.objects.order_by("-date")))
示例#16
0
    def test_field_in(self):
        self.assertEqual(set(pks(self.queryset.filter(name__in=['magazine 2', 'article 4']))),
                         set(pks(Document.objects.filter(name__in=['magazine 2', 'article 4']))))

        self.assertEqual(pks(self.queryset.filter(number__in=[4])),
                         pks(Document.objects.filter(number__in=[4])))

        self.assertEqual(pks(self.queryset.filter(number__in=[4, 8])),
                         pks(Document.objects.filter(number__in=[4, 8])))
示例#17
0
    def test_field_in(self):
        self.assertEqual(
            set(pks(
                self.queryset.filter(name__in=['magazine 2', 'article 4']))),
            set(
                pks(
                    Document.objects.filter(
                        name__in=['magazine 2', 'article 4']))))

        self.assertEqual(pks(self.queryset.filter(number__in=[4])),
                         pks(Document.objects.filter(number__in=[4])))

        self.assertEqual(pks(self.queryset.filter(number__in=[4, 8])),
                         pks(Document.objects.filter(number__in=[4, 8])))
示例#18
0
    def test_auto_query(self):
        # todo: improve to query text only.
        self.assertEqual(set(pks(self.queryset.auto_query("huge OR medium"))),
                         set(pks(Document.objects.filter(Q(text__contains="huge") |
                                                         Q(text__contains="medium")))))

        self.assertEqual(set(pks(self.queryset.auto_query("huge AND medium"))),
                         set(pks(Document.objects.filter(Q(text__contains="huge") &
                                                         Q(text__contains="medium")))))

        self.assertEqual(set(pks(self.queryset.auto_query("text:huge text:-this"))),
                         set(pks(Document.objects.filter(Q(text__contains="huge") &
                                                         ~Q(text__contains="this")))))

        self.assertEqual(len(self.queryset.filter(name=AutoQuery("8 OR 4"))), 2)
        self.assertEqual(len(self.queryset.filter(name=AutoQuery("8 AND 4"))), 0)
示例#19
0
 def test_field_or(self):
     self.assertEqual(pks(self.queryset.filter(name='8 4')), [2, 4])
示例#20
0
 def test_field_and(self):
     self.assertEqual(pks(self.queryset.filter(name='8').filter(name='4')),
                      [])
示例#21
0
 def test_non_ascii_search(self):
     """
     Regression test for #119.
     """
     self.assertEqual(pks(self.queryset.filter(content='corrup\xe7\xe3o')),
                      pks(Document.objects.filter(summary__contains='corrup\xe7\xe3o')))
示例#22
0
    def test_value_range(self):
        self.assertEqual(set(pks(self.queryset.filter(number__lt=3))),
                         set(pks(Document.objects.filter(number__lt=3))))

        self.assertEqual(set(pks(self.queryset.filter(django_id__gte=6))),
                         set(pks(Document.objects.filter(id__gte=6))))
示例#23
0
    def test_content_search(self):
        result = self.queryset.filter(content='medium this')
        self.assertEqual(sorted(pks(result)), pks(Document.objects.all()))

        # documents with "medium" AND "this" have higher score
        self.assertEqual(pks(result)[:4], [1, 4, 7, 10])
示例#24
0
 def test_field_or(self):
     self.assertEqual(pks(self.queryset.filter(name='8 4')), [2, 4])
示例#25
0
 def test_field_startswith(self):
     self.assertEqual(len(self.queryset.filter(name__startswith='magaz')), 4)
     self.assertEqual(set(pks(self.queryset.filter(text__startswith='This is'))),
                      set(pks(Document.objects.filter(text__startswith='This is'))))
示例#26
0
    def test_value_range(self):
        self.assertEqual(set(pks(self.queryset.filter(number__lt=3))),
                         set(pks(Document.objects.filter(number__lt=3))))

        self.assertEqual(set(pks(self.queryset.filter(django_id__gte=6))),
                         set(pks(Document.objects.filter(id__gte=6))))
示例#27
0
 def test_field_exact(self):
     self.assertEqual(pks(self.queryset.filter(name__exact='8')), [])
     self.assertEqual(pks(self.queryset.filter(name__exact='magazine 2')), [1])
示例#28
0
 def test_field_and(self):
     self.assertEqual(pks(self.queryset.filter(name='8').filter(name='4')), [])
示例#29
0
 def test_content_exact(self):
     self.assertEqual(pks(self.queryset.filter(content__exact='huge')), [])
示例#30
0
 def test_content_exact(self):
     self.assertEqual(pks(self.queryset.filter(content__exact='huge')), [])
示例#31
0
 def test_field_exact(self):
     self.assertEqual(pks(self.queryset.filter(name__exact='8')), [])
     self.assertEqual(pks(self.queryset.filter(name__exact='magazine 2')),
                      [1])
示例#32
0
    def test_content_and(self):
        self.assertEqual(pks(self.queryset.filter(content='huge').filter(summary='medium')), [])

        self.assertEqual(len(self.queryset.filter(content='huge this')), 12)
        self.assertEqual(len(self.queryset.filter(content='huge this').filter(summary='huge')), 4)