def transient(self, data): data['$uri'] = url_for('documents_api.view', document_id=data.get('id')) data['$ui'] = document_url(data.get('id')) collection_id = data.get('collection_id') data['$writeable'] = request.authz.can_write(collection_id) return data
def document_links(self, data, pk, schemata): links = { 'self': url_for('documents_api.view', document_id=pk), 'tags': url_for('entities_api.tags', id=pk), 'ui': document_url(pk) } if data.get('content_hash'): links['file'] = url_for('documents_api.file', document_id=pk) if schemata.intersection([Document.SCHEMA_PDF]): links['pdf'] = url_for('documents_api.pdf', document_id=pk) if schemata.intersection([Document.SCHEMA_PDF, Document.SCHEMA_TABLE]): links['records'] = url_for('documents_api.records', document_id=pk) if schemata.intersection([Document.SCHEMA_FOLDER]): query = (('filter:parent.id', pk), ) links['children'] = url_for('documents_api.index', _query=query) return links
def format_results(alert, results): output = [] for result in results.get('hits', []): document = unpack_result(result) # generate document URL: document['url'] = document_url(document['id'], dq=alert.query_text) collection = Collection.by_id(document.pop('collection_id')) if not collection: continue document['collection'] = collection # preview snippets: result['snippets'] = [] for field, snippets in result.get('highlight', {}).items(): result['snippets'].extend(snippets) output.append(document) return output
def get_results(query, limit): collections = {} for i, row in enumerate(query.scan()): if i >= limit: return source = row.get('_source') collection_id = source.pop('collection_id') if collection_id not in collections: obj = Collection.by_id(collection_id) if obj is None: collections[collection_id] = obj.label data = { 'collection': collections.get(collection_id, '[Missing]'), 'url': document_url(row.get('_id')) } for name, value in source.items(): if name not in FIELDS: continue if isinstance(value, (list, tuple, set)): value = ', '.join(value) data[name] = value yield data