changeset 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 810ea40a9ef8
children fee275163ff9
files ismi-python-neo4jrestclient/ismi-vis.py ismi-python-neo4jrestclient/static/commentaries.html
diffstat 2 files changed, 24 insertions(+), 9 deletions(-) [+]
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)))
--- a/ismi-python-neo4jrestclient/static/commentaries.html	Thu Feb 04 15:50:08 2016 +0100
+++ b/ismi-python-neo4jrestclient/static/commentaries.html	Thu Feb 04 17:35:50 2016 +0100
@@ -16,7 +16,7 @@
                             <div class="form-group">
                                 <input type="text" value="jaghmini" placeholder="Search for person name" class="form-control" name="search">
                             </div>
-                            <button class="btn btn-default" type="submit">Search for author name</button>
+                            <button class="btn btn-default" type="submit">Search for author name or id</button>
                         </form>
                     </li>
                 </ul>
@@ -46,6 +46,7 @@
             <table id="results" class="table table-striped table-hover">
                 <thead>
                 <tr>
+                    <th>Author</th>
                     <th>Title (translit)</th>
                     <th>Title (arabic)</th>
                     <th>ismi_id</th>
@@ -166,12 +167,14 @@
                         // clear all marks
                         $("#graph .marked").each(function(){this.classList.remove("marked")});
                         // fill table of titles
+                        var authors = {};
                         data.forEach(function (row) {
                             var text = row.text;
                             var author = row.author;
-                            $("#author").text("Titles by Author: "+author.label+" ["+author.ismi_id+"]");
+                            // collect authors
+                            authors[author.ismi_id] = author;
                             var comm = row.is_commentary || row.has_commentaries;
-                            var $row = $("<tr><td>" + text.label + "</td><td>" + text.full_title + "</td><td class='text_id'>" + text.ismi_id + "</td></tr>").appendTo(t)
+                            var $row = $("<tr><td>" + author.label + "</td><td>"  + text.label + "</td><td>" + text.full_title + "</td><td class='text_id'>" + text.ismi_id + "</td></tr>").appendTo(t)
                                     .click(function() { showText($(this).find("td.text_id").text());});
                             if (comm) {
                                 $row.addClass("marked");
@@ -179,6 +182,11 @@
                             // set mark
                             $("#graph .ismi-"+text.ismi_id).each(function(){this.classList.add("marked")});
                         });
+                        var authorlist = "";
+                        for (var a in authors) {
+                            authorlist += (authorlist ? ", " : "") + authors[a].label + " ["+authors[a].ismi_id+"]";
+                        }
+                        $("#author").text("Titles by: "+authorlist);
                         if (!keep_detail_view) {
                             // show first title in detail view
                             showText(data[0].text.ismi_id);