Exemplo n.º 1
0
    def setUp(self):
        self._vocabulary = Vocabulary.Vocabulary('Vocabulary',
                                                 'Vocabulary',
                                                 globbing=1)

        col1 = FieldIndex('col1')
        col2 = TextIndex('col2')
        col3 = KeywordIndex('col3')

        self._catalog = Catalog()
        self._catalog.addIndex('col1', col1)
        self._catalog.addIndex('col2', col2)
        self._catalog.addIndex('col3', col3)
        self._catalog.addColumn('col1')
        self._catalog.addColumn('col2')
        self._catalog.addColumn('col3')

        att1 = FieldIndex('att1')
        att2 = TextIndex('att2')
        att3 = KeywordIndex('att3')
        num = FieldIndex('num')

        self._catalog.addIndex('att1', att1)
        self._catalog.addIndex('att2', att2)
        self._catalog.addIndex('att3', att3)
        self._catalog.addIndex('num', num)
        self._catalog.addColumn('att1')
        self._catalog.addColumn('att2')
        self._catalog.addColumn('att3')
        self._catalog.addColumn('num')

        for x in range(0, self.upper):
            self._catalog.catalogObject(dummy(self.nums[x]), ` x `)
        self._catalog.aq_parent = dummy('foo')  # fake out acquisition
Exemplo n.º 2
0
    def setUp(self):
        self._catalog = self._makeOne()
        self._catalog.lexicon = PLexicon('lexicon')
        col1 = FieldIndex('col1')
        col2 = ZCTextIndex('col2', caller=self._catalog,
                          index_factory=OkapiIndex, lexicon_id='lexicon')
        col3 = KeywordIndex('col3')

        self._catalog.addIndex('col1', col1)
        self._catalog.addIndex('col2', col2)
        self._catalog.addIndex('col3', col3)
        self._catalog.addColumn('col1')
        self._catalog.addColumn('col2')
        self._catalog.addColumn('col3')

        att1 = FieldIndex('att1')
        att2 = ZCTextIndex('att2', caller=self._catalog,
                          index_factory=OkapiIndex, lexicon_id='lexicon')
        att3 = KeywordIndex('att3')
        num = FieldIndex('num')

        self._catalog.addIndex('att1', att1)
        self._catalog.addIndex('att2', att2)
        self._catalog.addIndex('att3', att3)
        self._catalog.addIndex('num', num)
        self._catalog.addColumn('att1')
        self._catalog.addColumn('att2')
        self._catalog.addColumn('att3')
        self._catalog.addColumn('num')

        for x in range(0, self.upper):
            self._catalog.catalogObject(dummy(self.nums[x]), repr(x))
        self._catalog = self._catalog.__of__(dummy('foo'))
Exemplo n.º 3
0
    def setUp(self):
        from Products.PluginIndexes.KeywordIndex.KeywordIndex \
                import KeywordIndex

        NodeAdapterTestCase.setUp(self)
        self._obj = KeywordIndex('foo_keyword')
        self._XML = _KEYWORD_XML
Exemplo n.º 4
0
    def setUp(self):
        self._index = KeywordIndex('foo')
        self._marker = []
        self._values = [(0, Dummy(['a'])),
                        (1, Dummy(['a', 'b'])),
                        (2, Dummy(['a', 'b', 'c'])),
                        (3, Dummy(['a', 'b', 'c', 'a'])),
                        (4, Dummy(['a', 'b', 'c', 'd'])),
                        (5, Dummy(['a', 'b', 'c', 'e'])),
                        (6, Dummy(['a', 'b', 'c', 'e', 'f'])),
                        (7, Dummy([0])),
                       ]
        self._noop_req = {'bar': 123}
        self._all_req = {'foo': ['a']}
        self._some_req = {'foo': ['e']}
        self._overlap_req = {'foo': ['c', 'e']}
        self._string_req = {'foo': 'a'}
        self._zero_req = {'foo': [0]}

        self._not_1 = {'foo': {'query': 'f', 'not': 'f'}}
        self._not_2 = {'foo': {'query': ['e', 'f'], 'not': 'f'}}
        self._not_3 = {'foo': {'not': 0}}
        self._not_4 = {'foo': {'not': [0, 'e']}}
        self._not_5 = {'foo': {'not': [0, 'no-value']}}
        self._not_6 = {'foo': 'c', 'bar': {'query': 123, 'not': 1}}
