示例#1
0
 def __call__(self, context):
     catalog = Catalog()
     path = NodeAttributeIndexer('path')
     catalog['path'] = CatalogFieldIndex(path)
     uuid = NodeAttributeIndexer('uuid')
     catalog['uuid'] = CatalogFieldIndex(uuid)
     return catalog
示例#2
0
    def init_catalog(self):
        '''
        Create a repoze.catalog instance and specify
        indices of intereset
        '''        
        catalog = RCatalog()
        catalog.document_map = DocumentMap()                
        # set up indexes
        catalog['title'] = CatalogTextIndex('_get_title')
        catalog['titleSorter'] = CatalogFieldIndex('_get_sorter')
        catalog['collection'] = CatalogKeywordIndex('_get_collection')
        # Descriptions are converted to TEXT for indexing
        catalog['description'] = CatalogTextIndex('_get_description')
        catalog['startDate'] = CatalogFieldIndex('_get_startDate')
        catalog['endDate'] = CatalogFieldIndex('_get_endDate')
        catalog['modificationDate'] = CatalogFieldIndex('_get_modificationDate')
        catalog['fid'] = CatalogTextIndex('_get_fid')
        catalog['keywords'] = CatalogKeywordIndex('_get_keywordsList')
        catalog['category'] = CatalogKeywordIndex('_get_categoryList')
        # I define as Text because I would permit searched for part of names
        catalog['rolesVals'] = CatalogTextIndex('_get_roles')
        catalog['persons'] = CatalogTextIndex('_get_persons')

        # ICTP SPECIFIC: index a deadline date if found. Just COMMENT this line if not interested
        catalog['deadlineDate'] = CatalogFieldIndex('_get_deadlineDate')


        self.db.root()[self.catalogName] = catalog
        self.catalog = self.db.root()[self.catalogName] 
        # commit the indexes
        transaction.commit()
示例#3
0
    def test_it(self):
        from repoze.catalog.catalog import Catalog
        from repoze.catalog.indexes.field import CatalogFieldIndex
        from repoze.catalog.indexes.keyword import CatalogKeywordIndex
        from repoze.catalog.indexes.text import CatalogTextIndex

        catalog = Catalog()
        catalog['name'] = CatalogFieldIndex('name')
        catalog['title'] = CatalogFieldIndex('title')
        catalog['text'] = CatalogTextIndex('text')
        catalog['allowed'] = CatalogKeywordIndex('allowed')

        catalog.index_doc(1, Content('name1', 'title1', 'body one', ['a']))
        catalog.index_doc(2, Content('name2', 'title2', 'body two', ['b']))
        catalog.index_doc(3, Content('name3', 'title3', 'body three', ['c']))
        catalog.index_doc(4, Content('name4', None, 'body four', ['a', 'b']))
        catalog.index_doc(
            5, Content('name5', 'title5', 'body five', ['a', 'b', 'c']))
        catalog.index_doc(6, Content('name6', 'title6', 'body six', ['d']))

        numdocs, result = catalog.query(self.query,
                                        sort_index='name',
                                        limit=5,
                                        names=dict(body='body'))
        self.assertEqual(numdocs, 2)
        self.assertEqual(list(result), [4, 5])
示例#4
0
    def __call__(self, context):
        catalog = Catalog()
        idindexer = NodeAttributeIndexer('id')
        catalog['id'] = CatalogFieldIndex(idindexer)
        searchable_blob = NodeAttributeIndexer('searchable_text')
        catalog['searchable_text'] = CatalogTextIndex(searchable_blob)
        notlegit = NodeAttributeIndexer('notlegit')
        catalog['notlegit'] = CatalogFieldIndex(notlegit)

        userindexer = NodeAttributeIndexer('username')
        catalog['username'] = CatalogTextIndex(userindexer)
        fullname = NodeAttributeIndexer('fullname')
        catalog['fullname'] = CatalogTextIndex(fullname)
        email = NodeAttributeIndexer('email')
        catalog['email'] = CatalogTextIndex(email)
        location = NodeAttributeIndexer('location')
        catalog['location'] = CatalogTextIndex(location)
        dni = NodeAttributeIndexer('dni')
        catalog['dni'] = CatalogTextIndex(dni)
        user_type = NodeAttributeIndexer('user_type')
        catalog['user_type'] = CatalogTextIndex(user_type)
        check_ubicacio = NodeAttributeIndexer('check_ubicacio')
        catalog['check_ubicacio'] = CatalogTextIndex(check_ubicacio)
        ubicacio = NodeAttributeIndexer('ubicacio')
        catalog['ubicacio'] = CatalogTextIndex(ubicacio)
        check_telefon = NodeAttributeIndexer('check_telefon')
        catalog['check_telefon'] = CatalogTextIndex(check_telefon)
        telefon = NodeAttributeIndexer('telefon')
        catalog['telefon'] = CatalogTextIndex(telefon)
        check_twitter_username = NodeAttributeIndexer('check_twitter_username')
        catalog['check_twitter_username'] = CatalogTextIndex(
            check_twitter_username)
        twitter_username = NodeAttributeIndexer('twitter_username')
        catalog['twitter_username'] = CatalogTextIndex(twitter_username)
        return catalog
