Example #1
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()
Example #2
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
Example #3
0
def bootstrap(zodb_root):
    if not 'projector' in zodb_root:
        # add site folder
        root = SiteFolder('Projector Site')
        zodb_root['projector'] = root
        # add catalog and document map
        catalog = Catalog()
        catalog['title'] = CatalogTextIndex('title')
        catalog['content'] = CatalogTextIndex('content')
        root.catalog = catalog
        document_map = DocumentMap()
        root.document_map = document_map
    return zodb_root['projector']
Example #4
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]
Example #5
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
Example #6
0
def _default_indexes():
    return {
        'title':
        CatalogFieldIndex(get_title),
        'description':
        CatalogFieldIndex(get_description),
        'type_name':
        CatalogFieldIndex(get_type_name),
        'sortable_title':
        CatalogFieldIndex(get_sortable_title),
        'path':
        CatalogPathIndex(get_path),
        'searchable_text':
        CatalogTextIndex(get_searchable_text,
                         lexicon=Lexicon(Splitter(), CaseNormalizer())),
        'uid':
        CatalogFieldIndex(get_uid),
        'tags':
        CatalogKeywordIndex(get_tags),
        'search_visible':
        CatalogFieldIndex(get_search_visible),
        'date':
        CatalogFieldIndex(get_date),
        'modified':
        CatalogFieldIndex(get_modified),
        'created':
        CatalogFieldIndex(get_created),
        'wf_state':
        CatalogFieldIndex(get_wf_state),
        'workflow':
        CatalogFieldIndex(get_workflow),
    }.items()
Example #7
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
Example #8
0
 def __call__(self, context=None):
     catalog = Catalog()
     email_indexer = NodeAttributeIndexer('email')
     catalog[u'email'] = CatalogFieldIndex(email_indexer)
     uid_indexer = NodeAttributeIndexer('uid')
     catalog[u'uid'] = CatalogFieldIndex(uid_indexer)
     buyable_uid_indexer = NodeAttributeIndexer('buyable_uid')
     catalog[u'buyable_uid'] = CatalogFieldIndex(buyable_uid_indexer)
     order_uid_indexer = NodeAttributeIndexer('order_uid')
     catalog[u'order_uid'] = CatalogFieldIndex(order_uid_indexer)
     vendor_uid_indexer = NodeAttributeIndexer('vendor_uid')
     catalog[u'vendor_uid'] = CatalogFieldIndex(vendor_uid_indexer)
     creator_indexer = NodeAttributeIndexer('creator')
     catalog[u'creator'] = CatalogFieldIndex(creator_indexer)
     created_indexer = NodeAttributeIndexer('created')
     catalog[u'created'] = CatalogFieldIndex(created_indexer)
     exported_indexer = NodeAttributeIndexer('exported')
     catalog[u'exported'] = CatalogFieldIndex(exported_indexer)
     title_indexer = NodeAttributeIndexer('title')
     catalog[u'title'] = CatalogFieldIndex(title_indexer)
     state_indexer = NodeAttributeIndexer('state')
     catalog[u'state'] = CatalogFieldIndex(state_indexer)
     salaried_indexer = NodeAttributeIndexer('salaried')
     catalog[u'salaried'] = CatalogFieldIndex(salaried_indexer)
     search_attributes = ['email', 'title']
     text_indexer = NodeTextIndexer(search_attributes)
     catalog[u'text'] = CatalogTextIndex(text_indexer)
     return catalog
Example #9
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])
Example #10
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
Example #11
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])
Example #12
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
Example #13
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
Example #14
0
def update_indexes(catalog, reindex=True):
    """ Add or remove indexes. If reindex is True, also reindex all content if
        an index has been added or removed.
        Will return a set of indexes changed regardless.
    """

    indexes = {
        'title': CatalogFieldIndex(get_title),
        'sortable_title': CatalogFieldIndex(get_sortable_title),
        'description': CatalogFieldIndex(get_description),
        'uid': CatalogFieldIndex(get_uid),
        'aid': CatalogFieldIndex(get_aid),
        'aid_int': CatalogFieldIndex(get_aid_int),
        'content_type': CatalogFieldIndex(get_content_type),
        'workflow_state': CatalogFieldIndex(get_workflow_state),
        'path': CatalogPathIndex(get_path),
        'creators': CatalogKeywordIndex(get_creators),
        'created': CatalogFieldIndex(get_created),
        'allowed_to_view': CatalogKeywordIndex(get_allowed_to_view),
        'view_meeting_userids': CatalogKeywordIndex(get_view_meeting_userids),
        'searchable_text': CatalogTextIndex(get_searchable_text),
        'start_time': CatalogFieldIndex(get_start_time),
        'end_time': CatalogFieldIndex(get_end_time),
        'unread': CatalogKeywordIndex(get_unread),
        'like_userids': CatalogKeywordIndex(get_like_userids),
        'order': CatalogFieldIndex(get_order),
        'tags': CatalogKeywordIndex(get_tags),
    }

    changed_indexes = set()

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

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

    if reindex:
        reindex_indexes(catalog)

    return changed_indexes