Exemplo n.º 5
0
 def setUp(self):
     self._indexes = [
         FieldIndex('review_state'),
         FieldIndex('portal_type'),
         BooleanIndex('is_default_page'),
         KeywordIndex('subject', extra={'indexed_attrs':
                                        'keyword,subject'}),
         CompositeIndex('comp01',
                        extra=[{
                            'id': 'portal_type',
                            'meta_type': 'FieldIndex',
                            'attributes': ''
                        }, {
                            'id': 'review_state',
                            'meta_type': 'FieldIndex',
                            'attributes': ''
                        }, {
                            'id': 'is_default_page',
                            'meta_type': 'BooleanIndex',
                            'attributes': ''
                        }, {
                            'id': 'subject',
                            'meta_type': 'KeywordIndex',
                            'attributes': 'keyword,subject'
                        }])
     ]
Exemplo n.º 6
0
 def _add_indexes(self):
     num = FieldIndex('num')
     self.zcat._catalog.addIndex('num', num)
     big = FieldIndex('big')
     self.zcat._catalog.addIndex('big', big)
     numbers = KeywordIndex('numbers')
     self.zcat._catalog.addIndex('numbers', numbers)
Exemplo n.º 7
0
    def setUp(self):
        """Custom setup for tests."""
        self.portal = self.layer['portal']

        from plone.app.vocabularies.tests import base
        context = base.create_context()
        rids = ('1', '2',)
        tool = base.DummyCatalog(rids)
        context.portal_catalog = tool
        context.portal_url = base.DummyUrlTool(context)

        from Products.PluginIndexes.KeywordIndex.KeywordIndex import KeywordIndex  # noqa
        kwindex = KeywordIndex('Subject')
        tool.indexes['Subject'] = kwindex
        from Products.ExtendedPathIndex.ExtendedPathIndex import ExtendedPathIndex  # noqa
        pathindex = ExtendedPathIndex('path')
        tool.indexes['path'] = pathindex

        self.subjects_1 = ['Berlin', 'Wien', 'Paris', 'Barcelona']
        self.subjects_2 = ['Montreal', 'Washington', 'Brasilia']

        self.navroot1 = base.DummyContentWithParent('nr1', parent=context)
        alsoProvides(self.navroot1, INavigationRoot)
        self.navroot2 = base.DummyContentWithParent('nr2', parent=context)
        alsoProvides(self.navroot2, INavigationRoot)

        self.doc1 = base.DummyContentWithParent(
            'doc1',
            subjects=self.subjects_1,
            parent=self.navroot1
        )
        kwindex._index_object(1, self.doc1, attr='Subject')
        pathindex.index_object(1, self.doc1)

        self.doc2 = base.DummyContentWithParent(
            'doc2',
            subjects=self.subjects_2,
            parent=self.navroot2
        )
        kwindex._index_object(2, self.doc2, attr='Subject')
        pathindex.index_object(2, self.doc2)

        from plone.app.vocabularies.catalog import KeywordsVocabulary
        self.vocab = KeywordsVocabulary()

        # mock our registry
        from plone.registry import Registry
        from plone.registry.interfaces import IRegistry
        from zope.component import getSiteManager
        sm = getSiteManager()
        from Products.CMFCore.interfaces import ICatalogTool
        sm.registerUtility(tool, ICatalogTool)
        registry = Registry()
        sm.registerUtility(registry, IRegistry)
        from Products.CMFCore.interfaces import IURLTool
        sm.registerUtility(context.portal_url, IURLTool)
        registry_patcher = mock.patch('plone.registry.registry.Registry.get')
        self.addCleanup(registry_patcher.stop)
        self.registry_mock = registry_patcher.start()
