diff app/query.service.ts @ 32:4c046f3244ec

new 'id_is' query type. new '_type' attribute.
author casties
date Tue, 02 Feb 2016 19:20:44 +0100
parents 193271b6b9d2
children e19d4c5e10a1
line wrap: on
line diff
--- a/app/query.service.ts	Mon Feb 01 20:10:55 2016 +0100
+++ b/app/query.service.ts	Tue Feb 02 19:20:44 2016 +0100
@@ -16,7 +16,8 @@
     //public neo4jBaseUrl = 'https://ismi-dev.mpiwg-berlin.mpg.de/neo4j-ismi/db/data';
     public neo4jBaseUrl = 'http://localhost:7474/db/data';
     public neo4jAuthentication = {'user': 'neo4j', 'password': 'neo5j'};
-    public excludedAttributes = {'type': true};
+    public typeAttribute = '_type';
+    public excludedAttributes = {};
     public invRelPrefix = '<- ';
     public state: QueryState;
     public objectTypes: string[];
@@ -116,6 +117,29 @@
             }
             
             /*
+             * step: object id is
+             */
+            if (mode === 'id_is') {
+                if (!queryMatch) {
+                    // first step - use match clause
+                    queryMatch = `MATCH (n${nIdx} {ismi_id: {att_val${stepIdx}}})`;
+                    queryParams[`att_val${stepIdx}`] = parseInt(params.value, 10);
+                    queryWhere = '';
+                    queryReturn =  `RETURN n${nIdx}`;
+                    returnType = 'node';
+                } else {
+                    // use where clause
+                    if (!queryWhere) {
+                        queryWhere = 'WHERE ';
+                    } else {
+                        queryWhere += ' AND ';
+                    }
+                    queryWhere += `n${nIdx}.ismi_id = {att_val${stepIdx}}`;                    
+                    queryParams[`att_val${stepIdx}`] = parseInt(params.value, 10);
+                }
+            }
+            
+            /*
              * step: relation type is
              */
             if (mode === 'relation_is') {
@@ -174,7 +198,7 @@
             
         });
         // compose query
-        resultQuery = queryMatch + '\n' + queryWhere + '\n' + queryReturn;
+        resultQuery = queryMatch + (queryWhere ? '\n'+queryWhere : '') + '\n' + queryReturn;
         // compose query for attributes of result
         attributesQuery = queryMatch + ' ' + queryWhere + ` WITH DISTINCT keys(n${nIdx}) AS atts`
             + ` UNWIND atts AS att RETURN DISTINCT att ORDER BY att`;
@@ -219,15 +243,16 @@
                 this.state.results = data.results[resIdx].data.map(elem => elem.row[0]);
                 this.state.numResults = this.state.results.length;
                 // count all types
-                var resTypes = {};
+                let resTypes = {};
                 this.state.results.forEach((r) => {
-                    if (resTypes[r.type] == null) {
-                        resTypes[r.type] = 1;
+                    let t = r[this.typeAttribute];
+                    if (resTypes[t] == null) {
+                        resTypes[t] = 1;
                     } else {
-                        resTypes[r.type] += 1;
+                        resTypes[t] += 1;
                     }
                 });
-                var info = '';
+                let info = '';
                 for (var t in resTypes) {
                     info += t + '(' + resTypes[t] + ') ';   
                 }