예제 #1
0
파일: views.py 프로젝트: romanchyla/adsabs
def word_cloud():
    """
    View that creates the data for the word cloud
    """

    query_url = config.SOLRQUERY_URL
    tvrh_query_url = query_url.rsplit('/', 1)[0] + '/tvrh'

    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 word cloud (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])

    query_components.update({
        'facets': [],
        'fields': ['id'],
        'highlights': [],
        'defType':'aqp', 
        'rows': str(config.WORD_CLOUD_DEFAULT_FIRST_RESULTS),
        'tv.all': 'true', 
        'tv.fl':'abstract', 
    })
        
    resp = solr.query(query_url=tvrh_query_url, **query_components)

    if resp.is_error():
        return render_template('errors/generic_error.html', error_message='Error while creating the word cloud (code #2). Please try later.')
    
    return render_template('word_cloud_embedded.html', wordcloud_data=wc_json(resp.raw_response()))
예제 #2
0
파일: views.py 프로젝트: aaccomazzi/adsabs
def word_cloud():
    """
    View that creates the data for the word cloud
    """

    query_url = config.SOLRQUERY_URL
    tvrh_query_url = query_url.rsplit('/', 1)[0] + '/tvrh'

    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 word cloud (code #1). Please try later.')

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

    # 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])

    query_components.update({
        'facets': [],
        'fields': ['id'],
        'highlights': [],
        'defType':'aqp', 
        'tv': 'true',
        'tv.tf_idf': 'true', 
        'tv.tf': 'true', 
        'tv.positions':'false',
        'tf.offsets':'false',
        'tv.fl':'abstract,title',
        'fl':'abstract,title' 
    })

    req = solr.create_request(**query_components)
    url = tvrh_query_url
    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 word cloud (code #2). Please try later.')
    
    statsd.incr("visualization.word_cloud.viewed")
    return render_template('word_cloud_embedded.html', wordcloud_data=wc_json(resp.raw_response()))