This repository has been archived by the owner on Feb 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_scholar.php
executable file
·86 lines (72 loc) · 2.03 KB
/
search_scholar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/*
* Génère le gexf des scholars à partir de la base sqlite
*/
include("parametres.php");
//include("../common/library/fonctions_php.php");
include("normalize.php");
$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,
// F*** it, I'll put the meta data here...
'category' => $cat,
"size" => $nbresults2,
"total" => $nbresults,
"remaining" => ($nbresults - $nbresults2)
));
}
$i = 0;
echo json_encode($completion);
?>