Exemplo n.º 1
0
 def update_links_and_data(self, old_redir, new_redir, old_data, new_data, dont_defer):
     if dont_defer:
         self.update_links(old_redir, new_redir)
         SchemaDataIndex.update_index(self.title, old_data, new_data)
     else:
         deferred.defer(self.update_links, old_redir, new_redir)
         deferred.defer(SchemaDataIndex.update_index, self.title, old_data, new_data)
Exemplo n.º 2
0
 def test_schema_index_create(self):
     page = WikiPage.get_by_title(u"Hello")
     page.update_content(u".schema Book\n[[author::AK]]\n{{isbn::123456789}}\n[[datePublished::2013]]", 0)
     page.rebuild_data_index()
     self.assertEqual(
         1,
         SchemaDataIndex.query(
             SchemaDataIndex.title == u"Hello", SchemaDataIndex.name == u"author", SchemaDataIndex.value == u"AK"
         ).count(),
     )
     self.assertEqual(
         1,
         SchemaDataIndex.query(
             SchemaDataIndex.title == u"Hello",
             SchemaDataIndex.name == u"isbn",
             SchemaDataIndex.value == u"123456789",
         ).count(),
     )
     self.assertEqual(
         1,
         SchemaDataIndex.query(
             SchemaDataIndex.title == u"Hello",
             SchemaDataIndex.name == u"datePublished",
             SchemaDataIndex.value == u"2013",
         ).count(),
     )
Exemplo n.º 3
0
 def test_update(self):
     self.update_page(u'.schema Book\n[[author::AK]]\n{{isbn::1234567890}}\n[[datePublished::2013]]', u'Hello')
     self.update_page(u'.schema Book\n[[author::AK]]\n{{isbn::1234567899}}\n[[dateModified::2013]]', u'Hello')
     self.assertTrue(SchemaDataIndex.has_match(u'Hello', u'author', u'AK'))
     self.assertFalse(SchemaDataIndex.has_match(u'Hello', u'isbn', u'1234567890'))
     self.assertTrue(SchemaDataIndex.has_match(u'Hello', u'isbn', u'1234567899'))
     self.assertFalse(SchemaDataIndex.has_match(u'Hello', u'datePublished', u'2013'))
     self.assertTrue(SchemaDataIndex.has_match(u'Hello', u'dateModified', u'2013'))
Exemplo n.º 4
0
 def update_links_and_data(self, old_redir, new_redir, old_data, new_data,
                           dont_defer):
     if dont_defer:
         self.update_links(old_redir, new_redir)
         SchemaDataIndex.update_index(self.title, old_data, new_data)
     else:
         deferred.defer(self.update_links, old_redir, new_redir)
         deferred.defer(SchemaDataIndex.update_index, self.title, old_data,
                        new_data)
Exemplo n.º 5
0
 def test_create(self):
     self.update_page(
         u'.schema Book\n[[author::AK]]\n{{isbn::1234567890}}\n[[datePublished::2013]]',
         u'Hello')
     self.assertTrue(SchemaDataIndex.has_match(u'Hello', u'author', u'AK'))
     self.assertTrue(
         SchemaDataIndex.has_match(u'Hello', u'isbn', u'1234567890'))
     self.assertTrue(
         SchemaDataIndex.has_match(u'Hello', u'datePublished', u'2013'))
Exemplo n.º 6
0
 def test_rebuild(self):
     page = self.update_page(
         u'.schema Book\n[[author::AK]]\n{{isbn::1234567890}}\n[[datePublished::2013]]',
         u'Hello')
     SchemaDataIndex.rebuild_index(page.title, page.data)
     self.assertTrue(SchemaDataIndex.has_match(u'Hello', u'author', u'AK'))
     self.assertTrue(
         SchemaDataIndex.has_match(u'Hello', u'isbn', u'1234567890'))
     self.assertTrue(
         SchemaDataIndex.has_match(u'Hello', u'datePublished', u'2013'))
Exemplo n.º 7
0
    def rebuild_all_data_index(cls, page_index=0):
        logging.debug('Rebuilding data index: %d' % page_index)

        batch_size = 20
        all_pages = list(cls.query().fetch(batch_size, offset=page_index * batch_size))
        if len(all_pages) == 0:
            logging.debug('Rebuilding data index: Finished!')
            return

        [SchemaDataIndex.rebuild_index(p.title, p.data) for p in all_pages]
        deferred.defer(cls.rebuild_all_data_index, page_index + 1)
Exemplo n.º 8
0
    def rebuild_all_data_index(cls, page_index=0):
        logging.debug('Rebuilding data index: %d' % page_index)

        batch_size = 20
        all_pages = list(cls.query().fetch(batch_size,
                                           offset=page_index * batch_size))
        if len(all_pages) == 0:
            logging.debug('Rebuilding data index: Finished!')
            return

        [SchemaDataIndex.rebuild_index(p.title, p.data) for p in all_pages]
        deferred.defer(cls.rebuild_all_data_index, page_index + 1)
Exemplo n.º 9
0
 def test_schema_index_create(self):
     page = WikiPage.get_by_title(u'Hello')
     page.update_content(
         u'.schema Book\n[[author::AK]]\n{{isbn::123456789}}\n[[datePublished::2013]]',
         0)
     page.rebuild_data_index()
     self.assertEqual(
         1,
         SchemaDataIndex.query(SchemaDataIndex.title == u'Hello',
                               SchemaDataIndex.name == u'author',
                               SchemaDataIndex.value == u'AK').count())
     self.assertEqual(
         1,
         SchemaDataIndex.query(
             SchemaDataIndex.title == u'Hello',
             SchemaDataIndex.name == u'isbn',
             SchemaDataIndex.value == u'123456789').count())
     self.assertEqual(
         1,
         SchemaDataIndex.query(SchemaDataIndex.title == u'Hello',
                               SchemaDataIndex.name == u'datePublished',
                               SchemaDataIndex.value == u'2013').count())
Exemplo n.º 10
0
 def test_should_not_index_for_longtext(self):
     self.update_page(u'longDescription::---\n\nHello there', u'Hello')
     self.assertFalse(SchemaDataIndex.has_match(u'Hello', u'longDescription', u'Hello there'))
Exemplo n.º 11
0
 def test_rebuild(self):
     page = self.update_page(u'.schema Book\n[[author::AK]]\n{{isbn::1234567890}}\n[[datePublished::2013]]', u'Hello')
     SchemaDataIndex.rebuild_index(page.title, page.data)
     self.assertTrue(SchemaDataIndex.has_match(u'Hello', u'author', u'AK'))
     self.assertTrue(SchemaDataIndex.has_match(u'Hello', u'isbn', u'1234567890'))
     self.assertTrue(SchemaDataIndex.has_match(u'Hello', u'datePublished', u'2013'))
Exemplo n.º 12
0
 def _evaluate_page_query_term(cls, name, value):
     if name == 'schema' and value.find('/') == -1:
         value = schema.get_itemtype_path(value)
     return SchemaDataIndex.query_titles(name, value)
Exemplo n.º 13
0
 def _evaluate_page_query_term(cls, name, value):
     if name == 'schema' and value.find('/') == -1:
         value = schema.get_itemtype_path(value)
     return SchemaDataIndex.query_titles(name, value)
Exemplo n.º 14
0
 def test_should_not_index_for_longtext(self):
     self.update_page(u'longDescription::---\n\nHello there', u'Hello')
     self.assertFalse(
         SchemaDataIndex.has_match(u'Hello', u'longDescription',
                                   u'Hello there'))