示例#1
0
def search():
    """ Renders the search results. """
    params = request.form
    payload = query_body(params, RESULT_LIMIT)
    headers = {'content-type': "application/json"}
    try:
        response = get(solr_url(app.config),
                       data=json.dumps(payload),
                       headers=headers)
        if response.status_code == 400 or response.status_code == 500:
            result = response.json()
            error = result['error']
            msg = result['error']['msg']
            trace = error.get('trace', '')
            return render_template('search.html',
                                   params={},
                                   offset='0',
                                   error='Solr failed: ' + msg,
                                   trace=trace)

        app.logger.debug('Calling Solr with url %s', response.url)
        app.logger.debug('Request body %s', json.dumps(payload))
        data = response.json()
        docs = data['grouped']['PatientID']
        docs = group(docs)
        facets = prepare_facets(data.get('facets', []), request.url)
        results = data['grouped']['PatientID']['ngroups']
        paging = calc(results, params.get('offset', '0'), RESULT_LIMIT)
        demo = app.config['DEMO']
        return render_template('result.html',
                               docs=docs,
                               results=results,
                               facets=facets,
                               payload=payload,
                               facet_url=request.url,
                               params=params,
                               paging=paging,
                               version=VERSION,
                               modalities=params.getlist('Modality'),
                               offset=params.get('offset', '0'),
                               demo=demo)
    except RequestException:
        return render_template('search.html',
                               params={},
                               error='No response from Solr, is it running?')
示例#2
0
def search():
    params = request.args
    payload = meta.query.query_body(params)
    headers = {'content-type': "application/json"}
    response = requests.get(solr_url(),
                            data=json.dumps(payload),
                            headers=headers)
    app.logger.debug('Calling Solr with url %s', response.url)
    app.logger.debug('Request body %s', json.dumps(payload))
    try:
        if response.status_code == 400 or response.status_code == 500:
            result = response.json()
            error = result['error']
            msg = result['error']['msg']
            trace = error.get('trace', '')

            return render_template('search.html',
                                   params={},
                                   error=' Call to Solr failed: ' + msg,
                                   trace=trace)
        data = response.json()
        docs = data['grouped']['PatientID']
        docs = group(docs)
        facets = prepare_facets(data.get('facets', []), request.url)
        results = data['grouped']['PatientID']['ngroups']
        paging = calc(results, request.url, params.get('offset', '1'))
        return render_template('result.html',
                               docs=docs,
                               results=results,
                               facets=facets,
                               payload=payload,
                               facet_url=request.url,
                               params=params,
                               paging=paging,
                               version=app.config['VERSION'],
                               modalities=params.getlist('Modality'))
    except json.JSONDecodeError:
        return render_template('search.html',
                               params={},
                               error='Can\'t decode JSON, is Solr running?')
def search():
    """ Renders the search results. """
    params = request.form
    payload = query_body(params, RESULT_LIMIT)
    headers = {"content-type": "application/json"}
    try:
        response = get(solr_url(app.config),
                       data=json.dumps(payload),
                       headers=headers)
    except RequestException:
        return render_template(
            "search.html",
            params=params,
            error="No response from Solr, is it running?",
            trace=solr_url(app.config),
        )
    if response.status_code >= 400 and response.status_code < 500:
        logging.error(response.text)
        return render_template(
            "search.html",
            params=params,
            page=0,
            offset=0,
            error=response.reason,
            trace=response.url,
        )
    elif response.status_code >= 500:
        result = response.json()
        error = result["error"]
        msg = result["error"]["msg"]
        trace = error.get("trace", "")
        logging.error(reposonse.text)
        return render_template(
            "search.html",
            params=params,
            page=0,
            offset=0,
            error="Solr failed: " + msg,
            trace=trace,
        )
    else:
        app.logger.debug("Calling Solr with url %s", response.url)
        data = response.json()
        docs = data["grouped"]["PatientID"]
        results = data["grouped"]["PatientID"]["ngroups"]
        studies_result = data["grouped"]["PatientID"]["matches"]
        page = params.get("page", 0)
        offset = params.get("offset", 0)
        paging = calc(results, page, RESULT_LIMIT)
        return render_template(
            "result.html",
            docs=docs,
            results="{:,}".format(results),
            studies_result="{:,}".format(studies_result),
            payload=payload,
            facet_url=request.url,
            params=params,
            paging=paging,
            version=VERSION,
            report_show_url=REPORT_SHOW_URL,
            zfp_viewer=ZFP_VIEWER,
            modalities=params.getlist("Modality"),
            page=page,
            offset=0,
            show_download_options=SHOW_DOWNLOAD_OPTIONS,
            show_transfer_targets=SHOW_TRANSFER_TARGETS,
            transfer_targets=TRANSFER_TARGETS,
            mova_url=MOVA_URL,
            mova_dashboard_url=MOVA_DASHBOARD_URL,
        )
示例#4
0
 def test_pages_only_20_shown(self):
     result = calc(550, '10', 10)
     self.assertEqual(9, len(result))
示例#5
0
 def test_total_pages(self):
     result = calc(100, '0', 10)
     self.assertEqual(5, len(result))
示例#6
0
 def test_last_2(self):
     result = calc(100, '4', 10)
     self.assertEqual(False, result[0][3])
示例#7
0
 def test_last_1(self):
     result = calc(100, '5', 10)
     self.assertEqual(9, len(result))
     self.assertEqual(True, result[0][3])
示例#8
0
 def test_active_3(self):
     result = calc(1200, '5', 100)
     self.assertEqual(True, result[4][1])
示例#9
0
 def test_active_2(self):
     result = calc(1200, '1', 100)
     self.assertEqual(True, result[1][1])
     self.assertEqual(6, len(result))
示例#10
0
 def test_active_1(self):
     result = calc(200, '0', 100)
     self.assertEqual(2, len(result))
     self.assertEqual(True, result[0][1])
示例#11
0
 def test_zero_pages(self):
     result = calc(99, 0, 100)
     self.assertEqual(0, len(result))
示例#12
0
 def test_update_url2(self):
     r = calc(1200, 'http://localhost', '1')
     self.assertEqual('http://localhost?offset=500', r[1][1])
     self.assertEqual(3, len(r))
示例#13
0
 def test_update_url1(self):
     r = calc(200, 'http://localhost', '1')
     self.assertEqual(0, len(r))