Ejemplo n.º 1
0
def get_astro_changes(message):
    """This is a special hack to retrieve only astro papers"""
    if message.getParam("last_recid"):
        #last_recid = int(Integer.cast_(message.getParam("last_recid")).intValue())
        last_recid = int(str(message.getParam("last_recid")))
        if last_recid == -1:
            api_calls.dispatch("create_collection_bibrec", "_astro_bibrec", "Astronomy")
    message.setParam("table", "_astro_bibrec")
    get_recids_changes(message)
Ejemplo n.º 2
0
def invenio_search(message):
    '''Search Invenio using high-level API
    @param kwargs: (Map<String, String[]>) list of parameters
    
    This search is problematic becuase it can return different
    types of values: None, list of ints, String
    '''
    params = message.getParam('kwargs')
    if params is None:
        return
    
    params = HashMap.cast_(params).of_(String, List)
    kwargs = {}
    
    kset = params.keySet().toArray()
    vset = params.values().toArray()
    max_size = len(vset)
    i = 0
    while i < max_size:
        v = list(ArrayList(vset[i]).of_(String))
        if len(v) == 1:
            kwargs[str(kset[i])] = v[0]
        else:
            kwargs[str(kset[i])] = v
        i += 1
    
    # versatile
    #(wid, result) = api_calls.dispatch('invenio_search', kwargs)
    
    # dumb, but fast
    (wid, result) = api_calls.dispatch('invenio_search_xml2', kwargs)
    
    if not (isinstance(result, str) or result is None):
        raise Exception('Wrong arguments - I\'ll rather die than give you what you want!')
    message.setResults(result)
Ejemplo n.º 3
0
def format_search_results(message):
    '''Returns the citation summary for the given recids. This method
    inserts the Invenio formatted citation summary directly into the
    response object
    
    @var message: 
        recids: Java int[]
        req: SolrQueryRequest
        rsp: SolrQueryResponse
    
    '''
    rsp = SolrQueryResponse.cast_(message.getParam('response'))
    
    recids = message.getParamArray_int("recids")
    start = time.time()
    if config.MONTYSOLR_BUGDEBUG:
        message.threadInfo("start: citation_summary")
    c_time = time.time()
    iset = intbitset(recids)
    if config.MONTYSOLR_BUGDEBUG:
        message.threadInfo("int[] converted to intbitset in: %s, size=%s" % (time.time() - c_time, len(iset)))
    (wid, (output)) = api_calls.dispatch('citation_summary', iset, 'hcs', 'en', '', '')
    if config.MONTYSOLR_BUGDEBUG:
        message.threadInfo("end: citation_summary pid=%s, finished in %s" % (wid, time.time() - start))
    rsp.add("inv_response", output)
Ejemplo n.º 4
0
def get_recids_changes(message):
    """Retrieves the recids of the last changed documents"""
    last_recid = None
    table = 'bibrec'
    if message.getParam("table"):
        table = str(message.getParam("table"))
    if message.getParam("last_recid"):
        #last_recid = int(Integer.cast_(message.getParam("last_recid")).intValue())
        last_recid = int(str(message.getParam("last_recid")))
    mod_date = None
    if message.getParam("mod_date"):
        mod_date = str(message.getParam("mod_date"))
    max_records = 10000
    if message.getParam('max_records'):
        max_records = int(Integer.cast_(message.getParam("max_records")).intValue())
    if last_recid and last_recid == -1:
        mod_date = None
    (wid, results) = api_calls.dispatch("get_recids_changes", last_recid, max_recs=max_records, 
                                        mod_date=mod_date, table=table)
    if results:
        data, last_recid, mod_date = results
        out = HashMap().of_(String, JArray_int)
        for k,v in data.items():
            out.put(k, JArray_int(v))
        message.setResults(out)
        message.setParam('mod_date', mod_date)
        message.setParam('last_recid', last_recid)
Ejemplo n.º 5
0
def parse_human_name(message):
    input = unicode(message.getParam("input"))
    (wid, results) = api_calls.dispatch("parse_human_name", input)
    if results:
        out = HashMap() #.of_(String, JArray_int)
        for k,v in results.items():
            out.put(k, v)
        message.setResults(out)