示例#5
0
 def __call__(self, context: typing.Union[Record, None] = None) -> Catalog:
     catalog = Catalog()
     catalog["uid"] = CatalogFieldIndex(NodeAttributeIndexer("uid"))
     catalog["group"] = CatalogFieldIndex(NodeAttributeIndexer("group"))
     catalog["created"] = CatalogFieldIndex(NodeAttributeIndexer("created"))
     catalog["owner"] = CatalogFieldIndex(NodeAttributeIndexer("owner"))
     catalog["queryparams"] = CatalogFieldIndex(
         NodeAttributeIndexer("queryparams"))
     return catalog
示例#6
0
 def __call__(self, context):
     catalog = Catalog()
     channels_indexer = NodeAttributeIndexer("channels")
     catalog[u"channels"] = CatalogKeywordIndex(channels_indexer)
     date_indexer = NodeAttributeIndexer("date")
     catalog[u"date"] = CatalogFieldIndex(date_indexer)
     title_indexer = NodeAttributeIndexer("title")
     catalog[u"title"] = CatalogTextIndex(title_indexer)
     type_indexer = NodeAttributeIndexer("type")
     catalog[u"type"] = CatalogFieldIndex(type_indexer)
     return catalog
示例#7
0
def bootstrap(zodb_root, app_root_id, request):
    """Setup Root Object and the ZODB Database structure"""

    if not app_root_id in zodb_root:
        # add root folders
        app_root = WebshopAPI()
        zodb_root[app_root_id] = app_root
        zodb_root[app_root_id]["categories"] = Folder()
        zodb_root[app_root_id]["item_groups"] = Folder()
        zodb_root[app_root_id]["items"] = Folder()
        zodb_root[app_root_id]["unit_of_measures"] = Folder()
        zodb_root[app_root_id]["vpe_types"] = Folder()
        # add repoze.catalog for indexing
        app_root["catalog"] = Catalog()
        app_root["catalog"]['parent_id'] = CatalogFieldIndex(get_parent_id)
        app_root["catalog"]['id'] = CatalogFieldIndex(get_id)
        app_root["catalog"]['__type__'] = CatalogFieldIndex(get__type__)
        app_root["catalog"]['group'] = CatalogFieldIndex(get_group)
        app_root["catalog"]['vpe_type_id'] = CatalogFieldIndex(get_vpe_type_id)
        app_root["catalog"]['unit_of_measure_id'] = \
            CatalogFieldIndex(get_unit_of_measure_id)
        app_root["catalog"]['quality_id'] = CatalogFieldIndex(get_quality_id)
        app_root["catalog"]['vpe_default'] = CatalogFieldIndex(get_vpe_default)
        app_root["catalog"]['title_url_slugs'] = CatalogKeywordIndex(
            get_title_url_slugs)
        app_root["catalog"]['shop_id'] = CatalogKeywordIndex(get_shop_ids)
        app_root["document_map"] = DocumentMap()
        transaction.commit()
    return Root(request, zodb_root[app_root_id])
