Esempio n. 1
0
    def test_len(self):
        self.assertEqual(len(QuerySet(DocumentIndex)), 100)
        self.assertEqual(QuerySet(DocumentIndex).count(), 100)

        self.assertEqual(len(QuerySet(DocumentIndex).search('@text adasdsa')),
                         0)
        self.assertEqual(
            QuerySet(DocumentIndex).search('@text adasdsa').count(), 0)
Esempio n. 2
0
    def test_order_by(self):
        q = QuerySet(DocumentIndex).order_by(C('number'))
        self.assertEqual(q[0].number, 2)

        q = QuerySet(DocumentIndex).order_by(-C('number'))
        self.assertEqual(q[0].number, 200)

        q = QuerySet(DocumentIndex).search('@text What').order_by(
            C('@relevance'))
        # most relevance is last, because has the most occurrences.
        self.assertEqual(q[0].number, 200)

        # other ordering
        q = QuerySet(DocumentIndex).search('@text What').order_by(C('number'))
        self.assertEqual(q[0].number, 2)
Esempio n. 3
0
    def test_pk_mapping(self):
        django_obj = self.documents.filter(text__icontains='text5').first()
        sphinx_qs = QuerySet(CharPrimaryKeyDocumentIndex).search('@text text5')
        # sleep(1200)
        self.assertEqual(len(sphinx_qs), 1)
        sphinx_obj = sphinx_qs[0]

        self.assertIsNotNone(django_obj)
        self.assertIsNotNone(sphinx_obj)
        self.assertEqual(django_obj.id, sphinx_obj.get_pk())
Esempio n. 4
0
    def test_getitem(self):
        query = QuerySet(DocumentIndex)

        self.assertEqual(len(query), 100)
        self.assertEqual(len(query[:20]), 20)

        self.assertEqual(len(query[90:110]), 10)

        self.assertRaises(NotSupportedError, query.__getitem__,
                          slice(90, None))

        self.assertEqual(query[0].number, 2)
Esempio n. 5
0
    def setUp(self):
        super(SimpleTestCase, self).setUp()

        self.document = Document.objects.create(summary="This is a summary",
                                                text="What a nice text",
                                                date=datetime.date(2015, 2, 2),
                                                added_time=datetime.datetime(
                                                    2015, 4, 4, 12, 12, 12),
                                                number=2)

        # retrieve data as it is stored in DB
        self.document = Document.objects.get(id=self.document.id)

        self.index()

        self.query = QuerySet(DocumentIndex)
Esempio n. 6
0
    def test_filter(self):
        sphinx_query = QuerySet(DocumentIndex).filter(number__gt=30)[:1000]
        django_query = self.documents.filter(number__gt=30)

        self.assertEqual(ids_set(sphinx_query), ids_set(django_query))
Esempio n. 7
0
    def test_iterate(self):
        with self.assertRaises(IndexError):
            iter(QuerySet(DocumentIndex))

        self.assertEqual(len(list(iter(QuerySet(DocumentIndex)[:1000]))), 1000)
Esempio n. 8
0
 def test_count(self):
     self.assertEqual(
         QuerySet(DocumentIndex).count(), self.documents.count())