Example #1
0
def unindex_object(catalog, obj):
    """ Remove an index and its metadata if it exists in the catalog. """
    obj_id = catalog.document_map.docid_for_address(resource_path(obj))
    if obj_id is None:
        return
    catalog.unindex_doc(obj_id)
    #Remove metadata
    if ICatalogMetadataEnabled.providedBy(obj):
        catalog.document_map.remove_metadata(obj_id)
Example #2
0
def unindex_object(catalog, obj):
    """ Remove an index and its metadata if it exists in the catalog. """
    obj_id = catalog.document_map.docid_for_address(resource_path(obj))
    if obj_id is None:
        return
    catalog.unindex_doc(obj_id)
    #Remove metadata
    if ICatalogMetadataEnabled.providedBy(obj):
        catalog.document_map.remove_metadata(obj_id)
Example #3
0
def index_object(catalog, obj):
    """ Index an object and add metadata. """
    #Check if object already exists
    if catalog.document_map.docid_for_address(resource_path(obj)) is not None:
        reindex_object(catalog, obj)
        return
    obj_id = catalog.document_map.add(resource_path(obj))
    catalog.index_doc(obj_id, obj)
    #Add metadata
    if ICatalogMetadataEnabled.providedBy(obj):
        metadata = getAdapter(obj, ICatalogMetadata)()
        metadata['docid'] = obj_id
        catalog.document_map.add_metadata(obj_id, metadata)
Example #4
0
def index_object(catalog, obj):
    """ Index an object and add metadata. """
    #Check if object already exists
    if catalog.document_map.docid_for_address(resource_path(obj)) is not None:
        reindex_object(catalog, obj)
        return
    obj_id = catalog.document_map.add(resource_path(obj))
    catalog.index_doc(obj_id, obj)
    #Add metadata
    if ICatalogMetadataEnabled.providedBy(obj):
        metadata = getAdapter(obj, ICatalogMetadata)()
        metadata['docid'] = obj_id
        catalog.document_map.add_metadata(obj_id, metadata)
Example #5
0
def reindex_object(catalog, obj, indexes = (), metadata = True):
    """ Reindex an object and update metadata.
        It's possible to not update metadata and to only update some indexes.
    """
    obj_id = catalog.document_map.docid_for_address(resource_path(obj))
    if obj_id is None:
        #This is a special case when an object that isn't indexed tries to be reindexed
        #Note that indexes and metadata parameter is ignored in that case
        index_object(catalog, obj) #Do reindex instead
        return

    if not indexes:
        catalog.reindex_doc(obj_id, obj)
    else:
        for index in indexes:
            catalog[index].reindex_doc(obj_id, obj)

    #Add metadata
    if metadata and ICatalogMetadataEnabled.providedBy(obj):
        metadata = getAdapter(obj, ICatalogMetadata)()
        metadata['docid'] = obj_id
        catalog.document_map.add_metadata(obj_id, metadata)
Example #6
0
def reindex_object(catalog, obj, indexes=(), metadata=True):
    """ Reindex an object and update metadata.
        It's possible to not update metadata and to only update some indexes.
    """
    obj_id = catalog.document_map.docid_for_address(resource_path(obj))
    if obj_id is None:
        #This is a special case when an object that isn't indexed tries to be reindexed
        #Note that indexes and metadata parameter is ignored in that case
        index_object(catalog, obj)  #Do reindex instead
        return

    if not indexes:
        catalog.reindex_doc(obj_id, obj)
    else:
        for index in indexes:
            catalog[index].reindex_doc(obj_id, obj)

    #Add metadata
    if metadata and ICatalogMetadataEnabled.providedBy(obj):
        metadata = getAdapter(obj, ICatalogMetadata)()
        metadata['docid'] = obj_id
        catalog.document_map.add_metadata(obj_id, metadata)