Exemplo n.º 8
0
def recreateCatalog(self, zcm, lang):

    #-- Create catalog
    cat_id = 'catalog_%s' % lang
    root = self.getRootElement()
    if cat_id in root.objectIds():
        root.manage_delObjects([cat_id])
    cat_title = 'Default catalog'
    zcatalog = ZCatalog.ZCatalog(id=cat_id, title=cat_title, container=root)
    root._setObject(zcatalog.id, zcatalog)
    zcatalog = getZCatalog(self, lang)
    writeChangesLog(
        zcatalog, '[recreateCatalog]: ' +
        self.getZMILangStr('MSG_INSERTED') % zcatalog.meta_type)

    #-- Add lexicon
    addLexicon(self, zcatalog)

    #-- Add columns
    for index_name in ['id', 'meta_id'
                       ] + ['zcat_column_%s' % x for x in extra_column_ids]:
        zcatalog.manage_addColumn(index_name)

    #-- Add Indexes (incl. Columns)
    for attr_id in zcm._getAttrIds():
        attr_type = 'string'
        for meta_id in self.getMetaobjIds():
            meta_obj_attr = self.getMetaobjAttr(meta_id, attr_id)
            if meta_obj_attr:
                attr_type = meta_obj_attr['type']
                break
        index_name = 'zcat_index_%s' % attr_id
        index_type = zcm.getConfProperty('ZCatalog.TextIndexType',
                                         'ZCTextIndex')
        if attr_id == 'home_id':
            index_type = KeywordIndex(attr_id)
        elif attr_type == 'date':
            index_type = DateIndex(attr_id)
        extra = None
        if index_type == 'ZCTextIndex':
            extra = Empty()
            extra.doc_attr = index_name
            extra.index_type = 'Okapi BM25 Rank'
            extra.lexicon_id = 'Lexicon'
        elif index_type != 'KeywordIndex':
            extra = {}
            extra['default_encoding'] = 'utf-8'
            extra['indexed_fields'] = index_name
            extra['fields'] = [index_name]
            extra['near_distance'] = 5
            extra['splitter_casefolding'] = 1
            extra['splitter_max_len'] = 64
            extra['splitter_separators'] = '.+-_@'
            extra['splitter_single_chars'] = 0
        zcatalog.manage_addColumn(index_name)
        zcatalog.manage_addIndex(index_name, index_type, extra)
Exemplo n.º 9
0
 def testAddWithSpace(self):
     idx = KeywordIndex(' space ')
     self._catalog.addIndex(' space ', idx)
     self.assertEqual(' space ' not in self._catalog.indexes, True,
                      'space not stripped in add index')
     self.assertEqual('space' in self._catalog.indexes, True,
                      'stripping space in add index failed')
     i = self._catalog.indexes['space']
     # Note: i.id still has spaces in it.
     self.assert_(isinstance(i, KeywordIndex))
Exemplo n.º 10
0
    def setUp(self):
        import Products.GenericSetup.PluginIndexes
        from Products.PluginIndexes.KeywordIndex.KeywordIndex \
                import KeywordIndex

        NodeAdapterTestCase.setUp(self)
        zcml.load_config('configure.zcml', Products.GenericSetup.PluginIndexes)

        self._obj = KeywordIndex('foo_keyword')
        self._XML = _KEYWORD_XML
Exemplo n.º 11
0
 def _add_indexes(self):
     from Products.PluginIndexes.FieldIndex.FieldIndex import FieldIndex
     from Products.PluginIndexes.KeywordIndex.KeywordIndex import \
         KeywordIndex
     num = FieldIndex('num')
     self.zcat._catalog.addIndex('num', num)
     big = FieldIndex('big')
     self.zcat._catalog.addIndex('big', big)
     numbers = KeywordIndex('numbers')
     self.zcat._catalog.addIndex('numbers', numbers)
Exemplo n.º 12
0
    def setUp(self):
        from Products.PluginIndexes.KeywordIndex.KeywordIndex \
                import KeywordIndex

        PlacelessSetup.setUp(self)
        zcml.load_config('meta.zcml', Products.Five)
        zcml.load_config('configure.zcml', Products.GenericSetup.PluginIndexes)

        self._obj = KeywordIndex('foo_keyword')
        self._XML = _KEYWORD_XML
Exemplo n.º 13
0
 def test_add_with_space(self):
     catalog = self._make_one()
     idx = KeywordIndex(' space ')
     catalog.addIndex(' space ', idx)
     self.assertNotIn(' space ', catalog.indexes,
                      'space not stripped in add index')
     self.assertIn('space', catalog.indexes,
                   'stripping space in add index failed')
     i = catalog.indexes['space']
     # Note: i.id still has spaces in it.
     self.assertIsInstance(i, KeywordIndex)