Ejemplo n.º 6
0
def perform_request_search_bitset(message):
    '''Search and use bitset for exchange of data
    @param query: (str) query string
    @param max_len: (int) how many max results to return
    @param offset: (int) start from the xth element
    '''
    query = unicode(message.getParam("query")).encode("utf8")
    max_len = message.getParam_int('max_len', 25)
    offset = message.getParam_int('offset', 0)
    
    #offset, hit_dump, total_matches, searcher_id = searching.multiprocess_search(query, 0)
    (wid, (offset, hits, total_matches)) = api_calls.dispatch('search', query, max_len=max_len, offset=offset)
    #message.threadInfo("query=%s, total_hits=%s" % (query, total_matches))
    message.setResults(JArray_byte(intbitset(hits).fastdump()))
Ejemplo n.º 7
0
def get_citation_dict(message):
    '''TODO: unittest'''
    dictname = String.cast_(message.getParam('dictname'))
    
    # we will call the local module (not dispatched remotely)
    if hasattr(api_calls, '_dispatch'):
        wid, cd = api_calls._dispatch("get_citation_dict", dictname)
    else:
        wid, cd = api_calls.dispatch("get_citation_dict", dictname)
    
    if cd:
        hm = HashMap().of_(String, JArray_int)
        for k,v in cd.items():
            j_array = JArray_int(v)
            hm.put(k, j_array)
        message.put('result', hm)
Ejemplo n.º 8
0
def perform_request_search_ints(message):
    '''Search and use ints for exchange of data
    @param query: (str) query string
    @param max_len: (int) how many max results to return
    @param offset: (int) start from the xth element
    '''
    query = unicode(message.getParam("query")).encode("utf8")
    max_len = message.getParam_int('max_len', 25)
    offset = message.getParam_int('offset', 0)
        
    #offset, hit_list, total_matches, searcher_id = searching.multiprocess_search(query, 0)
    (wid, (offset, hits, total_matches)) = api_calls.dispatch('search', query, max_len=max_len, offset=offset)
    if len(hits):
        message.setResults(JArray_int(hits))
    else:
        message.setResults(JArray_int([]))

    message.setParam("total", total_matches)
def _dispatch_remote(func_name, args, kwargs):
    """This receives the data on the remote side and calls
    the actual function that does the job and returns results.
    """

    g = globals()
    func_name_pre = '%s_remote_pre' % func_name
    func_name_post = '%s_remote_post' % func_name

    if func_name_pre in g:
        args = list(args)
        g[func_name_pre](args, kwargs)

    (thread_id, result) = api_calls.dispatch(func_name, *args, **kwargs)

    if func_name_post in g:
        result = g[func_name_post](result)

    return (os.getpid(), result)
Ejemplo n.º 10
0
def sort_and_format(message):
    '''Calls sorting XOR formatting over the result set'''
    
    start = time.time()
    
    recids = intbitset(message.getParamArray_int("recids"))
    kwargs = HashMap.cast_(message.getParam('kwargs'))

    kws = {}

    kset = kwargs.keySet().toArray()
    vset = kwargs.values().toArray()
    max_size = len(vset)
    i = 0
    while i < max_size:
        v = str(vset[i])
        if v[0:1] in ["'", '[', '{'] :
            try:
                v = eval(v)
            except:
                pass
        kws[str(kset[i])] = v
        i += 1
    
    
    if config.MONTYSOLR_BUGDEBUG:
        message.threadInfo("start: citation_summary")
        message.threadInfo("int[] converted to intbitset in: %s, size=%s" % (time.time() - start, len(recids)))
        
    (wid, (output)) = api_calls.dispatch('sort_and_format', recids, kws)
    
    if config.MONTYSOLR_BUGDEBUG:
        message.threadInfo("end: citation_summary pid=%s, finished in %s" % (wid, time.time() - start))

    if isinstance(output, list):
        message.setResults(JArray_int(output))
        message.setParam("rtype", "int")
    else:
        message.setResults(output)
        message.setParam("rtype", "string")
Ejemplo n.º 11
0
def _dispatch(func_name, *args, **kwargs):
    return api_calls.dispatch(func_name, *args, **kwargs)