예제 #1
0
 def get_similar(self, **kwargs):
     
     from adsabs.core.solr import get_document_similar
     q = "%s:%s" % (config.SOLR_DOCUMENT_ID_FIELD, self.data[config.SOLR_DOCUMENT_ID_FIELD])
     with statsd.timer("core.solr.similar.query_response_time"):
         resp = get_document_similar(q, **kwargs)
     return resp
예제 #2
0
파일: views.py 프로젝트: romanchyla/adsabs
def export_to_other_formats():
    """
    view that exports a set of papers
    the imput is a format and 
    a list of bibcodes or a variable containing the parameters for a solr query
    """
    #extract the format
    export_format = request.values.getlist('export_format')
    list_type = request.values.get('list_type')

    #list of bibcodes to extract
    bibcodes_to_export = []
    #flag to check if everything has been extracted
    all_extracted = True
    num_hits = None
    
    #if there are not bibcodes, there should be first a query to extract them  
    if not request.values.has_key('bibcode'):
        #@todo: code to query solr with the same query parameters but override the fields to retrieve
        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 exporting records (code #1). Please try later.')
        
        #update the query parameters to return only what is necessary
        query_components.update({'facets':[], 'fields': ['bibcode'], 'highlights':[], 'rows': str(config.EXPORT_DEFAULT_ROWS)})
        #execute the query
        if list_type == 'similar':
            resp = get_document_similar(**query_components)
        else:
            resp = solr.query(**query_components)
        if resp.is_error():
            return render_template('errors/generic_error.html', error_message='Error while exporting records (code #2). Please try later.')
        #extract the bibcodes
        for doc in resp.get_docset_objects():
            bibcodes_to_export.append(doc.bibcode)
        #check if all the results of the query have been extracted ( num results <= max to extract )
        if resp.get_hits() > config.EXPORT_DEFAULT_ROWS:
            all_extracted = False
            num_hits = resp.get_hits()

    else:
        #extract all the bibcodes
        bibcodes_to_export = request.values.getlist('bibcode')
        
    #actually export the records
    if bibcodes_to_export:
        export_str = get_classic_records_export(bibcodes_to_export, export_format)
    else:
        export_str = ''
    
    #if not everything has been extracted, show message on top  
    if not all_extracted:
        export_str = 'Exported first %s results of %s total. \n\n\n%s' % (config.EXPORT_DEFAULT_ROWS, num_hits, export_str)
    else:
        export_str = 'Exported %s records \n\n\n%s' % (len(bibcodes_to_export), export_str)
    
    return Response(export_str, mimetype='text/plain')
예제 #3
0
파일: utils.py 프로젝트: aburgm/adsabs
def get_publications_from_query(query_components, list_type=None, bigquery_id=None):
    try:
        # Get the information from Solr
        if list_type and list_type == 'similar':
            resp = get_document_similar(**query_components)
        else:
            req = solr.create_request(**query_components)
            if bigquery_id:
                from adsabs.core.solr import bigquery
                bigquery.prepare_bigquery_request(req, bigquery_id)
            req = solr.set_defaults(req)
            resp = solr.get_response(req)

    except SolrReferenceQueryError, e:
        app.logger.error("Solr publications query for %s blew up (%s)" % (q,e))
        raise
예제 #4
0
파일: views.py 프로젝트: aaccomazzi/adsabs
def export_to_other_formats():
    """
    view that exports a set of papers
    the imput is a format and 
    a list of bibcodes or a variable containing the parameters for a solr query
    """
    #extract the format
    export_format = request.values.getlist('export_format')
    list_type = request.values.get('list_type')
    numRecs   = request.values.get('numRecs')

    #list of bibcodes to extract
    bibcodes_to_export = []
    #flag to check if everything has been extracted
    all_extracted = True
    num_hits = None
    
    #if there are not bibcodes, there should be first a query to extract them  
    if not request.values.has_key('bibcode'):
        #@todo: code to query solr with the same query parameters but override the fields to retrieve
        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 exporting records (code #1). Please try later.')
        
        #update the query parameters to return only what is necessary
        query_components.update({'facets':[], 'fields': ['bibcode'], 'highlights':[], 'rows': str(numRecs)})
        if 'sort' not in query_components:
            # this might be an abstract citation/reference list view so get the sort from config
            if list_type is not None and list_type in config.ABS_SORT_OPTIONS_MAP:
                query_components['sort'] = [config.ABS_SORT_OPTIONS_MAP[list_type]]
        #execute the query
        if list_type == 'similar':
            resp = get_document_similar(**query_components)
        else:
            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 exporting records (code #2). Please try later.')
        #extract the bibcodes
        for doc in resp.get_docset_objects():
            bibcodes_to_export.append(doc.bibcode)
        #check if all the results of the query have been extracted ( num results <= max to extract )
        if resp.get_hits() > numRecs:
            all_extracted = False
            num_hits = resp.get_hits()

    else:
        #extract all the bibcodes
        bibcodes_to_export = request.values.getlist('bibcode')
        
    #actually export the records
    if bibcodes_to_export:
        export_str = get_classic_records_export(bibcodes_to_export, export_format)
    else:
        export_str = ''
    
    #if not everything has been extracted, show message on top  
    if not all_extracted:
        export_str = 'Exported first %s results of %s total. \n\n\n%s' % (numRecs, num_hits, export_str)
    else:
        export_str = 'Exported %s records \n\n\n%s' % (len(bibcodes_to_export), export_str)
    
    return Response(export_str, mimetype='text/plain')
예제 #5
0
파일: views.py 프로젝트: aaccomazzi/adsabs
    list_type = request.values.get('list_type')
    numRecs   = request.values.get('numRecs', str(config.EXPORT_DEFAULT_ROWS))
    
    try:
        query_components = json.loads(request.values.get('current_search_parameters'))
    except (TypeError, JSONDecodeError), e:
        #@todo: logging of the error
        return ''
    #update the query parameters to return only what is necessary
    query_components.update({'facets':[], 'fields': ['bibcode'], 'highlights':[], 'rows': numRecs})
    if 'sort' not in query_components:
        query_components['sort'] = create_sort_param(list_type=list_type)

    #execute the query
    if list_type == 'similar':
        resp = get_document_similar(**query_components)
    else:
        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():
        #@todo: logging of the error
        return ''
    #extract the bibcodes
    for doc in resp.get_docset_objects():