Commit 29744782 authored by Romain Loth's avatar Romain Loth

new MySQL connectors for comex directory/filter operations

parent 0d619851
### List of features that where deactivated
During rewrite we deactivated some retrieval to match the new sql tables from registration:
- tables organizations, labs don't exist => TODO RESTORE in `directory_content.php` (and therefore empty arrays are passed to `labs_list.php` and `orga_list.php`)
- in `search_scholar.php`, column nb_keywords doesn't exist (and now keywords are never 0) => TODO RESTORE
- in `print_directory.php`, all the following columns are now ignored: 'nb_keywords', 'css_voter', 'css_member', 'keywords_ids', 'status', 'homepage', 'lab2', 'affiliation2', 'homepage', **'position'** (used in `stats_prep_from_array.php`), 'photo_url', 'address', 'city', 'postal_code', 'phone', 'mobile', 'fax', 'affiliation_acronym' => TODO RESTORE
- in `print_scholar_directory.php`
- similar changes as above
- additional change to keywords_ids search in old "scholars2terms" table => becomes `LIKE` search in keywords: TODO index
...@@ -16,14 +16,16 @@ function clean_exp($string){ ...@@ -16,14 +16,16 @@ function clean_exp($string){
} }
} }
function get_value($cle_value,$table='data',$cle='cle',$valeur='valeur'){
// NB actually (2016-12) this is unused TODO use !!!
function get_value($cle_value,$table='data',$cle='cle',$valeur='valeur'){
// renvoie la valeur correspondant à la clé $cle dans la table data // renvoie la valeur correspondant à la clé $cle dans la table data
$sql = 'SELECT '.$valeur.' from '.$table.' WHERE '.$cle.'="'.trim($cle_value).'"'; $sql = 'SELECT '.$valeur.' from '.$table.' WHERE '.$cle.'="'.trim($cle_value).'"';
$resultat=mysql_query($sql); $resultat=mysql_query($sql);
while ($ligne=mysql_fetch_array($resultat)) { while ($ligne=mysql_fetch_array($resultat)) {
$out=$ligne[$valeur]; $out=$ligne[$valeur];
} }
return $out; return $out;
} }
?> ?>
This diff is collapsed.
<?php <?php
/* /* liste de parametres */
list de parametres.
*/
$dbname='/home/jbilcke/databases/scholar_test_data.db';
$dbname='community.db'; $dbname='community.db';
//$dbname='scholar_test_data.db';
//$scholars_db ="raw_scholars";
$fichier = "CSSscholars20Oct2011.csv";
$fichier = "CSSscholars2Oct2011.csv";
$lab_csv="CSLabs13Fev2012.csv";
$orga_csv='';
$min_num_friends=0;// nombre minimal de voisin que doit avoir un scholar pour être affiché $min_num_friends=0;// nombre minimal de voisin que doit avoir un scholar pour être affiché
//$fichier = "Scholars13Sept2011.csv"; // $compress='No';
//$fichier = "test2.csv";
$drop_tables=true; // on efface les tables
$language='english';
$file_sep=',';
//$scholar_filter=" where country='France' AND status='o'";
//$scholar_filter=" where country='France' AND want_whoswho='Yes' AND css_member='Yes'";
//$scholar_filter=" where css_member='Yes' AND want_whoswho='Yes'";
//$scholar_filter=" where css_member='Yes' OR want_whoswho='Yes'";
$scholar_filter="where css_member='Yes'";
//$scholar_filter="";
//$scholar_filter=" where country='France' AND want_whoswho='Yes'";
//$scholar_filter=" where country='France'";
$compress='No';
/* parametres externes: nom de l'hôte SQL*/
$params = parse_ini_file("parametres_comex.ini");
/* tout pour le MySQL */
$host = $params['SQL_HOST'];
$db = 'comex_shared';
$user = 'root';
$pass = 'very-safe-pass';
$charset = 'utf8';
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
?> ?>
This diff is collapsed.
...@@ -72,27 +72,33 @@ function is_utf8($string) { ...@@ -72,27 +72,33 @@ function is_utf8($string) {
$login = $_GET['query']; $login = $_GET['query'];
$base = new PDO("sqlite:" . $dbname); // $base = new PDO("sqlite:" . $dbname);
$base = new PDO($dsn, $user, $pass, $opt);
if ($login) { if ($login) {
if (sizeof($login) > 0) { if (sizeof($login) > 0) {
// liste des chercheurs // liste des chercheurs
$sql = "SELECT keywords_ids,last_name,first_name FROM scholars where unique_id='" . $login . "'"; $sql = "SELECT keywords,last_name,first_name FROM comex_registrations WHERE doors_uid='" . $login . "'";
foreach ($base->query($sql) as $row) { foreach ($base->query($sql) as $row) {
$keywords_ids = explode(',', $row['keywords_ids']); $keywords = explode(',', $row['keywords']);
$scholar_array = array(); $scholar_array = array();
$target_name=$row['first_name'].' '.$row['last_name']; $target_name=$row['first_name'].' '.$row['last_name'];
foreach ($keywords_ids as $keywords_id) { foreach ($keywords as $keyword) {
$sql2 = "SELECT * FROM scholars2terms where term_id=" . trim($keywords_id); if (strlen($keyword) > 0) {
#pt($sql2);
foreach ($base->query($sql2) as $row) {
if (array_key_exists($row['scholar'], $scholar_array)){
$scholar_array[$row['scholar']] += 1;
}else{
$scholar_array[$row['scholar']] = 1;
}
// TODO RESTORE index keywords
// $sql2 = "SELECT * FROM scholars2terms where term_id=" . trim($keywords_id);
$sql2 = "SELECT doors_uid FROM comex_registrations WHERE keywords LIKE \"%" . trim($keyword)."%\"";
// echo($sql2."<br/>");
foreach ($base->query($sql2) as $row) {
if (array_key_exists($row['doors_uid'], $scholar_array)){
$scholar_array[$row['doors_uid']] += 1;
}else{
$scholar_array[$row['doors_uid']] = 1;
}
}
} }
} }
} }
...@@ -100,48 +106,51 @@ if ($login) { ...@@ -100,48 +106,51 @@ if ($login) {
} }
} }
// les scholars sont affichés par ordre de pertinence // les scholars sont affichés par ordre de pertinence
arsort($scholar_array); arsort($scholar_array);
$scholar_id_array=array_keys($scholar_array);
// echo var_dump($scholar_id_array)."<br/>" ;
$scholar_id_array=array_keys($scholar_array);
// liste des chercheurs // liste des chercheurs
$scholars = array(); $scholars = array();
//
foreach ($scholar_id_array as $scholar_id){ foreach ($scholar_id_array as $scholar_id){
$sql = "SELECT * FROM scholars where unique_id='" . $scholar_id. "'"; $sql = "SELECT * FROM comex_registrations where doors_uid='" . $scholar_id. "'";
// echo var_dump($scholar_id)."<br/>" ;
//$query = "SELECT * FROM scholars"; //$query = "SELECT * FROM scholars";
foreach ($base->query($sql) as $row) { foreach ($base->query($sql) as $row) {
$info = array(); $info = array();
$info['unique_id'] = $row['unique_id']; $info['unique_id'] = $row['doors_uid'];
$info['first_name'] = $row['first_name']; $info['first_name'] = $row['first_name'];
$info['initials'] = $row['initials']; $info['initials'] = $row['initials'];
$info['last_name'] = $row['last_name']; $info['last_name'] = $row['last_name'];
$info['nb_keywords'] = $row['nb_keywords']; // $info['nb_keywords'] = $row['nb_keywords'];
$info['css_voter'] = $row['css_voter']; // $info['css_voter'] = $row['css_voter'];
$info['css_member'] = $row['css_member']; // $info['css_member'] = $row['css_member'];
$info['keywords_ids'] = explode(',', $row['keywords_ids']); // $info['keywords_ids'] = explode(',', $row['keywords_ids']);
$info['keywords'] = $row['keywords']; $info['keywords'] = $row['keywords'];
$info['status'] = $row['status']; // $info['status'] = $row['status'];
$info['country'] = $row['country']; $info['country'] = $row['country'];
$info['homepage'] = $row['homepage']; // $info['homepage'] = $row['homepage'];
$info['lab'] = $row['lab']; $info['lab'] = $row['team_lab'];
$info['affiliation'] = $row['affiliation']; $info['affiliation'] = $row['institution'];
$info['lab2'] = $row['lab2']; // $info['lab2'] = $row['lab2'];
$info['affiliation2'] = $row['affiliation2']; // $info['affiliation2'] = $row['affiliation2'];
$info['homepage'] = $row['homepage']; // $info['homepage'] = $row['homepage'];
$info['title'] = $row['title']; $info['title'] = $row['jobtitle'];
$info['position'] = $row['position']; $info['position'] = $row['jobtitle'];
$info['photo_url'] = $row['photo_url']; // $info['photo_url'] = $row['photo_url'];
$info['interests'] = $row['interests']; $info['pic_file'] = $row['pic_file'];
$info['address'] = $row['address']; $info['interests'] = $row['interests_text'];
$info['city'] = $row['city']; // $info['address'] = $row['address'];
$info['postal_code'] = $row['postal_code']; // $info['city'] = $row['city'];
$info['phone'] = $row['phone']; // $info['postal_code'] = $row['postal_code'];
$info['mobile'] = $row['mobile']; // $info['phone'] = $row['phone'];
$info['fax'] = $row['fax']; // $info['mobile'] = $row['mobile'];
$info['affiliation_acronym'] = $row['affiliation_acronym']; // $info['fax'] = $row['fax'];
$scholars[$row['unique_id']] = $info; // $info['affiliation_acronym'] = $row['affiliation_acronym'];
$scholars[$row['doors_uid']] = $info;
} }
} }
...@@ -210,7 +219,7 @@ Contributions and ideas are welcome to improve this directory. ...@@ -210,7 +219,7 @@ Contributions and ideas are welcome to improve this directory.
echo $meta.' '.$stats.'</head>'; echo $meta.' '.$stats.'</head>';
if (count($scholars)==0){ if (count($scholars)==0){
echo '<h2>Sorry, '.$target_name.' did not mentioned any keywords ... we cannot process it\'s network.</h2><br/> echo '<h2>Sorry, '.$target_name.' did not mention any keywords ... we cannot process its network.</h2><br/>
If you are '.$target_name.', you can <a href="http://main.csregistry.org/Whoswhodata" target="_BLANK">modify your profile</a> and see your If you are '.$target_name.', you can <a href="http://main.csregistry.org/Whoswhodata" target="_BLANK">modify your profile</a> and see your
network in few minutes.'; network in few minutes.';
}else{ }else{
......
<?php <?php
/* /*
* Génère le gexf des scholars à partir de la base sqlite * Génère le gexf des scholars à partir de la base mysql
*/ */
include("parametres.php"); include("parametres.php");
//include("../common/library/fonctions_php.php"); //include("../common/library/fonctions_php.php");
include("normalize.php"); include("normalize.php");
$base = new PDO("sqlite:" . $dbname); $base = new PDO($dsn, $user, $pass, $opt);
$category = trim(strtolower($_GET['category'])); $category = trim(strtolower($_GET['category']));
$term = trim(strtolower($_GET['term'])); $term = trim(strtolower($_GET['term']));
...@@ -20,7 +20,10 @@ if ($category == 'country' || $category == 'countries') { ...@@ -20,7 +20,10 @@ if ($category == 'country' || $category == 'countries') {
$cat = "country"; $cat = "country";
$query = 'LIKE upper(\''.strtoupper($q).'\')'; $query = 'LIKE upper(\''.strtoupper($q).'\')';
} elseif ($category == 'organization' || $category == 'organizations') { } elseif ($category == 'organization' || $category == 'organizations') {
$cat = "affiliation";
// POSSIBLE: `concat(institution, ", ", IFNULL(team_lab, ""))``
// (change in $cat here and in print_directory args downstream)
$cat = 'institution';
$query = 'LIKE upper(\''.strtoupper($q).'\')'; $query = 'LIKE upper(\''.strtoupper($q).'\')';
} elseif ($category == 'keyword' || $category == 'keywords') { } elseif ($category == 'keyword' || $category == 'keywords') {
$cat = "keywords"; $cat = "keywords";
...@@ -29,7 +32,7 @@ if ($category == 'country' || $category == 'countries') { ...@@ -29,7 +32,7 @@ if ($category == 'country' || $category == 'countries') {
$cat = "tags"; $cat = "tags";
$query = 'LIKE upper(\''.strtoupper($q).'\')'; $query = 'LIKE upper(\''.strtoupper($q).'\')';
} elseif ($category == 'labs' || $category == 'laboratories' || $category == 'laboratory') { } elseif ($category == 'labs' || $category == 'laboratories' || $category == 'laboratory') {
$cat = "lab"; $cat = "team_lab";
$query = 'LIKE upper(\''.strtoupper($q).'\')'; $query = 'LIKE upper(\''.strtoupper($q).'\')';
} else { } else {
echo ("ERROR"); echo ("ERROR");
...@@ -41,17 +44,18 @@ $filtered = array ( ...@@ -41,17 +44,18 @@ $filtered = array (
); );
function filter_word($value) { function filter_word($value) {
if ($value == null) return true; if ($value == null) return true;
return ! in_array(strtolower($value),$filtered); return ! in_array(strtolower($value),$filtered);
} }
$req = "SELECT ".$cat." AS key, count(".$cat.") AS value FROM scholars WHERE ".$cat." ".$query." GROUP BY ".$cat." ORDER BY value DESC"; $req = "SELECT ".$cat." AS clef, count(".$cat.") AS value FROM comex_registrations WHERE ".$cat." ".$query." GROUP BY ".$cat." ORDER BY value DESC";
// echo $req;
$results = array(); $results = array();
$i = 0; $i = 0;
foreach ($base->query($req) as $row) { foreach ($base->query($req) as $row) {
$nb = $row['value']; $nb = $row['value'];
if ($cat == "keywords" || $cat == "tags") { if ($cat == "keywords" || $cat == "tags") {
//echo "in keywords\n"; //echo "in keywords\n";
$words = explode(",", $row["key"]); $words = explode(",", $row["clef"]);
foreach ($words as $word) { foreach ($words as $word) {
$pos = strpos($word,$term); $pos = strpos($word,$term);
...@@ -69,9 +73,9 @@ foreach ($base->query($req) as $row) { ...@@ -69,9 +73,9 @@ foreach ($base->query($req) as $row) {
} }
} }
} else { } else {
$word = $row["key"]; $word = $row["clef"];
if ($cat == "country") { if ($cat == "country") {
$word = normalize_country($word); $word = normalize_country($word);
} }
if (filter_word($word)) { if (filter_word($word)) {
...@@ -98,7 +102,7 @@ foreach($results as $key => $value) { ...@@ -98,7 +102,7 @@ foreach($results as $key => $value) {
'label' => $key, 'label' => $key,
// 'value' => $value, // 'value' => $value,
'score' => $value, 'score' => $value,
// F*** it, I'll put the meta data here... // F*** it, I'll put the meta data here...
'category' => $cat, 'category' => $cat,
"term" => $term, "term" => $term,
...@@ -110,4 +114,4 @@ foreach($results as $key => $value) { ...@@ -110,4 +114,4 @@ foreach($results as $key => $value) {
$i = 0; $i = 0;
echo json_encode($completion); echo json_encode($completion);
?> ?>
\ No newline at end of file
...@@ -8,79 +8,114 @@ include("parametres.php"); ...@@ -8,79 +8,114 @@ include("parametres.php");
include("normalize.php"); include("normalize.php");
$base = new PDO("sqlite:" . $dbname);
$category = trim(strtolower($_GET['category'])); // ===================== SQL connect =====================
$login = trim(strtolower($_GET['login'])); $base = new PDO($dsn, $user, $pass, $opt);
$q = "%".sanitize_input($login)."%"; // ==================== /SQL connect =====================
//echo "category: ".$category.";";
//echo "login: ".$login.";";
//echo "q: ".$q.";";
$cat = '';
$query = '';
if ($category == 'login') {
$cat = "unique_id";
$query = 'unique_id LIKE upper(\''.strtoupper($q).'\')';
} elseif ($category == 'firstname') {
$cat = "firstname";
$query = 'first_name LIKE upper(\''.strtoupper($q).'\')';
} elseif ($category == 'lastname') {
$cat = "lastname";
$query = 'last_name LIKE upper(\''.strtoupper($q).'\')';
} else {
echo ("ERROR");
exit();
}
$filtered = array ( // ==================== new retrieval ======================
"yes", "1", "0", "nvgfpmeilym", "no", "mr", "ms", "", " ", " " $login = trim(strtolower($_GET['login']));
); $q = "%".sanitize_input($login)."%";
function filter_word($value) {
if ($value == null) return true;
return ! in_array(strtolower($value),$filtered);
}
$req = "SELECT unique_id, first_name, last_name,nb_keywords FROM scholars WHERE ".$query." GROUP BY unique_id"; $query = 'concat(first_name, " ", IFNULL(middle_name,""), " ", last_name) LIKE "%'.$q.'%"';
#echo "req: ".$req.";";
$req = "SELECT doors_uid, email, first_name, last_name, keywords FROM comex_registrations WHERE ".$query." GROUP BY doors_uid";
// echo "req: ".$req.";";
$results = array(); $results = array();
$i = 0; $i = 0;
$res = $base->query($req); $res = $base->query($req);
foreach ($res as $row) {
if ($row["nb_keywords"]==0){
$row["nb_keywords"]=' (no keyword to map)';
} else {
$row["nb_keywords"]='';
}
array_push($results,$row);
}
$nbresults = sizeof($results);
$results = array_slice($results,0,20);
$nbresults2 = sizeof($results);
$completion = array( $completion = array(
"results" => array() "results" => array(),
"query" => $login
); );
foreach($res as $row) {
foreach($results as $row) {
array_push($completion["results"], array( array_push($completion["results"], array(
'id' => $row["unique_id"], 'id' => $row["doors_uid"],
'term' => $login, 'term' => $login,
'firstname' => $row["first_name"], 'firstname' => $row["first_name"],
'lastname' => $row["last_name"].$row["nb_keywords"], 'lastname' => $row["last_name"],
'score' => 1,
// F*** it, I'll put the meta data here...
'category' => $cat,
"size" => $nbresults2,
"total" => $nbresults,
"remaining" => ($nbresults - $nbresults2)
)); ));
} }
$i = 0; // ==================== /new retrieval =====================
// $base = new PDO("sqlite:" . $dbname);
//
// $category = trim(strtolower($_GET['category']));
// $login = trim(strtolower($_GET['login']));
// $q = "%".sanitize_input($login)."%";
//
// //echo "category: ".$category.";";
// //echo "login: ".$login.";";
// //echo "q: ".$q.";";
//
// $cat = '';
// $query = '';
// if ($category == 'login') {
// $cat = "unique_id";
// $query = 'unique_id LIKE upper(\''.strtoupper($q).'\')';
// } elseif ($category == 'firstname') {
// $cat = "firstname";
// $query = 'first_name LIKE upper(\''.strtoupper($q).'\')';
// } elseif ($category == 'lastname') {
// $cat = "lastname";
// $query = 'last_name LIKE upper(\''.strtoupper($q).'\')';
// } else {
// echo ("ERROR");
// exit();
// }
//
// $filtered = array (
// "yes", "1", "0", "nvgfpmeilym", "no", "mr", "ms", "", " ", " "
// );
// function filter_word($value) {
// if ($value == null) return true;
// return ! in_array(strtolower($value),$filtered);
// }
//
// $req = "SELECT unique_id, first_name, last_name,nb_keywords FROM scholars WHERE ".$query." GROUP BY unique_id";
// #echo "req: ".$req.";";
// $results = array();
// $i = 0;
// $res = $base->query($req);
//
// foreach ($res as $row) {
// if ($row["nb_keywords"]==0){
// $row["nb_keywords"]=' (no keyword to map)';
// } else {
// $row["nb_keywords"]='';
// }
// array_push($results,$row);
// }
//
// $nbresults = sizeof($results);
// $results = array_slice($results,0,20);
// $nbresults2 = sizeof($results);
// $completion = array(
// "results" => array()
// );
//
//
// foreach($results as $row) {
// array_push($completion["results"], array(
// 'id' => $row["unique_id"],
// 'term' => $login,
// 'firstname' => $row["first_name"],
// 'lastname' => $row["last_name"].$row["nb_keywords"],
// 'score' => 1,
//
// // TODO change: general metadata is uselessly copied x nbresults
// // F*** it, I'll put the meta data here...
// 'category' => $cat,
// "size" => $nbresults2,
// "total" => $nbresults,
// "remaining" => ($nbresults - $nbresults2)
// ));
// }
// $i = 0;
echo json_encode($completion); echo json_encode($completion);
?> ?>
\ No newline at end of file
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