Example #15
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
Example #16
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
Example #17
0
def switch_text_index(args, site):
    """
    It turns out, for OSI at least, that reindexing every document is too large
    of a transaction to fit in memory at once. This strategy seeks to address
    this problem along with a couple of other design goals:

      1) Production site can be running in read/write mode while documents
         are reindexed.

      2) This operation can be interrupted and pick back up where it left off.

    To accomplish this, in this function we create the new text index without
    yet replacing the old text index. We then store the set of document ids of
    documents which need to be reindexed. The 'reindex_text' function then
    reindexes documents in small batches, each batch in its own transaction.
    Because the old index has not yet been replaced, users can use the site
    normally while this occurs. When all documents have been reindexed,
    'reindex_text' looks to see if any new documents have been indexed in the
    old index in the meantime and creates a new list of documents to reindex.
    When the old_index and new_index are determined to contain the exact same
    set of document ids, then the new_index is put in place of the old_index
    and the migration is complete.
    """
    new_type = args.convert_to
    old_type = get_index_type(args, site)
    if new_type is None:
        new_type = old_type
    else:
        if new_type != old_type:
            log.info("Converting to %s." % new_type)
    catalog = find_catalog(site)
    if new_type == 'pg':
        new_index = KarlPGTextIndex(get_weighted_textrepr)
        if old_type == 'pg':
            new_index.drop_and_create()
    elif new_type == 'zope':
        new_index = CatalogTextIndex(get_textrepr)
    else:
        raise ValueError("Unknown text index type: %s" % new_type)
    catalog['new_texts'] = new_index  # temporary location
    new_index.to_index = IF.Set()
    new_index.indexed = IF.Set()
    transaction.commit()
    site._reindex_text_status = 'reindexing'
Example #18
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
Example #19
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
Example #20
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)
        ubicacio = NodeAttributeIndexer('ubicacio')
        catalog['ubicacio'] = CatalogTextIndex(ubicacio)
        telefon = NodeAttributeIndexer('telefon')
        catalog['telefon'] = CatalogTextIndex(telefon)
        twitter_username = NodeAttributeIndexer('twitter_username')
        catalog['twitter_username'] = CatalogTextIndex(twitter_username)
        return catalog
Example #21
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
Example #22
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
Example #23
0
 def create(self, indexer):
     # XXX use txng here if available
     return CatalogTextIndex(indexer)
Example #24
0
    def next_index(self):
        cur_index = self.index_count
        self.index_count += 1
        return cur_index


if __name__ == '__main__':
    _, root_node = db_setup()
    ## Load sample generated by http://www.generatedata.com/
    load_data('media/dataSep-7-2014.json', root_node)
    transaction.commit()
    ## Preparing catalog
    ## see http://docs.repoze.org/catalog/overview.html
    nodes = PersistentMapping()
    catalog = PersistentCatalog()
    root_node['catalog'] = catalog
    catalog['email'] = CatalogTextIndex(get_email)
    catalog['country'] = CatalogTextIndex(get_country)
    for d in root_node['data']:
        ni = catalog.next_index()
        nodes[ni] = d
        catalog.index_doc(ni, d)
    root_node['catalog_map'] = nodes
    transaction.commit()
    (q_count, q_result) = catalog.query(Eq('country', "Belgium"))
    print "Number of results: %d" % q_count
    print "Items:"
    for res in q_result.items():
        print nodes[res[0]]
Example #25
0
    def __call__(self, context):
        catalog = Catalog()
        idindexer = NodeAttributeIndexer('id_username')
        catalog['id_username'] = CatalogTextIndex(idindexer)

        return catalog
Example #26
0
def CatalogFactory():
    catalog = Catalog()
    catalog['text'] = CatalogTextIndex(get_text)
    catalog['page'] = CatalogFieldIndex(get_page)
    return catalog
Example #27
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