Exemplo n.º 14
0
 def _make_catalog(self):
     zcat = ZCatalog('catalog')
     zcat._catalog.addIndex('big', BooleanIndex('big'))
     zcat._catalog.addIndex('date', DateRangeIndex('date', 'start', 'end'))
     zcat._catalog.addIndex('num', FieldIndex('num'))
     zcat._catalog.addIndex('numbers', KeywordIndex('numbers'))
     zcat._catalog.addIndex('path', PathIndex('getPhysicalPath'))
     zcat._catalog.addIndex('uuid', UUIDIndex('num'))
     for i in range(9):
         obj = Dummy(i)
         zcat.catalog_object(obj, str(i))
     return zcat
Exemplo n.º 15
0
    def __init__(self, id='Help', title=''):
        self.id = id
        self.title = title
        c = self.catalog = ZCatalog('catalog')

        l = PLexicon('lexicon', '', HTMLWordSplitter(), CaseNormalizer(),
                     StopWordRemover())
        c._setObject('lexicon', l)
        i = ZCTextIndex('SearchableText',
                        caller=c,
                        index_factory=OkapiIndex,
                        lexicon_id=l.id)
        # not using c.addIndex because it depends on Product initialization
        c._catalog.addIndex('SearchableText', i)
        c._catalog.addIndex('categories', KeywordIndex('categories'))
        c._catalog.addIndex('permissions', KeywordIndex('permissions'))
        c.addColumn('categories')
        c.addColumn('permissions')
        c.addColumn('title_or_id')
        c.addColumn('url')
        c.addColumn('id')
Exemplo n.º 16
0
    def addIndex(self):
        context = getSite()
        sm = context.getSiteManager()
        sm.registerAdapter(TaxonomyIndexer(self.field_name, self.name),
                           (IDexterityContent, IZCatalog),
                           IIndexer,
                           name=self.field_name)

        catalog = getToolByName(context, 'portal_catalog')
        idx_object = KeywordIndex(str(self.field_name))
        try:
            catalog.addIndex(self.field_name, idx_object)
        except CatalogError:
            logging.info("Index " + self.field_name +
                         " already exists, we hope it is proper configured")
Exemplo n.º 17
0
    def _make_one(self):
        from Products.ZCatalog.Catalog import Catalog
        catalog = Catalog()
        catalog.lexicon = PLexicon('lexicon')
        att1 = FieldIndex('att1')
        att2 = ZCTextIndex('att2', caller=catalog,
                           index_factory=OkapiIndex, lexicon_id='lexicon')
        att3 = KeywordIndex('att3')
        catalog.addIndex('att1', att1)
        catalog.addIndex('att2', att2)
        catalog.addIndex('att3', att3)

        for x in range(0, self.upper):
            catalog.catalogObject(Dummy(x), repr(x))
        return catalog.__of__(Dummy('foo'))
Exemplo n.º 18
0
 def setUp(self):
     """
     """
     self._index = KeywordIndex('foo')
     self._marker = []
     self._values = [(0, Dummy(['a'])), (1, Dummy(['a', 'b'])),
                     (2, Dummy(['a', 'b', 'c'])),
                     (3, Dummy(['a', 'b', 'c', 'a'])),
                     (4, Dummy(['a', 'b', 'c', 'd'])),
                     (5, Dummy(['a', 'b', 'c', 'e'])),
                     (6, Dummy(['a', 'b', 'c', 'e', 'f'])), (7, Dummy([0]))]
     self._noop_req = {'bar': 123}
     self._all_req = {'foo': ['a']}
     self._some_req = {'foo': ['e']}
     self._overlap_req = {'foo': ['c', 'e']}
     self._string_req = {'foo': 'a'}
     self._zero_req = {'foo': [0]}
