Skip to content

Commit e15b5e2

Browse files
committed
Update search endpoint to handle counts properly, fix imports
1 parent e9ce3b0 commit e15b5e2

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

src/indra_cogex/apps/search/search.py

+28-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import json
22
from typing import List, Optional, Mapping, Tuple
33

4-
from flask import Blueprint, render_template, request, jsonify, redirect, url_for
4+
from flask import (
5+
Blueprint,
6+
render_template,
7+
request,
8+
jsonify,
9+
redirect,
10+
url_for,
11+
current_app,
12+
)
513
from flask_jwt_extended import jwt_required
614
from flask_wtf import FlaskForm
715
from indra.statements import get_all_descendants, Statement
@@ -11,14 +19,12 @@
1119

1220
from indra_cogex.apps.utils import render_statements
1321
from indra_cogex.client import Neo4jClient, autoclient
14-
from indra_cogex.client.queries import *
15-
from indra_cogex.representation import norm_id
22+
from indra_cogex.client.queries import enrich_statements, get_statements
23+
from indralab_auth_tools.auth import resolve_auth
24+
from indra_cogex.representation import norm_id, indra_stmts_from_relations
1625

17-
__all__ = ["search_blueprint"]
18-
19-
from indra_cogex.client.queries import enrich_statements
2026

21-
from indra_cogex.representation import indra_stmts_from_relations
27+
__all__ = ["search_blueprint"]
2228

2329
search_blueprint = Blueprint("search", __name__, url_prefix="/search")
2430

@@ -44,6 +50,8 @@ def search():
4450
stmt_types = {c.__name__ for c in get_all_descendants(Statement)}
4551
stmt_types -= {"Influence", "Event", "Unresolved"}
4652
stmt_types_json = json.dumps(sorted(list(stmt_types)))
53+
user, roles = resolve_auth(dict(request.args))
54+
remove_medscan = user is None
4755

4856
form = SearchForm()
4957

@@ -92,7 +100,7 @@ def search():
92100

93101
# Fetch and display statements
94102
if agent or other_agent or rel_types:
95-
statements, evidence_count = get_statements(
103+
statements, source_count = get_statements(
96104
agent=agent,
97105
agent_role=agent_role,
98106
other_agent=other_agent,
@@ -103,9 +111,18 @@ def search():
103111
mesh_term=mesh_terms,
104112
limit=1000,
105113
evidence_limit=1000,
106-
return_evidence_counts=True,
114+
return_source_counts=True,
115+
)
116+
# Create evidence count from source count
117+
evidence_count = {
118+
k: sum(v.values()) for k, v in source_count.items()
119+
}
120+
return render_statements(
121+
stmts=statements,
122+
evidence_counts=evidence_count,
123+
remove_medscan=remove_medscan,
124+
source_counts_dict=source_count,
107125
)
108-
return render_statements(stmts=statements, evidence_count=evidence_count)
109126

110127
# Render the form page
111128
return render_template(
@@ -115,10 +132,7 @@ def search():
115132
)
116133

117134

118-
from flask import current_app
119-
120-
121-
@search_blueprint.route("/gilda_ground", methods=["GET", "POST"])
135+
@search_blueprint.route("/gilda_ground", methods=["POST"])
122136
@jwt_required(optional=True)
123137
def gilda_ground_endpoint():
124138
data = request.get_json()

0 commit comments

Comments
 (0)