Exemple #1
0
def handle_request_body(message):
    req = message.getSolrQueryRequest()
    rsp = message.getSolrQueryResponse()
    params = message.getParams()

    start = time.time()
    q = params.get("q").encode('utf8') #TODO: sj.CommonParams.Q is overshadowed by solr.util.CommonParams or is not wrapped at all

    #offset, hit_list, total_matches, searcher_id = searching.multiprocess_search(str(q))
    (wid, (offset, hit_list, total_matches)) = api_calls.dispatch('search', str(q))

    t = time.time() - start
    #message.threadInfo("Query took: %s s. hits=%s and was executed by: %s" % (t, total_matches, searcher_id))

    reader = req.getSearcher().getReader();

    # translate invenio recids into lucene docids
    transl_table = sj.DictionaryCache.INSTANCE.getTranslationCache(reader, "id")
    res = []
    for h in hit_list:
        if transl_table.containsKey(h):
            res.append(transl_table.get(h))

    #logging.error(transl_table.size())

    ds = sj.DocSlice(offset,len(res),res, None, total_matches, 1.0)
    rsp.add("response", ds)
Exemple #2
0
def perform_request_search_ints(message):
    query = unicode(message.getParam("query")).encode("utf8")
    #offset, hit_list, total_matches, searcher_id = searching.multiprocess_search(query, 0)
    (wid, (offset, hits, total_matches)) = api_calls.dispatch('search', query, 0)
    if len(hits):
        message.setResults(sj.JArray_int(hits))
    else:
        message.setResults(sj.JArray_int([]))

    message.setParam("total", total_matches)
Exemple #3
0
def format_search_results(message):
    req = message.getSolrQueryRequest()
    rsp = message.getSolrQueryResponse()
    recids = message.getParamArray_int("recids")
    start = time.time()
    message.threadInfo("start: citation_summary")
    c_time = time.time()
    iset = intbitset(recids)
    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', '', '')
    message.threadInfo("end: citation_summary pid=%s, finished in %s" % (wid, time.time() - start))
    rsp.add("inv_response", output)
Exemple #4
0
def format_search_results_local(message):
    req = message.getSolrQueryRequest()
    rsp = message.getSolrQueryResponse()

    recids = message.getParamArray_int("recids")
    out = StringIO()
    # TODO: pass the ln and other arguments
    (wid, (output,)) = api_calls.dispatch("sumarize_records", intbitset(recids), 'hcs', 'en', '', '', out)
    if not output:
        out.seek(0)
        output = out.read()
    del out
    rsp.add("inv_response", output)
Exemple #5
0
def get_recids_changes(message):
    """Retrieves the recids of the last changed documents"""
    last_recid = int(sj.Integer.cast_(message.getParam("last_recid")).intValue())
    max_records = 10000
    if message.getParam('max_records'):
        mr = int(sj.Integer.cast_(message.getParam("max_records")).intValue())
        if mr < 100001:
            max_records = mr
    (wid, results) = api_calls.dispatch("get_recids_changes", last_recid, max_records)
    if results:
        out = sj.HashMap().of_(sj.String, sj.JArray_int)
        for k,v in results.items():
            out.put(k, sj.JArray_int(v))
        message.setResults(out)
Exemple #6
0
def perform_request_search_bitset(message):
    query = unicode(message.getParam("query")).encode("utf8")
    #offset, hit_dump, total_matches, searcher_id = searching.multiprocess_search(query, 0)
    (wid, (offset, hits, total_matches)) = api_calls.dispatch('search', query, 0)
    #message.threadInfo("query=%s, total_hits=%s" % (query, total_matches))
    message.setResults(sj.JArray_byte(intbitset(hits).fastdump()))