示例#8
0
    def test_with_contents(self):
        def discriminator(value, default):
            return value

        from repoze.catalog.indexes.field import CatalogFieldIndex
        src = CatalogFieldIndex(discriminator)
        src.index_doc(5, 9000)
        src.index_doc(6, 9000)
        src.index_doc(7, 9001)
        src.index_doc(8, 11005)

        obj = self._call(src)

        self.assertEqual(sorted(obj._fwd_index.keys()), [9000, 9001, 11005])
        self.assertEqual(sorted(obj._fwd_index[9000]), [5, 6])
        self.assertEqual(sorted(obj._fwd_index[9001]), [7])
        self.assertEqual(sorted(obj._fwd_index[11005]), [8])
        self.assertEqual(sorted(obj._rev_index.keys()), [5, 6, 7, 8])
        self.assertEqual(obj._rev_index[5], 9000)
        self.assertEqual(obj._rev_index[6], 9000)
        self.assertEqual(obj._rev_index[7], 9001)
        self.assertEqual(obj._rev_index[8], 11005)
        ndx = obj._granular_indexes[0][1]
        self.assertEqual(sorted(ndx.keys()), [9, 11])
        self.assertEqual(sorted(ndx[9]), [5, 6, 7])
        self.assertEqual(sorted(ndx[11]), [8])
        self.assertEqual(obj._num_docs(), 4)
示例#9
0
            def __call__(self, context=None):
                catalog = Catalog()
                r_uid_indexer = NodeAttributeIndexer(REMOTE_UID)
                catalog[unicode(REMOTE_UID)] = CatalogFieldIndex(r_uid_indexer)

                l_uid_indexer = NodeAttributeIndexer(LOCAL_UID)
                catalog[unicode(LOCAL_UID)] = CatalogFieldIndex(l_uid_indexer)

                r_path_indexer = NodeAttributeIndexer(REMOTE_PATH)
                catalog[unicode(REMOTE_PATH)] = CatalogFieldIndex(r_path_indexer)

                l_path_indexer = NodeAttributeIndexer(LOCAL_PATH)
                catalog[unicode(LOCAL_PATH)] = CatalogFieldIndex(l_path_indexer)

                return catalog
示例#10
0
 def __call__(self, context):
     catalog = Catalog()
     groupindexer = NodeAttributeIndexer('id')
     catalog['id'] = CatalogFieldIndex(groupindexer)
     idsearchableindexer = NodeAttributeIndexer('searchable_id')
     catalog['searchable_id'] = CatalogTextIndex(idsearchableindexer)
     return catalog
示例#11
0
 def __call__(self, context):
     catalog = Catalog()
     idindexer = NodeAttributeIndexer('id_menusoup')
     catalog['id_menusoup'] = CatalogTextIndex(idindexer)
     containerindexer = NodeAttributeIndexer('dades')
     catalog['dades'] = CatalogFieldIndex(containerindexer)
     return catalog
示例#12
0
def prep_catalog():
    """Download python mailing list, create new catalog and catalog 
       messages, if not done already.
    """
    if not os.path.exists(BENCHMARK_DATA_DIR):
        os.makedirs(BENCHMARK_DATA_DIR)

    # Check to see if mailing list data already present
    if len(get_mailbox_filenames()) == 0:
        MailListSucker(MAILLIST_INDEX, BENCHMARK_DATA_DIR).suck()

    # Create ZODB and index maillist messages, if not yet done
    zodb_file = os.path.join(BENCHMARK_DATA_DIR, 'test.zodb')
    if not os.path.exists(zodb_file):
        # Create a catalog
        manager = ConnectionManager()
        factory = FileStorageCatalogFactory(
            os.path.join(BENCHMARK_DATA_DIR, 'test.zodb'), 'benchmark')
        c = factory(manager)

        # Create some indices
        c['subject'] = CatalogFieldIndex(get_subject)
        c['date'] = CatalogFieldIndex(get_date)
        c['sender_email'] = CatalogFieldIndex(get_sender_email)
        c['topics'] = CatalogFacetIndex(get_topics, topic_taxonomy)
        c['text'] = CatalogTextIndex(get_text)
        manager.commit()

        # Loop over messages to get base line
        profiler.start("Loop over messages without indexing")
        for _ in MessageIterator():
            pass
        profiler.stop("Loop over messages without indexing")

        profiler.start("Index messages")
        id = 1
        for msg in MessageIterator():
            c.index_doc(id, msg)
            id += 1
            if id / 100 == 0:
                manager.commit()
        manager.commit()
        manager.close()

        profiler.stop("Index messages")
        print "Indexed %d messages" % id
