Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
clinicaltrials
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
david Chavalarias
clinicaltrials
Commits
2bc6b946
Commit
2bc6b946
authored
Feb 28, 2017
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
scholar directory sql query 2-in-1 (neighboors expansion and scholars info at once together)
parent
5f17088b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
106 additions
and
113 deletions
+106
-113
print_scholar_directory.php
print_scholar_directory.php
+106
-113
No files found.
print_scholar_directory.php
View file @
2bc6b946
...
...
@@ -68,58 +68,48 @@ $base = new PDO($dsn, $user, $pass, $opt);
// liste des chercheurs
$scholar
_array
=
array
();
$scholar
s
=
array
();
if
(
$userid
)
{
if
(
sizeof
(
$userid
)
>
0
)
{
// old way in two steps without a scholars <=> keywords table
// $sql1 = "SELECT keywords,last_name,first_name FROM scholars WHERE luid='" . $login . "'";
// $sql2 = "SELECT uid FROM sch_kw JOIN keywords ON sch_kw.kwid = keywords.kwid WHERE kwstr LIKE \"%" . trim($keyword)."%\"";
// new way in one query
$sql1
=
<<<
HERE_QUERY
SELECT
second_level
.
uid
FROM
sch_kw
LEFT
JOIN
sch_kw
AS
second_level
ON
sch_kw
.
kwid
=
second_level
.
kwid
WHERE
sch_kw
.
uid
=
{
$userid
}
--
(
uncomment
if
ego
not
self
-
neighboor
)
--
AND
second_level
.
uid
!=
sch_kw
.
uid
GROUP
BY
second_level
.
uid
ORDER
BY
second_level
.
uid
!=
{
$userid
}
;
--
allows
ego
to
be
first
HERE_QUERY
;
foreach
(
$base
->
query
(
$sql1
)
as
$row
)
{
if
(
array_key_exists
(
$row
[
'uid'
],
$scholar_array
)){
$scholar_array
[
$row
[
'uid'
]]
+=
1
;
}
else
{
$scholar_array
[
$row
[
'uid'
]]
=
1
;
}
}
}
}
// les scholars sont affichés par ordre de pertinence
arsort
(
$scholar_array
);
$scholar_id_array
=
array_keys
(
$scholar_array
);
// var_dump($scholar_id_array)."<br/>" ;
// liste des chercheurs "expansion transitive"
$scholars
=
array
();
//
foreach
(
$scholar_id_array
as
$scholar_id
){
// £TODO do it at once with previous SELECT !!
$sql
=
<<<
END_QUERY
SELECT
// query idea:
// ------------
// SELECT sch_kw.uid AS source,
// count(sch_kw.kwid) AS similarity,
// second_level.uid AS neighboor
// FROM sch_kw
// LEFT JOIN sch_kw AS second_level ON sch_kw.kwid = second_level.kwid
// WHERE sch_kw.uid = 4207
// GROUP BY second_level.uid
// ORDER BY count(sch_kw.kwid) DESC, second_level.uid != 4207 ASC;
// exemple:
// +--------+------------+-----------+
// | source | similarity | neighboor |
// +--------+------------+-----------+
// | 4207 | 2 | 4207 |
// | 4207 | 2 | 2792 |
// | 4207 | 1 | 2732 |
// | 4207 | 1 | 2569 |
// | 4207 | 1 | 3128 |
// | 4207 | 1 | 2636 |
// | 4207 | 1 | 3488 |
// | 4207 | 1 | 2727 |
// | 4207 | 1 | 3604 |
// | 4207 | 1 | 3942 |
// | (...) |
// +--------+------------+-----------+
// implementation with all details and infos to retrieve
$sql
=
<<<
HERE_QUERY
SELECT
scholars_and_affiliations
.*
,
COUNT
(
keywords
.
kwid
)
AS
keywords_nb
,
GROUP_CONCAT
(
keywords
.
kwid
)
AS
keywords_ids
,
GROUP_CONCAT
(
kwstr
)
AS
keywords_list
FROM
(
FROM
(
SELECT
scholars
.*
,
affiliations
.*
...
...
@@ -128,20 +118,22 @@ FROM (
ON
scholars
.
affiliation_id
=
affiliations
.
affid
WHERE
(
record_status
=
'active'
OR
(
record_status
=
'legacy'
AND
valid_date
>=
NOW
()))
)
AS
scholars_and_affiliations
)
AS
scholars_and_affiliations
LEFT
JOIN
sch_kw
ON
sch_kw
.
uid
=
scholars_and_affiliations
.
luid
LEFT
JOIN
keywords
LEFT
JOIN
sch_kw
AS
second_level
ON
second_level
.
uid
=
scholars_and_affiliations
.
luid
JOIN
sch_kw
ON
sch_kw
.
kwid
=
second_level
.
kwid
JOIN
keywords
ON
sch_kw
.
kwid
=
keywords
.
kwid
GROUP
BY
luid
END_QUERY
;
WHERE
sch_kw
.
uid
=
{
$userid
}
GROUP
BY
luid
ORDER
BY
count
(
sch_kw
.
kwid
)
DESC
,
second_level
.
uid
!=
{
$userid
}
ASC
;
// echo var_dump($scholar_id)."<br/>"
;
//$query = "SELECT * FROM scholars";
foreach
(
$base
->
query
(
$sql
)
as
$row
)
{
HERE_QUERY
;
foreach
(
$base
->
query
(
$sql
)
as
$row
)
{
$info
=
array
();
$info
[
'unique_id'
]
=
$row
[
'luid'
];
$info
[
'doors_uid'
]
=
$row
[
'doors_uid'
];
...
...
@@ -186,9 +178,10 @@ foreach ($base->query($sql) as $row) {
// $info['fax'] = $row['fax'];
// $info['affiliation_acronym'] = $row['affiliation_acronym'];
$scholars
[
$row
[
'luid'
]]
=
$info
;
}
}
}
/// stats
include
(
"php_library/stat-prep_from_array.php"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment