forked from looma/Looma-II
-
Notifications
You must be signed in to change notification settings - Fork 0
/
looma-dictionary-admin.php
executable file
·51 lines (46 loc) · 1.65 KB
/
looma-dictionary-admin.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
<!doctype html>
<!--
Name: Justin Cardozo
Email: [email protected]
Owner: VillageTech Solutions (villagetechsolutions.org)
Date: 2015 06
Revision: Looma 2.0.0
File: contentNavigator.php
Description: updates all dictionary entries with random value in "rand" field
-->
<?php
include ('includes/mongo-connect.php');
function keyIsSet($key, $array) { return isset($array[$key]);} //compatibility shiv for php 5.x "keyIsSet()"
?>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Random Generator</title>
</head>
<body>
<?php
echo "<h3>Adding random fields and ensuring indexing on randomization</h3>";
$count = 0;
$dictionary = mongoFind($dictionary_collection, [], null, null, null);
foreach ($dictionary as $d)
{
$count += 1;
$d_id = keyIsSet('_id', $d) ? $d['_id'] : null;
$random = (float)rand()/(float)getrandmax();
$newdata = array('$set' => array("rand" => $random));
mongoUpdate($dictionary_collection, array("_id" => $d_id), $newdata);
echo "<p>Dictionary entry: <b>" . $d['en'] .
"</b> [nepali: " . $d['np'] .
" assigned random index: " . $d['rand'] . "</p>";
}
echo "<h3>Processed $count dictionary entries</h3>";
/*
*
echo "<h3>Ensuring database index on RAND runs asynchronously - may not complete for a while after this page terminates</h3>";
$dictionary_collection->createIndex(array('rand' => 1)); //index DICTIONARY for random search
$dictionary_collection->createIndex(array('ch_id' => 1)); //index DICTIONARY for search on CH_ID
$dictionary_collection->createIndex(array('en' => 1)); //index DICTIONARY for search on EN (english word) "lookup"
*/
?>
</body>
</html>