示例#13
0
 def __call__(self, context):
     catalog = Catalog()
     text_indexer = NodeTextIndexer(["name", "surname", "email"])
     catalog[u"text"] = CatalogTextIndex(text_indexer)
     email_indexer = NodeAttributeIndexer("email")
     catalog[u"email"] = CatalogFieldIndex(email_indexer)
     name_indexer = NodeAttributeIndexer("name")
     catalog[u"name"] = CatalogFieldIndex(name_indexer)
     surname_indexer = NodeAttributeIndexer("surname")
     catalog[u"surname"] = CatalogFieldIndex(surname_indexer)
     channels_indexer = NodeAttributeIndexer("channels")
     catalog[u"channels"] = CatalogKeywordIndex(channels_indexer)
     date_indexer = NodeAttributeIndexer("date")
     catalog[u"date"] = CatalogFieldIndex(date_indexer)
     newspaper_indexer = NodeAttributeIndexer("newspaper")
     catalog[u"newspaper"] = CatalogFieldIndex(newspaper_indexer)
     return catalog
示例#14
0
    def __call__(self, context):
        catalog = Catalog()
        idindexer = NodeAttributeIndexer('id')
        catalog['id'] = CatalogFieldIndex(idindexer)
        hashindex = NodeAttributeIndexer('searches')
        catalog['searches'] = CatalogKeywordIndex(hashindex)

        return catalog
示例#15
0
    def __call__(self, context):
        catalog = Catalog()
        idindexer = NodeAttributeIndexer('id_username')
        catalog['id_username'] = CatalogTextIndex(idindexer)
        portrait = NodeAttributeIndexer('portrait')
        catalog['portrait'] = CatalogFieldIndex(portrait)

        return catalog
示例#16
0
    def test_with_contents(self):
        def discriminator(value, default):
            return value

        from repoze.catalog.indexes.field import CatalogFieldIndex
        src = CatalogFieldIndex(discriminator)
        src.index_doc(5, 9000)
        src.index_doc(6, 9000)
        src.index_doc(7, 9001)
        src.index_doc(8, 11005)

        obj = self._call(src)

        self.assertEqual(sorted(obj._fwd_index.keys()), [9000, 9001, 11005])
        self.assertEqual(sorted(obj._fwd_index[9000]), [5, 6])
        self.assertEqual(sorted(obj._fwd_index[9001]), [7])
        self.assertEqual(sorted(obj._fwd_index[11005]), [8])
        self.assertEqual(sorted(obj._rev_index.keys()), [5, 6, 7, 8])
        self.assertEqual(obj._rev_index[5], 9000)
        self.assertEqual(obj._rev_index[6], 9000)
        self.assertEqual(obj._rev_index[7], 9001)
        self.assertEqual(obj._rev_index[8], 11005)
        ndx = obj._granular_indexes[0][1]
        self.assertEqual(sorted(ndx.keys()), [9, 11])
        self.assertEqual(sorted(ndx[9]), [5, 6, 7])
        self.assertEqual(sorted(ndx[11]), [8])
        self.assertEqual(obj._num_docs(), 4)
示例#17
0
    def update_indexes(self):
        """ Ensure that we have indexes matching what the application needs.

        This function is called when the site is first created, and again
        whenever the ``reindex_catalog`` script is run.

        Extensions can arrange to get their own indexes added by registering
        named utilities for the
        :interface:`karl.models.interfaces.IIndexFactory` interface:  each
        such interface will be called to create a new (or overwritten) index.
        """
        indexes = {
            'name': CatalogFieldIndex(get_name),
            'title': CatalogFieldIndex(get_title),  # used as sort index
            'titlestartswith': CatalogFieldIndex(get_title_firstletter),
            'interfaces': CatalogKeywordIndex(get_interfaces),
            'containment': CatalogKeywordIndex(get_containment),
            'texts': CatalogTextIndex(get_textrepr),
            'path': CatalogPathIndex2(get_path, attr_discriminator=get_acl),
            'allowed': CatalogKeywordIndex(get_allowed_to_view),
            'creation_date': GranularIndex(get_creation_date),
            'modified_date': GranularIndex(get_modified_date),
            'content_modified': GranularIndex(get_content_modified_date),
            'start_date': GranularIndex(get_start_date),
            'end_date': GranularIndex(get_end_date),
            'publication_date': GranularIndex(get_publication_date),
            'mimetype': CatalogFieldIndex(get_mimetype),
            'creator': CatalogFieldIndex(get_creator),
            'modified_by': CatalogFieldIndex(get_modified_by),
            'email': CatalogFieldIndex(get_email),
            'tags': TagIndex(self),
            'lastfirst': CatalogFieldIndex(get_lastfirst),
            'member_name': CatalogTextIndex(get_member_name),
            'virtual': CatalogFieldIndex(get_virtual),
        }

        for name, utility in getUtilitiesFor(IIndexFactory):
            indexes[name] = utility()

        catalog = self.catalog

        # add indexes
        for name, index in indexes.iteritems():
            if name not in catalog:
                catalog[name] = index

        # remove indexes
        for name in catalog.keys():
            if name not in indexes:
                del catalog[name]
示例#18
0
    def _test_functional_merge(self, **extra):
        catalog = self._makeOne()
        from repoze.catalog.indexes.field import CatalogFieldIndex
        from repoze.catalog.indexes.keyword import CatalogKeywordIndex
        from repoze.catalog.indexes.text import CatalogTextIndex
        from repoze.catalog.indexes.path2 import CatalogPathIndex2

        class Content(object):
            def __init__(self, field, keyword, text, path):
                self.field = field
                self.keyword = keyword
                self.text = text
                self.path = path

        field = CatalogFieldIndex('field')
        keyword = CatalogKeywordIndex('keyword')
        text = CatalogTextIndex('text')
        path = CatalogPathIndex2('path')
        catalog['field'] = field
        catalog['keyword'] = keyword
        catalog['text'] = text
        catalog['path'] = path
        map = {
            1:
            Content('field1', ['keyword1', 'same'], 'text one', '/path1'),
            2:
            Content('field2', ['keyword2', 'same'], 'text two',
                    '/path1/path2'),
            3:
            Content('field3', ['keyword3', 'same'], 'text three',
                    '/path1/path2/path3'),
        }
        for num, doc in map.items():
            catalog.index_doc(num, doc)
        num, result = catalog.search(field=('field1', 'field1'), **extra)
        self.assertEqual(num, 1)
        self.assertEqual(list(result), [1])
        num, result = catalog.search(field=('field2', 'field2'), **extra)
        self.assertEqual(num, 1)
        self.assertEqual(list(result), [2])
        num, result = catalog.search(field=('field2', 'field2'),
                                     keyword='keyword2',
                                     **extra)
        self.assertEqual(num, 1)
        self.assertEqual(list(result), [2])
        num, result = catalog.search(field=('field2', 'field2'),
                                     text='two',
                                     **extra)
        self.assertEqual(num, 1)
        self.assertEqual(list(result), [2])
        num, result = catalog.search(text='text', keyword='same', **extra)
        self.assertEqual(num, 3)
        self.assertEqual(list(result), [1, 2, 3])

        num, result = catalog.search(text='text', path='/path1', **extra)
        self.assertEqual(num, 2)
        self.assertEqual(list(result), [2, 3])
示例#19
0
    def __call__(self, context):
        catalog = Catalog()
        idindexer = NodeAttributeIndexer('id')
        catalog['id'] = CatalogFieldIndex(idindexer)
        searchable_blob = NodeAttributeIndexer('searchable_text')
        catalog['searchable_text'] = CatalogTextIndex(searchable_blob)
        notlegit = NodeAttributeIndexer('notlegit')
        catalog['notlegit'] = CatalogFieldIndex(notlegit)

        userindexer = NodeAttributeIndexer('username')
        catalog['username'] = CatalogTextIndex(userindexer)
        fullname = NodeAttributeIndexer('fullname')
        catalog['fullname'] = CatalogTextIndex(fullname)
        email = NodeAttributeIndexer('email')
        catalog['email'] = CatalogTextIndex(email)
        location = NodeAttributeIndexer('location')
        catalog['location'] = CatalogTextIndex(location)
        home_page = NodeAttributeIndexer('home_page')
        catalog['home_page'] = CatalogTextIndex(home_page)
        return catalog