Exemplo n.º 19
0
    def test_KeywordIndex(self):
        from xml.dom.minidom import parseString
        from Products.PluginIndexes.KeywordIndex.KeywordIndex \
                import KeywordIndex
        from Products.GenericSetup.testing import DummySetupEnviron
        from Products.GenericSetup.PluginIndexes.exportimport \
                import PluggableIndexNodeAdapter
        environ = DummySetupEnviron()

        def _no_clear(*a):
            raise AssertionError("Don't clear me!")

        index = KeywordIndex('foo_keyword')
        index.indexed_attrs = ['bar']
        index.clear = _no_clear
        adapted = PluggableIndexNodeAdapter(index, environ)
        adapted.node = parseString(_KEYWORD_XML).documentElement  # no raise
    def setUp(self):
        ZCatalogBase.setUp(self)

        self._catalog.resolve_path = self._resolve_num
        from Products.PluginIndexes.KeywordIndex.KeywordIndex import \
            KeywordIndex
        title = KeywordIndex('title')
        self._catalog.addIndex('title', title)
        self._catalog.addColumn('title')

        self.upper = 10
        self.d = {}
        for x in range(0, self.upper):
            # make uid a string of the number
            ob = ZDummy(x)
            self.d[str(x)] = ob
            self._catalog.catalog_object(ob, str(x))
Exemplo n.º 21
0
    def addIndex(self):
        context = getSite()
        sm = context.getSiteManager()
        sm.registerAdapter(
            TaxonomyIndexer(self.field_name, self.vocabulary_name),
            (IDexterityContent, IZCatalog),
            IIndexer,
            name=self.field_name,
        )

        catalog = getToolByName(context, "portal_catalog")
        idx_object = KeywordIndex(str(self.field_name))
        try:
            catalog.addIndex(self.field_name, idx_object)
        except CatalogError:
            logging.info(
                "Index {0} already exists, we hope it is proper configured".format(  # noqa: E501
                    self.field_name
                )
            )
Exemplo n.º 22
0
 def _make_catalog(self):
     from Products.PluginIndexes.BooleanIndex.BooleanIndex import \
         BooleanIndex
     from Products.PluginIndexes.DateRangeIndex.DateRangeIndex import \
         DateRangeIndex
     from Products.PluginIndexes.FieldIndex.FieldIndex import FieldIndex
     from Products.PluginIndexes.KeywordIndex.KeywordIndex import \
         KeywordIndex
     from Products.PluginIndexes.PathIndex.PathIndex import PathIndex
     from Products.PluginIndexes.UUIDIndex.UUIDIndex import UUIDIndex
     from Products.ZCatalog.ZCatalog import ZCatalog
     zcat = ZCatalog('catalog')
     zcat._catalog.addIndex('big', BooleanIndex('big'))
     zcat._catalog.addIndex('date', DateRangeIndex('date', 'start', 'end'))
     zcat._catalog.addIndex('num', FieldIndex('num'))
     zcat._catalog.addIndex('numbers', KeywordIndex('numbers'))
     zcat._catalog.addIndex('path', PathIndex('getPhysicalPath'))
     zcat._catalog.addIndex('uuid', UUIDIndex('num'))
     for i in range(9):
         obj = dummy(i)
         zcat.catalog_object(obj, str(i))
     return zcat
Exemplo n.º 23
0
 def testDelKeywordIndex(self):
     idx = KeywordIndex('id')
     self._catalog.addIndex('id', idx)
     self._catalog.delIndex('id')
     self.assert_(
         self._catalog.indexes.has_key('id') != 1, 'del index failed')
Exemplo n.º 24
0
 def testDelKeywordIndex(self):
     idx = KeywordIndex('id')
     self._catalog.addIndex('id', idx)
     self._catalog.delIndex('id')
     self.assert_('id' not in self._catalog.indexes,
                  'del index failed')
Exemplo n.º 25
0
 def testAddKeywordIndex(self):
     idx = KeywordIndex('id')
     self._catalog.addIndex('id', idx)
     i = self._catalog.indexes['id']
     self.assert_(isinstance(i, type(KeywordIndex('id'))),
                  'add kw index failed')
Exemplo n.º 26
0
    def setUp(self):
        from Products.PluginIndexes.KeywordIndex.KeywordIndex \
                import KeywordIndex

        self._obj = KeywordIndex('foo_keyword')
        self._XML = _KEYWORD_XML
Exemplo n.º 27
0
 def test_del_keyword_index(self):
     catalog = self._make_one()
     idx = KeywordIndex('id')
     catalog.addIndex('id', idx)
     catalog.delIndex('id')
     self.assert_('id' not in catalog.indexes)
Exemplo n.º 28
0
 def test_add_keyword_index(self):
     catalog = self._make_one()
     idx = KeywordIndex('id')
     catalog.addIndex('id', idx)
     i = catalog.indexes['id']
     self.assert_(isinstance(i, KeywordIndex))