Hello!

To see the file structure, click on "tree".

Note that updates take place every 10 minutes, commits may not be seen immediately.
Modified queries to provide more fields from the AmiGO db.
authorpreecej <preecej@localhost>
Fri, 15 Jul 2011 18:11:15 +0000 (18:11 +0000)
committerpreecej <preecej@localhost>
Fri, 15 Jul 2011 18:11:15 +0000 (18:11 +0000)
svn path=/; revision=120

preecej/semantic_wiki/prototyping/TermSearch_JSON.php

index acf76689586af5e629ff7327cb4aae8768b1134a..ab57a6adc8ddff6bb609d4b8be770b8a846235e6 100644 (file)
@@ -22,23 +22,23 @@ if(isset($_GET['user']) && ($_GET['user']) == 'paw') {
             ? strtolower($_GET['qval'])
             : die('Please provide a searchable value');
 
-        // optional, for type 'lookup'
-        if ($type == 'lookup' && isset($_GET['ret_field']) && in_array($_GET['ret_field'],$arr_field_names)) {
-           $ret_field = $_GET['ret_field'];
-        }
-        
         $format = strtolower($_GET['format']) != 'json' 
             ? strtolower($_GET['format']) 
             : 'json'; //json is the default
         
         /* connect to the db */
-        $link = mysql_connect('floret.cgrb.oregonstate.edu', 'po-read-user', 'po-read-user_pw') or die('Cannot connect to the DB');
-        mysql_select_db('po_beta',$link) or die('Cannot select the DB');
+        $link = mysql_connect($_SERVER['mysql_host'], $_SERVER['mysql_user'], $_SERVER['mysql_pw']) or die('Cannot connect to the DB');
+        mysql_select_db($_SERVER['mysql_db'],$link) or die('Cannot select the DB');
 
         switch ($type) {
             case 'autocomplete':
                 /* grab the terms from the db */
-                $query = "select $field from term where $field like '%$qval%' ORDER BY name LIMIT $number_of_terms";
+                $query = "SELECT t.$field FROM term t"
+                    . " LEFT JOIN term_definition d ON d.term_id = t.id"
+                    . " WHERE t.$field LIKE '%$qval%'"
+                    . " AND UCASE(t.name) NOT LIKE 'OBSOLETE%'"
+                    . " AND UCASE(d.term_definition) NOT LIKE 'OBSOLETE%'"
+                    . " ORDER BY name LIMIT $number_of_terms";
                 $result = mysql_query($query,$link) or die('Errant query:  '.$query);
             
                 /* create one master array of the records */
@@ -59,23 +59,33 @@ if(isset($_GET['user']) && ($_GET['user']) == 'paw') {
                 }
                 break;
 
-            case 'lookup':
-                /* grab the terms from the db */
-                $query = "select distinct $ret_field from term where $field = '$qval' ORDER BY name LIMIT 1";
+            case 'term_detail':
+                /* grab the ontology data from the db */
+                $query = "SELECT DISTINCT t.acc as 'acc', t.term_type as 'type', d.term_definition as 'definition', d.term_comment as 'comment'"
+                    . " FROM term t"
+                    . " LEFT JOIN term_definition d ON d.term_id = t.id"
+                    . " WHERE t.name = '$qval'"
+                    . " AND t.term_type in ('plant_anatomy','plant_growth_and_development_stage')"
+                    . " AND UCASE(t.name) NOT LIKE 'OBSOLETE%'"
+                    . " AND UCASE(d.term_definition) NOT LIKE 'OBSOLETE%'"
+                    . " ORDER BY t.name LIMIT 1";
                 $result = mysql_query($query,$link) or die('Errant query:  '.$query);
             
                 /* create one master array of the records */
                 $terms = array();
                 if(mysql_num_rows($result)) {
                     while($term = mysql_fetch_assoc($result)) {
-                        $terms[] = array('title'=>$term[$ret_field]);
+                        $terms[] = array(
+                            'id'=>$term['acc'],
+                            'aspect'=>$term['type'] == "plant_anatomy" ? "Plant Anatomy" : "Plant Growth and Development Stage",
+                            'definition'=>$term['definition'],
+                            'comment'=>$term['comment']);
                     }
                 }
-                // TODO: change this to the necessary output for #get_web_data wiki call 
                 /* output in necessary format */
                 if($format == 'json') {
                     header('Content-type: application/json');
-                    echo json_encode(array('sfautocomplete'=>$terms));
+                    echo json_encode(array('PO_result'=>$terms));
                 }
                 else {
                     die('Sorry, this request cannot be fulfilled in '.$format.' format.');