示例#20
0
 def __call__(self, context):
     catalog = Catalog()
     idindexer = NodeAttributeIndexer('id')
     catalog['id'] = CatalogFieldIndex(idindexer)
     userindexer = NodeAttributeIndexer('username')
     catalog['username'] = CatalogTextIndex(userindexer)
     unit_organizational = NodeAttributeIndexer('unit_organizational')
     catalog['unit_organizational'] = CatalogTextIndex(unit_organizational)
     position = NodeAttributeIndexer('position')
     catalog['position'] = CatalogTextIndex(position)
     return catalog
示例#21
0
 def __init__(self, parent, indices=None):
     ZopeDict.__init__(self)
     self.__parent__ = parent
     parent[self.__name__] = self
     self._cat = Catalog()
     if indices is None:
         self._currentIndex = ""
     else:
         self._currentIndex = indices[0]
         for index in indices:
             self._cat[index] = CatalogFieldIndex(index)
示例#22
0
    def test_with_empty_index(self):
        def discriminator(value, default):
            return value

        from repoze.catalog.indexes.field import CatalogFieldIndex
        src = CatalogFieldIndex(discriminator)
        obj = self._call(src)
        self.assertEqual(sorted(obj._fwd_index.keys()), [])
        self.assertEqual(sorted(obj._rev_index.keys()), [])
        ndx = obj._granular_indexes[0][1]
        self.assertEqual(sorted(ndx.keys()), [])
        self.assertEqual(obj._num_docs(), 0)
示例#23
0
 def __call__(self, context=None):
     catalog = Catalog()
     uid_indexer = NodeAttributeIndexer('uid')
     catalog[u'uid'] = CatalogFieldIndex(uid_indexer)
     email_indexer = NodeAttributeIndexer('personal_data.email')
     catalog[u'personal_data.email'] = CatalogFieldIndex(email_indexer)
     ordernumber_indexer = NodeAttributeIndexer('ordernumber')
     catalog[u'ordernumber'] = CatalogFieldIndex(ordernumber_indexer)
     booking_uids_indexer = NodeAttributeIndexer('booking_uids')
     catalog[u'booking_uids'] = CatalogKeywordIndex(booking_uids_indexer)
     vendor_uids_indexer = NodeAttributeIndexer('vendor_uids')
     buyable_uids_indexer = NodeAttributeIndexer('buyable_uids')
     catalog[u'buyable_uids'] = CatalogKeywordIndex(buyable_uids_indexer)
     catalog[u'vendor_uids'] = CatalogKeywordIndex(vendor_uids_indexer)
     creator_indexer = NodeAttributeIndexer('creator')
     catalog[u'creator'] = CatalogFieldIndex(creator_indexer)
     created_indexer = NodeAttributeIndexer('created')
     catalog[u'created'] = CatalogFieldIndex(created_indexer)
     firstname_indexer = NodeAttributeIndexer('personal_data.firstname')
     catalog[u'personal_data.firstname'] = \
         CatalogFieldIndex(firstname_indexer)
     lastname_indexer = NodeAttributeIndexer('personal_data.lastname')
     catalog[u'personal_data.lastname'] = \
         CatalogFieldIndex(lastname_indexer)
     city_indexer = NodeAttributeIndexer('billing_address.city')
     catalog[u'billing_address.city'] = CatalogFieldIndex(city_indexer)
     search_attributes = [
         'personal_data.lastname', 'personal_data.firstname',
         'personal_data.email', 'billing_address.city', 'ordernumber'
     ]
     text_indexer = NodeTextIndexer(search_attributes)
     catalog[u'text'] = CatalogTextIndex(text_indexer)
     # state on order only used for sorting in orders table
     state_indexer = NodeAttributeIndexer('state')
     catalog[u'state'] = CatalogFieldIndex(state_indexer)
     # salaried on order only used for sorting in orders table
     salaried_indexer = NodeAttributeIndexer('salaried')
     catalog[u'salaried'] = CatalogFieldIndex(salaried_indexer)
     return catalog
