def execute_documents_query(args, query): """Execute the query and return a set of results.""" begin_time = time.time() result, hits, output = execute_basic(TYPE_DOCUMENT, query) query_duration = (time.time() - begin_time) * 1000 log.debug('Query ES time: %.5fms', query_duration) convert_document_aggregations(result, output, args) query_duration = (time.time() - begin_time) * 1000 log.debug('Post-facet accumulated: %.5fms', query_duration) sub_shoulds = records_query_shoulds(args) sub_queries = [] for doc in hits.get('hits', []): document = doc.get('_source') document['id'] = int(doc.get('_id')) document['score'] = doc.get('_score') document['records'] = {'results': [], 'total': 0} collection_id = document.get('collection_id') document['public'] = authz.collections_public(collection_id) # TODO: restore entity highlighting somehow. sq = records_query_internal(document['id'], sub_shoulds) if sq is not None: sub_queries.append(json.dumps({})) sub_queries.append(json.dumps(sq)) output['results'].append(document) run_sub_queries(output, sub_queries) query_duration = (time.time() - begin_time) * 1000 log.debug('Post-subquery accumulated: %.5fms', query_duration) return output
def _add_to_dict(self, data): collection_ids = self.collection_ids try: from aleph.authz import collections_public data['public'] = collections_public(collection_ids) except: pass data.update({ 'id': self.id, 'type': self.type, 'source_collection_id': self.source_collection_id, 'collection_id': collection_ids, 'created_at': self.created_at, 'updated_at': self.updated_at }) return data