當前位置: 首頁>>代碼示例>>Python>>正文


Python CatalogTool.addIndex方法代碼示例

本文整理匯總了Python中Products.CMFCore.CatalogTool.CatalogTool.addIndex方法的典型用法代碼示例。如果您正苦於以下問題:Python CatalogTool.addIndex方法的具體用法?Python CatalogTool.addIndex怎麽用?Python CatalogTool.addIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Products.CMFCore.CatalogTool.CatalogTool的用法示例。


在下文中一共展示了CatalogTool.addIndex方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _initSite

# 需要導入模塊: from Products.CMFCore.CatalogTool import CatalogTool [as 別名]
# 或者: from Products.CMFCore.CatalogTool.CatalogTool import addIndex [as 別名]
    def _initSite(self, foo=2):
        site = Folder(id='site').__of__(self.app)
        ctool = CatalogTool()
        getSiteManager().registerUtility(ctool, ICatalogTool)

        for obj_id in ctool.objectIds():
            ctool._delObject(obj_id)
        for idx_id in ctool.indexes():
            ctool.delIndex(idx_id)
        for col in ctool.schema()[:]:
            ctool.delColumn(col)

        if foo > 0:
            ctool._setObject('foo_plexicon', PLexicon('foo_plexicon'))
            lex = ctool.foo_plexicon
            lex._pipeline = (Splitter(), CaseNormalizer(), StopWordRemover())

            extra = _extra()
            extra.lexicon_id = 'foo_plexicon'
            extra.index_type = 'Okapi BM25 Rank'
            ctool.addIndex('foo_zctext', 'ZCTextIndex', extra)

            ctool.addColumn('foo_zctext')

        return site, ctool
開發者ID:goschtl,項目名稱:zope,代碼行數:27,代碼來源:test_catalog.py

示例2: UniqueIdHandlerTests

# 需要導入模塊: from Products.CMFCore.CatalogTool import CatalogTool [as 別名]
# 或者: from Products.CMFCore.CatalogTool.CatalogTool import addIndex [as 別名]
class UniqueIdHandlerTests(SecurityTest):

    def _getTargetClass(self):
        from Products.CMFUid.UniqueIdHandlerTool import UniqueIdHandlerTool

        return UniqueIdHandlerTool

    def _makeOne(self, *args, **kw):
        return self._getTargetClass()(*args, **kw)

    def setUp(self):
        from Products.CMFCore.CatalogTool import CatalogTool
        from Products.CMFUid.interfaces import IUniqueIdHandler
        from Products.CMFUid.UniqueIdAnnotationTool \
                import UniqueIdAnnotationTool
        from Products.CMFUid.UniqueIdGeneratorTool \
                import UniqueIdGeneratorTool

        SecurityTest.setUp(self)
        self.app._setObject('dummy', DummyContent(id='dummy'))
        self.app._setObject('dummy2', DummyContent(id='dummy2'))
        self.ctool = CatalogTool().__of__(self.app)
        self.uidhandler = self._makeOne()
        sm = getSiteManager()
        sm.registerUtility(self.ctool, ICatalogTool)
        sm.registerUtility(self.uidhandler, IUniqueIdHandler)
        sm.registerUtility(UniqueIdAnnotationTool(),
                           IUniqueIdAnnotationManagement)
        sm.registerUtility(UniqueIdGeneratorTool(), IUniqueIdGenerator)

        # Make sure we have our indices/columns
        uid_name = self.uidhandler.UID_ATTRIBUTE_NAME
        self.ctool.addIndex(uid_name, 'FieldIndex')
        self.ctool.addColumn(uid_name)

    def tearDown(self):
        cleanUp()
        SecurityTest.tearDown(self)

    def test_interfaces(self):
        from Products.CMFUid.interfaces import IUniqueIdBrainQuery
        from Products.CMFUid.interfaces import IUniqueIdHandler
        from Products.CMFUid.interfaces import IUniqueIdUnrestrictedQuery

        verifyClass(IUniqueIdBrainQuery, self._getTargetClass())
        verifyClass(IUniqueIdHandler, self._getTargetClass())
        verifyClass(IUniqueIdUnrestrictedQuery, self._getTargetClass())

    def test_getUidOfNotYetRegisteredObject(self):
        handler = self.uidhandler
        dummy = self.app.dummy
        UniqueIdError = handler.UniqueIdError

        self.assertEqual(handler.queryUid(dummy, None), None)
        self.assertRaises(UniqueIdError, handler.getUid, dummy)

    def test_getInvalidUid(self):
        handler = self.uidhandler
        dummy = self.app.dummy
        UniqueIdError = handler.UniqueIdError

        self.assertEqual(handler.queryObject(100, None), None)
        self.assertRaises(UniqueIdError, handler.getObject, 100)
        self.assertEqual(handler.unrestrictedQueryObject(100, None), None)
        self.assertRaises(UniqueIdError, handler.unrestrictedGetObject, 100)

        uid = handler.register(dummy)
        self.assertEqual(handler.queryObject(uid + 1, None), None)
        self.assertRaises(UniqueIdError, handler.getObject, uid + 1)
        self.assertEqual(handler.unrestrictedQueryObject(uid + 1, None), None)
        self.assertRaises(UniqueIdError, handler.unrestrictedGetObject, uid + 1)

    def test_getUidOfRegisteredObject(self):
        handler = self.uidhandler
        dummy = self.app.dummy

        uid = handler.register(dummy)
        self.assertEqual(handler.getUid(dummy), uid)

    def test_getRegisteredObjectByUid(self):
        handler = self.uidhandler
        dummy = self.app.dummy

        uid = handler.register(dummy)
        self.assertEqual(handler.getObject(uid), dummy)
        self.assertEqual(handler.unrestrictedGetObject(uid), dummy)

    def test_getUnregisteredObject(self):
        handler = self.uidhandler
        dummy = self.app.dummy
        UniqueIdError = handler.UniqueIdError

        uid = handler.register(dummy)
        handler.unregister(dummy)
        self.assertEqual(handler.queryObject(uid, None), None)
        self.assertRaises(UniqueIdError, handler.getObject, uid)
        self.assertEqual(handler.unrestrictedQueryObject(uid, None), None)
        self.assertRaises(UniqueIdError, handler.unrestrictedGetObject, uid)

    def test_getUidOfUnregisteredObject(self):
#.........這裏部分代碼省略.........
開發者ID:goschtl,項目名稱:zope,代碼行數:103,代碼來源:test_uidhandling.py


注:本文中的Products.CMFCore.CatalogTool.CatalogTool.addIndex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。