Mercurial > hg > NetworkVis
diff ismi-python-neo4jrestclient/ismi-vis.py @ 37:7b5dcd3238d2
search field also accepts ismi_ids. display list of authors in head. display author name in title list.
author | casties |
---|---|
date | Thu, 04 Feb 2016 17:35:50 +0100 |
parents | 9f0d4fd3a412 |
children |
line wrap: on
line diff
--- a/ismi-python-neo4jrestclient/ismi-vis.py Thu Feb 04 15:50:08 2016 +0100 +++ b/ismi-python-neo4jrestclient/ismi-vis.py Thu Feb 04 17:35:50 2016 +0100 @@ -153,20 +153,27 @@ try: q = request.args["q"] qs = urllib.parse.quote(q) + norm_js = loadJSON(ismi_db_baseurl + "jsonInterface?method=normalize_string&type=arabic_translit&text=%s"%qs) nq = norm_js.get("normalized_text") except KeyError: return [] else: - #query = ("MATCH (t:TEXT)-[:was_created_by]->(p:PERSON {ismi_id: {id}})" - # " RETURN t,p,exists((t)-[:is_commentary_on]->()),exists(()-[:is_commentary_on]->(t))") - query = ("MATCH (t:TEXT)-[:was_created_by]->(p:PERSON)" - " WHERE p._n_label =~ {name}" - " RETURN t,p,exists((t)-[:is_commentary_on]->()),exists(()-[:is_commentary_on]->(t))") + if qs.isdigit(): + query = ("MATCH (t:TEXT)-[:was_created_by]->(p:PERSON {ismi_id: {id}})" + " RETURN t,p,exists((t)-[:is_commentary_on]->()),exists(()-[:is_commentary_on]->(t))") + param = {"id": int(qs)} + + else: + query = ("MATCH (t:TEXT)-[:was_created_by]->(p:PERSON)" + " WHERE p._n_label =~ {name}" + " RETURN t,p,exists((t)-[:is_commentary_on]->()),exists(()-[:is_commentary_on]->(t))") + param = {"name": ".*%s.*"%nq.lower()} + results = gdb.query( query, returns=(Node,Node,bool,bool), - params={"name": ".*%s.*"%nq.lower()} + params=param ) # {"name": "(?i).*" + q + ".*"} print("search for %s returned %s results"%(repr(q),len(results)))