示例#24
0
def initialize_catalog():
    global _initialized
    if not _initialized:
        # create a catalog
        manager = ConnectionManager()
        catalog = factory(manager)
        # set up indexes
        catalog['flavors'] = CatalogFieldIndex('flavor')
        catalog['texts'] = CatalogTextIndex('text')
        # commit the indexes
        manager.commit()
        manager.close()
        _initialized = True
示例#25
0
def createCmedCatalogs(portal):
    cct = getToolByName(portal, 'cmed_catalog_tool')
    from repoze.catalog.indexes.text import CatalogTextIndex
    from repoze.catalog.indexes.field import CatalogFieldIndex

    # event catalog
    event_catalog = cct.add_catalog('event_catalog')
    # event_catalog['event_text'] = CatalogTextIndex('event_text')
    event_catalog['date'] = CatalogFieldIndex('date')
    event_catalog['date_year'] = CatalogFieldIndex('date_year')
    event_catalog['date_month'] = CatalogFieldIndex('date_month')
    event_catalog['date_day'] = CatalogFieldIndex('date_day')
    event_catalog['path'] = CatalogFieldIndex('path')
    event_catalog['event_type'] = CatalogFieldIndex('event_type')
    event_catalog['meta_type'] = CatalogFieldIndex('meta_type')
    event_catalog['related_object_id'] = CatalogFieldIndex('related_object_id')
示例#26
0
 def __call__(self, context):
     if not isinstance(context, SoupAdapter):
         raise ValueError('Current context must be a SoupAdapter')
     pfg = aq_parent(context)
     catalog = Catalog()
     for field in pfg._getFieldObjects():
         pfgindexadder = queryAdapter(field, IAddPfgIndex)
         if pfgindexadder is None:
             continue
         pfgindexadder(catalog)
     for field_id in auto_field_ids():
         indexer = NodeAttributeIndexer(field_id)
         catalog[field_id] = CatalogFieldIndex(indexer)
     return catalog
示例#27
0
    def update_indexes(self):
        indexes = {
            'lastfirst': CatalogFieldIndex(get_lastfirst),
            'lastnamestartswith': CatalogFieldIndex(get_lastname_firstletter),
            'texts': CatalogTextIndex(get_textrepr),
            # path index is needed for profile deletion
            'path': CatalogPathIndex2(get_path, attr_discriminator=get_acl),
            'allowed': CatalogKeywordIndex(get_allowed_to_view),
            'is_staff': CatalogFieldIndex(is_staff),
            'groups': CatalogKeywordIndex(get_groups),

            # provide indexes for sorting reports
            'department': CatalogFieldIndex(get_department),
            'email': CatalogFieldIndex(get_email),
            'location': CatalogFieldIndex(get_location),
            'organization': CatalogFieldIndex(get_organization),
            'phone': CatalogFieldIndex(get_phone),
            'position': CatalogFieldIndex(get_position),
        }

        # provide indexes for filtering reports
        for name in self['categories'].keys():
            getter = ProfileCategoryGetter(name)
            indexes['category_%s' % name] = CatalogKeywordIndex(getter)

        catalog = self.catalog
        need_reindex = False

        # add indexes
        for name, index in indexes.items():
            if name not in catalog:
                catalog[name] = index
                need_reindex = True

        # remove indexes
        for name in catalog.keys():
            if name not in indexes:
                del catalog[name]

        return need_reindex
