def content_types_analyzer(node, source, validated):
"""Return for example
{'content_types': {
'artist': 8610, 'person': 3, 'cinema_review': 769, 'venue': 729,
'cultural_event': 2487, 'organization': 1, 'review': 4187}
}
only includes content type != 0
"""
if 'metadata_filter' in validated:
validated['metadata_filter'].pop('content_types', None)
objects = source(**validated)
index = find_catalog('system')['content_type']
intersection = index.family.IF.intersection
object_ids = getattr(objects, 'ids', objects)
if isinstance(object_ids, (list, types.GeneratorType)):
object_ids = index.family.IF.Set(object_ids)
result = [(content_type, len(intersection(object_ids, oids)))
for content_type, oids in index._fwd_index.items()]
result = dict([(k, v) for k, v in result if v != 0])
return {'content_types': result}
评论列表
文章目录