[sword-svn] r168 - trunk/utils/flash2mongo


Mon Feb 7 10:08:05 MST 2011


Author: 
Date: 2011-02-07 10:08:05 -0700 (Mon, 07 Feb 2011)
New Revision: 168

Modified:
   trunk/utils/flash2mongo/flash2mongo.php
Log:
updated mongo import utility to include index creation

Modified: trunk/utils/flash2mongo/flash2mongo.php
===================================================================
--- trunk/utils/flash2mongo/flash2mongo.php	2011-02-06 05:00:43 UTC (rev 167)
+++ trunk/utils/flash2mongo/flash2mongo.php	2011-02-07 17:08:05 UTC (rev 168)
@@ -48,14 +48,28 @@
 
 $mongo 		= new Mongo($mongo_host);
 $db    		= $mongo->selectDB($mongo_db);
-$lessonsets = $db->selectCollection('lessonsets');
-$cards = $db->selectCollection('cards');
 
+$db->dropCollection('lessonsets');
+$db->dropCollection('lessons');
+$db->dropCollection('cards');
+
+$lessonsets_coll	= $db->selectCollection('lessonsets');
+$lessons_coll 		= $db->selectCollection('lessons');
+$cards_coll 		= $db->selectCollection('cards');
+
+$lessonsets_coll->ensureIndex(array("name"=>1));
+
+$lessons_coll->ensureIndex(array("name"=>1));
+
+$cards_coll->ensureIndex(array("lessonset"=>1, "lesson"=>1));
+$cards_coll->ensureIndex(array("front"=>1));
+$cards_coll->ensureIndex(array("back"=>1));
+
 while ($entryName = readdir($myDirectory)) {
     if (!preg_match('/^\./', $entryName) && is_dir($lessonDir . '/' . $entryName)) {
         $dirArray[] = $entryName;
 
-        $lessonsets->insert(array("lessonset"=>$entryName));
+        $lessonsets_coll->insert(array("name"=>$entryName));
     }
 }
 
@@ -94,14 +108,19 @@
             
             $lessonfont = array_key_exists('lessonFont', $lesson_data) ? $lesson_data['lessonFont'] : "GalSILB201";
             
+            $lessons_coll->insert(array(
+   					"lessonset"=>$lessonSetDir,
+            		"name"=>$lesson,
+					"font"=>$lessonfont
+            ));
+            
             $totwords += $cardCount;
             for ($i = 0; $i < $cardCount; $i++) {
                 $front = convertUnicode($lesson_data['word' . $i]);
                 $back = $lesson_data['answers' . $i];
-				$cards->insert(array(
+				$cards_coll->insert(array(
 					"lessonset"=>$lessonSetDir,
 					"lesson"=>$lesson,
-					"font"=>$lessonfont,
 					"front"=>$front,
 					"back"=>$back
 				));




More information about the sword-cvs mailing list