示例#28
0
    def __call__(self, context):
        catalog = Catalog()
        idindexer = NodeAttributeIndexer('id')
        catalog['id'] = CatalogFieldIndex(idindexer)

        userindexer = NodeAttributeIndexer('username')
        catalog['username'] = CatalogTextIndex(userindexer)

        fullname = NodeAttributeIndexer('fullname')
        catalog['fullname'] = CatalogTextIndex(fullname)

        email = NodeAttributeIndexer('email')
        catalog['email'] = CatalogTextIndex(email)

        wop_platforms = NodeAttributeIndexer('wop_platforms')
        catalog['wop_platforms'] = CatalogTextIndex(wop_platforms)

        wop_programs = NodeAttributeIndexer('wop_programs')
        catalog['wop_programs'] = CatalogTextIndex(wop_programs)

        wop_partners = NodeAttributeIndexer('wop_partners')
        catalog['wop_partners'] = CatalogTextIndex(wop_partners)

        country = NodeAttributeIndexer('country')
        catalog['country'] = CatalogTextIndex(country)

        position = NodeAttributeIndexer('position')
        catalog['position'] = CatalogTextIndex(position)

        type_of_organization = NodeAttributeIndexer('type_of_organization')
        catalog['type_of_organization'] = CatalogTextIndex(type_of_organization)

        common_working_areas = NodeAttributeIndexer('common_working_areas')
        catalog['common_working_areas'] = CatalogTextIndex(common_working_areas)

        donors = NodeAttributeIndexer('donors')
        catalog['donors'] = CatalogTextIndex(donors)

        other_info = NodeAttributeIndexer('other_info')
        catalog['other_info'] = CatalogTextIndex(other_info)

        return catalog
示例#29
0
    def _get_model_root(cls):
        root = cls._get_connection().root
        if not hasattr(root, cls.Meta.table):
            model_root = BTrees.OOBTree.BTree()
            setattr(root, cls.Meta.table, model_root)
            model_root['objects'] = BTrees.OOBTree.BTree()
            model_root['catalog'] = Catalog()
            model_root['catalog_index'] = None

        model_root = getattr(root, cls.Meta.table)
        # Regenerate index fields?
        if 'catalog_index' not in model_root or model_root[
                'catalog_index'] != cls._get_index_fields():
            catalog = Catalog()
            for field in cls._get_index_fields():
                catalog[field] = CatalogFieldIndex(field)

            model_root['catalog'] = catalog
            model_root['catalog_index'] = cls._get_index_fields()

            cls.commit()
            cls.index()

        return model_root
示例#30
0
 def __call__(self, context=None):
     catalog = Catalog()
     uid_indexer = NodeAttributeIndexer('uid')
     catalog[u'uid'] = CatalogFieldIndex(uid_indexer)
     email_indexer = NodeAttributeIndexer('personal_data.email')
     catalog[u'email'] = CatalogFieldIndex(email_indexer)
     cid_indexer = NodeAttributeIndexer('cid')
     catalog[u'cid'] = CatalogFieldIndex(cid_indexer)
     firstname_indexer = ContactAttributeIndexer('personal_data.firstname')
     catalog[u'firstname'] = CatalogFieldIndex(firstname_indexer)
     lastname_indexer = ContactAttributeIndexer('personal_data.lastname')
     catalog[u'lastname'] = CatalogFieldIndex(lastname_indexer)
     zip_indexer = ContactAttributeIndexer('billing_address.zip')
     catalog[u'zip'] = CatalogFieldIndex(zip_indexer)
     street_indexer = ContactAttributeIndexer('billing_address.street')
     catalog[u'street'] = CatalogFieldIndex(street_indexer)
     search_attributes = ['personal_data.email',
                          'personal_data.firstname',
                          'personal_data.lastname'
                          ]
     text_indexer = NodeTextIndexer(search_attributes)
     catalog[u'text'] = CatalogTextIndex(text_indexer)
     return catalog
示例#31
0
 def __call__(self, context=None):
     catalog = Catalog()
     # uid of context rule refers to
     context_uid_indexer = NodeAttributeIndexer('context_uid')
     catalog[u'context_uid'] = CatalogFieldIndex(context_uid_indexer)
     # rule category
     category_indexer = NodeAttributeIndexer('category')
     catalog[u'category'] = CatalogFieldIndex(category_indexer)
     # rule valid from date
     valid_from_indexer = NodeAttributeIndexer('valid_from')
     catalog[u'valid_from'] = CatalogFieldIndex(valid_from_indexer)
     # rule valid to date
     valid_to_indexer = NodeAttributeIndexer('valid_to')
     catalog[u'valid_to'] = CatalogFieldIndex(valid_to_indexer)
     # user this rule applies
     user_indexer = NodeAttributeIndexer('user')
     catalog[u'user'] = CatalogFieldIndex(user_indexer)
     # group this rule applies
     group_indexer = NodeAttributeIndexer('group')
     catalog[u'group'] = CatalogFieldIndex(group_indexer)
     return catalog