Commit b8a4907e authored by Romain Loth's avatar Romain Loth

WIP better reldb entries and logic 3 : php side

read the db.json extended format in php + rationalize passed url params
parent cac574fe
......@@ -6,7 +6,7 @@ $elems = json_decode($query);
// the table used as search perimeter is from db.json conf
$table = $my_conf[$ntid]['reldbqtable'] ;
$table = $my_conf["node".$ntid][$dbtype]['qtable'] ;
// values for CortextDB that seem to never change: /!\ hardcoded here /!\
// the column accessors
......@@ -100,7 +100,7 @@ foreach ($wos_ids as $id => $score) {
foreach ($base->query($sql) as $row) {
$external_link="<a href=http://google.com/webhp?#q=".urlencode('"'.$row['data'].'"')." target=blank>".' <img width=15px src="'.$our_libs_root.'/img/google.png"></a>';
$link = 'JavaScript:newPopup(\''.$our_php_root.'/default_doc_details.php?gexf='.urlencode($gexf).'&index='.$table.'&query='.urlencode($query).'&type='.urlencode($_GET['type']).'&id='.$id.' \')';
$link = 'JavaScript:newPopup(\''.$our_php_root.'/default_doc_details.php?gexf='.urlencode($gexf).'&dbtype='.$dbtype.'&query='.urlencode($query).'&ndtype='.$ntid.'&id='.$id.'\')';
if ($output_mode == "html") {
$htmlout.="<li title='".$score."'>";
......
......@@ -6,6 +6,9 @@ $base = new PDO("sqlite:" .$mainpath.$graphdb);
$query = str_replace( '__and__', '&', $_GET["query"] );
$terms_of_query = json_decode($query);
// the table used as search perimeter is from db.json conf
$table = $my_conf["node".$ntid][$dbtype]['qtable'] ;
// echo "mainpath: ".$mainpath."<br>";
// echo "thedb: ".$mainpath.$graphdb."<br>";
// echo "thequery: ".var_dump($terms_of_query);
......@@ -32,7 +35,7 @@ echo '
<div id="tabs">
<ul>
<li><a href="#tabs-1">Selected Document</a></li>
<li><a href="full_doc_list.php?'.'gexf='.urlencode($gexf).'&query='.urlencode($_GET["query"]).'&index='.$_GET["index"].'&type='.urlencode($_GET["type"]).'">Full list</a></li>';
<li><a href="full_doc_list.php?'.'gexf='.urlencode($gexf).'&query='.urlencode($_GET["query"]).'&ndtype='.$ntid.'&dbtype='.$dbtype.'">Full list</a></li>';
echo '</ul>';
echo '<div id="tabs-1">';
......@@ -81,7 +84,7 @@ $id=$_GET["id"];
// }
// // get the date
if(strpos($_GET["index"],'terms') ) $sql = 'SELECT data FROM '.$_GET["index"].' WHERE id='.$id;
if(strpos($table,'terms') ) $sql = "SELECT data FROM $table WHERE id=".$id;
else $sql = 'SELECT data FROM ISItermsListV1 WHERE id='.$id;
$output.='<br/><b>Keywords: </b>';
$terms=array();
......
......@@ -8,7 +8,7 @@ $base = new PDO("sqlite:" .$mainpath.$graphdb);
$output = "<ul>"; // string sent to the javascript for display
$type = $_GET["type"];
$type = $_GET["ndtype"];
$query = str_replace( '__and__', '&', $_GET["query"] );
$terms_of_query=json_decode($_GET["query"]);
$elems = json_decode($query);
......@@ -19,25 +19,20 @@ foreach ($base->query($sql) as $row) {
$table_size=$row['COUNT(*)'];
}
$table = "";
$column = "";
$id="";
// the table used as search perimeter is from db.json conf
$table = $my_conf["node".$ntid][$dbtype]['qtable'] ;
if($type=="social"){
$table = "ISIAUTHOR";
$column = "data";
$id = "id";
$restriction='';
$factor=10;// factor for normalisation of stars
}
// values for CortextDB that seem to never change: /!\ hardcoded here /!\
// the column accessors
$column = "data";
$id = "id";
if($type=="semantic"){
$table = $_GET["index"];
$column = "data";
$id = "id";
$restriction='';
$factor=10;
}
// the output tables
$author_table = "ISIAUTHOR";
$titles_table = "ISITITLE";
$factor=10;// factor for normalisation of stars
$restriction='';
$sql = 'SELECT count(*),'.$id.'
......@@ -88,7 +83,7 @@ foreach ($wos_ids as $id => $score) {
$count+=1;
$output.="<li title='".$score."'>";
$output.=imagestar($score,$factor,'./').' ';
$sql = 'SELECT data FROM ISITITLE WHERE id='.$id." group by data";
$sql = "SELECT data FROM $titles_table WHERE id=".$id." group by data";
foreach ($base->query($sql) as $row) {
$output.='<a href="default_doc_details.php?gexf='.urlencode($gexf).'&type='.urlencode($_GET["type"]).'&query='.urlencode($query).'&id='.$id.'">'.$row['data']." </a> ";
......@@ -96,7 +91,7 @@ foreach ($wos_ids as $id => $score) {
}
// get the authors
$sql = 'SELECT data FROM ISIAUTHOR WHERE id='.$id;
$sql = "SELECT data FROM $author_table WHERE id=".$id;
foreach ($base->query($sql) as $row) {
$output.=strtoupper($row['data']).', ';
}
......
......@@ -14,25 +14,6 @@ if ($output_mode == "json") {
header('Content-Type: application/json');
}
$dbtype = null;
if (array_key_exists('reldbtype', $my_conf[$ntid])) {
$dbtype = $my_conf[$ntid]['reldbtype'];
}
else {
$guess_src = '';
if (array_key_exists('dbtype', $_GET)) {
$dbtype = $_GET['dbtype'];
$guess_src = "via url parameters";
}
else {
$dbtype = 'csv'; // new default
$guess_src = "by default";
}
errmsg("not filled", "$gexf -> node$ntid -> 'reldbtype'", "...Assuming dbtype is $dbtype ($guess_src).");
}
if ($dbtype == "CortextDB") {
$base = new PDO("sqlite:".$mainpath.$graphdb);
include('default_div.php');
......@@ -42,15 +23,19 @@ else {
// to index: the union of "searchable columns" qcols for all nodetypes
$idxcolsbytype = [];
for ($i = 0; $i < $ntypes ; $i++) {
if ($my_conf[$i]['active']) {
$idxcolsbytype[$i] = [];
$idxcolsbytype[$i] = $my_conf[$i]['reldbqcols'];
}
else {
echo("<p>Your settings for relatedDocsType are set on a local database,
but your servermenu file does not provide any information about
the CSV or DB table to query for related documents
(on nodetypeId ".$i.")</p>");
// if nodetype is active
if (count($my_conf["node".$i])) {
// ... and well-formed
if (array_key_exists('qcols', $my_conf["node".$i][$dbtype])) {
$idxcolsbytype[$i] = $my_conf["node".$i][$dbtype]['qcols'];
}
else {
echo("<p>Your settings for relatedDocsType are set on a local database,
but your servermenu file does not provide any information about
the CSV or DB table to query for related documents
(on nodetypeId ".$i.")</p>");
}
}
}
......@@ -101,7 +86,7 @@ else {
// DO THE SEARCH
// -------------
$searchcols = $my_conf[$ntid]['reldbqcols'];
$searchcols = $my_conf["node".$ntid][$dbtype]['qcols'];
// a - split the query
$qtokens = preg_split('/\W/', $_GET["query"]);
......
......@@ -48,7 +48,8 @@ $conf = read_conf($mainpath.$project_menu_path, $ntypes, $supported_dbtypes);
// =======================================
$gexf= str_replace('"','',$_GET["gexf"]);
$ntid = $_GET["type"];
$ntid = $_GET["ndtype"];
$dbtype = $_GET["dbtype"];
$ndtype = null;
$my_conf = null;
......@@ -58,13 +59,21 @@ else { $ndtype = 'semantic'; }
// echodump("params: node type id", $ntid);
if (! $conf[$gexf][$ntid]['active']) {
errmsg("not active", "your graph ($gexf)");
if (! count($conf[$gexf]['node'.$ntid])) {
errmsg("has no php reldbs configured for nodetype $ntid", "your graph ($gexf)");
exit(1);
}
else if (! array_key_exists($dbtype, $conf[$gexf]['node'.$ntid])) {
errmsg("reldbs isn't configured for nodes of type $ntid and dbtype $dbtype", "your graph ($gexf)");
exit(1);
}
else if (! array_key_exists('file', $conf[$gexf]['node'.$ntid][$dbtype])) {
errmsg("reldb has no DB file for nodes of type $ntid and dbtype $dbtype", "your graph ($gexf)");
exit(1);
}
else {
$my_conf = $conf[$gexf];
$graphdb = $my_conf[$ntid]['dir'].'/'.$my_conf[$ntid]['reldbfile'];
$graphdb = $my_conf['node'.$ntid][$dbtype]['file'];
}
// echodump("params: reldb", $graphdb);
......
......@@ -11,12 +11,14 @@ function echodump($title, $anyObj) {
function errmsg($message, $context, $more = "") {
echo "<p class='micromessage'>The relatedDocs DB conf for $context is $message
echo "<p class='micromessage'>The relatedDocs DB conf for $context $message
(please read A-Introduction/servermenu_config.md).<br>$more</p>";
}
// reading db.json associations
// source graph file <=> (db, dbtype, cols) as relatedDocs php API
// 1) we filter db.json entries by active/inactive nodetypes
// 2) we filter db.json entries by supported dbtypes
function read_conf($filepath, $ntypes, $our_dbtypes) {
$project_menu_fh = fopen($filepath, "r");
$json_st = '';
......@@ -37,7 +39,7 @@ function read_conf($filepath, $ntypes, $our_dbtypes) {
continue;
}
foreach ($dir_items->graphs as $graph_file => $graph_conf){
echodump("== $graph_file ==", $graph_conf);
// echodump("== $graph_file ==", $graph_conf);
$gpath = $project_dir.'/'.$graph_file;
......@@ -47,42 +49,38 @@ function read_conf($filepath, $ntypes, $our_dbtypes) {
// NB2 now additionnally, each nodetype can have several dbs configured !
$conf[$gpath] = array($ntypes);
// $conf[$gpath] = array($ntypes);
for ($i = 0 ; $i < $ntypes ; $i++) {
$conf[$gpath]['node'.$i] = array();
// check node0, node1, etc to see if they at least have a reldb conf
if (! property_exists($graph_conf, 'node'.$i)
|| ! property_exists($graph_conf->{'node'.$i}, 'reldbs') ) {
if (property_exists($graph_conf, 'node'.$i)
&& property_exists($graph_conf->{'node'.$i}, 'reldbs') ) {
// all dbtypes inactive on this file and nodetype
foreach ($our_dbtypes as $dbtype) {
// $conf[$gpath][$i][$dbtype] = array('active' => false);
$conf[$gpath][$i] = array('active' => false);
}
continue;
}
else {
// further check for each configured db that is listed under reldbs
// check for each configured db that is listed under reldbs
$dbinfos = $graph_conf->{'node'.$i}->reldbs;
foreach ($dbinfos as $dbtype => $dbconf) {
echodump("reldbtype", $dbtype);
echodump("reldbconf", $dbconf);
// valid conf cases
// filter: supported and valid conf cases
if (in_array($dbtype, $our_dbtypes) && $dbconf->file) {
// we have a file for this nodetype and dbtype: copy entire conf
$conf[$gpath][$i][$dbtype] = array();
$test = (array)$dbconf;
echodump("conf copy", $test);
// $conf[$gpath][$i][$dbtype] = (array)$dbconf;
$conf[$gpath]['node'.$i][$dbtype] = (array)$dbconf ;
// update files path with dirpath
if (array_key_exists('file', $conf[$gpath]['node'.$i][$dbtype])) {
$relpath = $conf[$gpath]['node'.$i][$dbtype]['file'];
$conf[$gpath]['node'.$i][$dbtype]['file'] = $project_dir.'/'.$relpath;
}
}
}
echodump("got conf", $conf[$gpath][$i]);
// echodump("got conf", $conf[$gpath]['node'.$i]);
}
// $conf[$gpath][$i]['active'] = true;
// $conf[$gpath][$i]['dir'] = $project_dir;
else {
// empty array <=> inactive nodetype or no supported dbs
$conf[$gpath]['node'.$i] = array ();
}
// POSS here info on higher level may be propagated for lower ones
// (ex: if dbtype is on the project level, its value should count
......@@ -90,6 +88,8 @@ function read_conf($filepath, $ntypes, $our_dbtypes) {
}
}
}
// echodump("full conf", $conf);
return $conf;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment