Beispiel #1
0
def author_network():
    """
    View that creates the data for the author network
    """
        
    #if there are not bibcodes, there should be a query to extract the authors
    try:
        query_components = json.loads(request.values.get('current_search_parameters'))
    except (TypeError, JSONDecodeError):
        #@todo: logging of the error
        return render_template('errors/generic_error.html', error_message='Error while creating the author network (code #1). Please try later.')

    # checked bibcodes will be input as
    if request.values.has_key('bibcode'):
        bibcodes = request.values.getlist('bibcode')
        query_components['q'] = ' OR '.join(["bibcode:%s" % b for b in bibcodes])

    #update the query parameters to return only what is necessary
    query_components.update({
        'facets': [], 
        'fields': ['author_norm'], 
        'highlights': [], 
        'rows': str(config.AUTHOR_NETWORK_DEFAULT_FIRST_RESULTS)
        })

    resp = solr.query(**query_components)

    if resp.is_error():
        return render_template('errors/generic_error.html', error_message='Error while creating the author network (code #2). Please try later.')

    #extract the authors
    lists_of_authors = [doc.author_norm for doc in resp.get_docset_objects() if doc.author_norm]
        
    return render_template('author_network_embedded.html', network_data=get_authorsnetwork(lists_of_authors))
Beispiel #2
0
def author_network():
    """
    View that creates the data for the author network
    """
        
    #if there are not bibcodes, there should be a query to extract the authors
    try:
        query_components = json.loads(request.values.get('current_search_parameters'))
    except (TypeError, JSONDecodeError):
        #@todo: logging of the error
        return render_template('errors/generic_error.html', error_message='Error while creating the author network (code #1). Please try later.')

    # get the maximum number of records to use
    query_components['rows'] = request.values.get('numRecs', config.MAX_EXPORTS['authnetwork'])

    # checked bibcodes will be input as
    if request.values.has_key('bibcode'):
        bibcodes = request.values.getlist('bibcode')
        query_components['q'] = ' OR '.join(["bibcode:%s" % b for b in bibcodes])

    #update the query parameters to return only what is necessary
    query_components.update({
        'facets': [], 
        'fields': ['author_norm'], 
        'highlights': [], 
        })

    req = solr.create_request(**query_components)
    url = None
    if 'bigquery' in request.values:
        from adsabs.core.solr import bigquery
        bigquery.prepare_bigquery_request(req, request.values['bigquery'])
        url = config.SOLRBIGQUERY_URL
    req = solr.set_defaults(req, query_url=url)
    resp = solr.get_response(req)

    if resp.is_error():
        return render_template('errors/generic_error.html', error_message='Error while creating the author network (code #2). Please try later.')

    #extract the authors
    lists_of_authors = [doc.author_norm for doc in resp.get_docset_objects() if doc.author_norm]
        
    statsd.incr("visualization.author_network.viewed")
    return render_template('author_network_embedded.html', network_data=get_authorsnetwork(lists_of_authors))