Author: mj
Date: Fri Mar 30 14:46:33 2012
New Revision: 11329

Log:
Issue 2199.  Add QubitPdoActor for bulk indexing of actors. Implement I18ns in 
QubitPdoInformationObject. Extend and clean up PDO index in ES plugin.

Added:
   trunk/plugins/qtElasticSearchPlugin/lib/model/QubitPdoActor.class.php
Modified:
   
trunk/plugins/qtElasticSearchPlugin/lib/model/QubitPdoInformationObject.class.php
   trunk/plugins/qtElasticSearchPlugin/lib/qtElasticSearchPlugin.class.php

Added: trunk/plugins/qtElasticSearchPlugin/lib/model/QubitPdoActor.class.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/plugins/qtElasticSearchPlugin/lib/model/QubitPdoActor.class.php       
Fri Mar 30 14:46:33 2012        (r11329)
@@ -0,0 +1,181 @@
+<?php
+
+  /*
+  * This file is part of Qubit Toolkit.
+  *
+  * Qubit Toolkit is free software: you can redistribute it and/or modify
+  * it under the terms of the GNU Affero General Public License as published by
+  * the Free Software Foundation, either version 3 of the License, or
+  * (at your option) any later version.
+  *
+  * Qubit Toolkit is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  *
+  * You should have received a copy of the GNU General Public License
+  * along with Qubit Toolkit.  If not, see <http://www.gnu.org/licenses/>.
+  */
+
+  /**
+   * Lightweight version of QubitActor which uses PDO directly instead of the 
Propel ORM
+   *
+   * @package    qtElasticSearchPlugin
+   * @author     MJ Suhonos <[email protected]>
+   * @version    SVN: $Id: QubitPdoActor.class.php 11309 2012-03-29 20:46:14Z 
mj $
+   */
+
+  class QubitPdoActor
+  {
+    public
+//      $ancestors,
+      $i18ns;
+
+    protected
+      $data = array();
+
+    protected static
+      $conn,
+      $lookups,
+      $statements;
+
+    /**
+     * METHODS
+     */
+    public function __construct($id, $options = array())
+    {
+      if (isset($options['conn']))
+      {
+        self::$conn = $options['conn'];
+      }
+
+      if (!isset(self::$conn))
+      {
+        self::$conn = Propel::getConnection();
+      }
+
+      $this->loadData($id, $options);
+/*
+      // Get inherited ancestors
+      if (isset($options['ancestors']))
+      {
+        $this->ancestors = $options['ancestors'];
+      }
+
+      // Get inherited repository, unless a repository is set at current level
+      if (isset($options['repository']) && !$this->__isset('repository_id'))
+      {
+        $this->repository = $options['repository'];
+      }
+*/
+    }
+
+    public function __isset($name)
+    {
+      return isset($this->data[$name]);
+    }
+
+    public function __get($name)
+    {
+      if ('events' == $name && !isset($this->data[$name]))
+      {
+        $this->data[$name] = $this->getEvents();
+      }
+
+      if (isset($this->data[$name]))
+      {
+        return $this->data[$name];
+      }
+    }
+
+    public function __set($name, $value)
+    {
+      $this->data[$name] = $value;
+    }
+
+    protected function loadData($id)
+    {
+      if (!isset(self::$statements['actor']))
+      {
+        $sql = 'SELECT
+                  actor.*,
+                  slug.slug
+                FROM '.QubitActor::TABLE_NAME.' actor
+                JOIN '.QubitSlug::TABLE_NAME.' slug
+                  ON actor.id = slug.object_id
+                WHERE actor.id = :id';
+
+        self::$statements['actor'] = self::$conn->prepare($sql);
+      }
+
+      // Do select
+      self::$statements['actor']->execute(array(
+        ':id' => $id));
+
+      // Get first result
+      $this->data = self::$statements['actor']->fetch(PDO::FETCH_ASSOC);
+
+      if (false === $this->data)
+      {
+        throw new sfException("Couldn't find actor (id:'.$this->id.')");
+      }
+
+      self::$statements['actor']->closeCursor();
+
+      return $this;
+    }
+
+    /**
+     * Return an array of i18n arrays
+     *
+     * @return array of i18n arrays
+     */
+    public function getI18ns()
+    {
+      if (!isset($this->i18ns))
+      {
+        // Find i18ns
+        $sql = 'SELECT
+                  i18n.*
+              FROM '.QubitActorI18n::TABLE_NAME.' i18n
+              WHERE i18n.id = ?
+              ORDER BY i18n.culture';
+
+        $this->i18ns = QubitPdo::fetchAll($sql, array($this->id));
+      }
+
+      return $this->i18ns;
+    }
+
+    // Serialize yaself!  Don' disrespec yaself
+    public function serialize()
+    {
+      $serialized = array();
+
+      $serialized['slug'] = $this->slug;
+
+      // get all i18n-ized versions of this object
+      $this->getI18ns();
+      foreach ($this->i18ns as $objectI18n)
+      {
+        // index all values on the i18n-ized object
+        foreach (QubitMapping::getI18nFields('QubitActor') as $camelName)
+        {
+          $fieldName = sfInflector::underscore($camelName);
+
+          if (!is_null($objectI18n->$fieldName))
+          {
+            $doc[lcfirst($camelName)] = $objectI18n->$fieldName;
+          }
+        }
+        $doc['culture'] = $objectI18n->culture;
+        $i18ns[] = $doc;
+      }
+
+      $serialized['sourceCulture'] = $this->source_culture;
+      $serialized['i18n'] = $i18ns;
+
+      return $serialized;
+    }
+
+  }
\ No newline at end of file

Modified: 
trunk/plugins/qtElasticSearchPlugin/lib/model/QubitPdoInformationObject.class.php
==============================================================================
--- 
trunk/plugins/qtElasticSearchPlugin/lib/model/QubitPdoInformationObject.class.php
   Fri Mar 30 13:54:21 2012        (r11328)
+++ 
trunk/plugins/qtElasticSearchPlugin/lib/model/QubitPdoInformationObject.class.php
   Fri Mar 30 14:46:33 2012        (r11329)
@@ -28,72 +28,16 @@
 {
   public
     $ancestors,
-    $index,
-    $doc,
+    $i18ns,
     $repository;
 
   protected
-    $data = array(),
-    $languages,
-    $scripts;
+    $data = array();
 
   protected static
     $conn,
     $lookups,
-    $statements,
-    $fields = array(
-      'id',
-      'access_conditions',
-      'accruals',
-      'acquisition',
-      'creator_history',
-      'alternate_title',
-      'appraisal',
-      'archival_history',
-      'arrangement',
-      'creator',
-      'creator_serialized',
-      'date',
-      'date_serialized',
-      'edition',
-      'end_date',
-      'extent_and_medium',
-      'class_name',
-      'collection_root_slug',
-//      'culture',
-      'finding_aids',
-      'has_digital_object',
-      'identifier',
-      'language',
-      'level_of_description',
-      'level_of_description_id',
-      'location_of_copies',
-      'location_of_originals',
-      'material_type_id',
-      'media_type',
-      'media_type_id',
-      'notes',
-      'parent',
-      'part_of',
-      'physical_characteristics',
-      'physical_storage',
-      'place',
-      'publication_status_id',
-      'reference_code',
-      'related_units_of_description',
-      'repository',
-      'repository_id',
-      'repository_slug',
-      'reproduction_conditions',
-      'script',
-      'scope_and_content',
-      'slug',
-      'sources',
-      'start_date',
-      'subject',
-      'thumbnail_path',
-      'title'
-    );
+    $statements;
 
   /**
    * METHODS
@@ -154,14 +98,11 @@
     {
       $sql = 'SELECT
          io.*,
-         i18n.*,
          slug.slug,
          pubstat.status_id as publication_status_id,
          do.id as digital_object_id,
          do.media_type_id as media_type_id
        FROM '.QubitInformationObject::TABLE_NAME.' io
-       JOIN '.QubitInformationObjectI18n::TABLE_NAME.' i18n
-         ON io.id = i18n.id
        JOIN '.QubitSlug::TABLE_NAME.' slug
          ON io.id = slug.object_id
        JOIN '.QubitStatus::TABLE_NAME.' pubstat
@@ -169,15 +110,13 @@
        LEFT JOIN '.QubitDigitalObject::TABLE_NAME.' do
          ON io.id = do.information_object_id
        WHERE io.id = :id';
-//         AND i18n.culture = :culture';
 
       self::$statements['informationObject'] = self::$conn->prepare($sql);
     }
 
     // Do select
     self::$statements['informationObject']->execute(array(
-      ':id' => $id,
-));//      ':culture' => $culture));
+      ':id' => $id));
 
     // Get first result
     $this->data = 
self::$statements['informationObject']->fetch(PDO::FETCH_ASSOC);
@@ -193,6 +132,28 @@
   }
 
   /**
+   * Return an array of i18n arrays
+   *
+   * @return array of i18n arrays
+   */
+  public function getI18ns()
+  {
+    if (!isset($this->i18ns))
+    {
+      // Find i18ns
+      $sql = 'SELECT
+                  i18n.*
+              FROM '.QubitInformationObjectI18n::TABLE_NAME.' i18n
+              WHERE i18n.id = ?
+              ORDER BY i18n.culture';
+
+      $this->i18ns = QubitPdo::fetchAll($sql, array($this->id));
+    }
+
+    return $this->i18ns;
+  }
+
+  /**
    * Return an array of ancestors
    *
    * @return array of ancestors
@@ -219,6 +180,28 @@
     return $this->ancestors;
   }
 
+  public function getChildren()
+  {
+    if (!isset($this->children))
+    {
+      // Find ancestors
+      $sql  = 'SELECT
+                  node.id';
+      $sql .= ' FROM '.QubitInformationObject::TABLE_NAME.' node';
+      $sql .= ' WHERE node.parent_id = ?';
+      $sql .= ' ORDER BY lft';
+
+      $this->children = QubitPdo::fetchAll($sql, array(':id' => $this->id));
+    }
+
+    return $this->children;
+  }
+
+  public function hasChildren()
+  {
+    return !empty($this->children);
+  }
+
   /**
    * Return the closest repository
    *
@@ -261,6 +244,7 @@
     }
   }
 
+// TODO: FIX THESE METHODS
   protected function getFallbackTitle()
   {
     $sql  = 'SELECT i18n.title';
@@ -273,10 +257,6 @@
     return QubitPdo::fetchOne($sql, array($this->__get('id')));
   }
 
-  public function hasChildren()
-  {
-  }
-
   public function getCreators()
   {
     $creators = array();
@@ -351,7 +331,7 @@
       $refcode = '';
       if (isset($this->repository))
       {
-        if (null != $cc = $this->repository->getCountryCode(array('culture' => 
$this->__get('culture'))))
+        if (null != $cc = $this->repository->getCountryCode(array('culture' => 
$this->__get('source_culture'))))
         {
           $refcode .= $cc.' ';
         }
@@ -404,16 +384,12 @@
       $sql .= ' LEFT JOIN '.QubitSlug::TABLE_NAME.' act_slug
                   ON event.actor_id = act_slug.object_id';
       $sql .= ' WHERE event.information_object_id = ?';
-//                  AND i18n.culture = ?
-//                  AND (act_i18n.id IS NULL OR act_i18n.culture = ?)';
 
       self::$statements['event'] = self::$conn->prepare($sql);
     }
 
     self::$statements['event']->execute(array(
       $this->__get('id')));
-//      $this->__get('culture'),
-//      $this->__get('culture')));
 
     return self::$statements['event']->fetchAll(PDO::FETCH_OBJ);
   }
@@ -519,45 +495,26 @@
     if (!isset(self::$statements['actorRelation']))
     {
       $sql  = 'SELECT
-                  i18n.authorized_form_of_name as name';
+                  actor.id';
       $sql .= ' FROM '.QubitActor::TABLE_NAME.' actor';
-      $sql .= ' JOIN '.QubitActorI18n::TABLE_NAME.' i18n
-                  ON actor.id = i18n.id';
       $sql .= ' JOIN '.QubitRelation::TABLE_NAME.' relation
                   ON actor.id = relation.object_id';
-      $sql .= ' WHERE i18n.culture = :culture
-                  AND relation.subject_id = :resourceId
+      $sql .= ' WHERE relation.subject_id = :resourceId
                   AND relation.type_id = :typeId';
 
       self::$statements['actorRelation'] = self::$conn->prepare($sql);
     }
 
     self::$statements['actorRelation']->execute(array(
-      ':culture' => $this->__get('culture'),
       ':resourceId' => $this->__get('id'),
       ':typeId' => QubitTerm::NAME_ACCESS_POINT_ID));
 
     foreach (self::$statements['actorRelation']->fetchAll(PDO::FETCH_OBJ) as 
$item)
     {
-      if (!in_array($item->name, $names))
-      {
-        $names[] = $item->name;
-      }
-    }
-
-    // Get actors linked via the "event" table (e.g. creators)
-    foreach ($this->getActors() as $item)
-    {
-      if (!in_array($item->authorized_form_of_name, $names))
-      {
-        $names[] = $item->authorized_form_of_name;
-      }
+      $names[] = new QubitPdoActor($item->id);
     }
 
-    if (0 < count($names))
-    {
-      return implode(' ', $names);
-    }
+    return $names;
   }
 
   public function getSubjectAccessPoints()
@@ -577,15 +534,12 @@
     if (!isset(self::$statements['relatedTerms']))
     {
       $sql  = 'SELECT
-                  term.taxonomy_id,
-                  i18n.name';
+                  term.id,
+                  term.taxonomy_id';
       $sql .= ' FROM '.QubitObjectTermRelation::TABLE_NAME.' otr';
       $sql .= ' JOIN '.QubitTerm::TABLE_NAME.' term 
                   ON otr.term_id = term.id';
-      $sql .= ' JOIN '.QubitTermI18n::TABLE_NAME.' i18n
-                  ON term.id = i18n.id';
       $sql .= ' WHERE otr.object_id = ?
-                  AND i18n.culture = ?
                   AND term.taxonomy_id = ?';
 
       self::$statements['relatedTerms'] = self::$conn->prepare($sql);
@@ -593,19 +547,10 @@
 
     self::$statements['relatedTerms']->execute(array(
       $this->__get('id'),
-      $this->__get('culture'),
       $typeId
     ));
 
-    foreach (self::$statements['relatedTerms']->fetchAll(PDO::FETCH_OBJ) as 
$item)
-    {
-      $terms[] = $item->name;
-    }
-
-    if (0 < count($terms))
-    {
-      return implode(' ', $terms);
-    }
+    return self::$statements['relatedTerms']->fetchAll(PDO::FETCH_OBJ);
   }
 
   protected function getLanguagesAndScripts()
@@ -681,32 +626,19 @@
     if (!isset(self::$statements['note']))
     {
       $sql  = 'SELECT
-                  i18n.content';
+                  i18n.*';
       $sql .= ' FROM '.QubitNote::TABLE_NAME.' note';
       $sql .= ' JOIN '.QubitNoteI18n::TABLE_NAME.' i18n
                   ON note.id = i18n.id';
-      $sql .= ' WHERE note.object_id = ?
-                  AND i18n.culture = ?';
+      $sql .= ' WHERE note.object_id = ?';
 
       self::$statements['note'] = self::$conn->prepare($sql);
     }
 
     self::$statements['note']->execute(array(
-      $this->__get('id'),
-      $this->__get('culture')));
-
-    foreach (self::$statements['note']->fetchAll(PDO::FETCH_OBJ) as $item)
-    {
-      if (0 < strlen($item->content))
-      {
-        $notes[] = $item->content;
-      }
-    }
+      $this->__get('id')));
 
-    if (0 < count($notes))
-    {
-      return implode(' ', $notes);
-    }
+    return self::$statements['note']->fetchAll(PDO::FETCH_OBJ);
   }
 
   public function getThumbnailPath()
@@ -862,44 +794,47 @@
       // Subject access points (terms)
       foreach ($this->getSubjectAccessPoints() as $subject)
       {
-        $term = $subject->getTerm();
+        $term = QubitTerm::getById($subject->id);
 
         $subjectI18ns = $term->termI18ns->indexBy('culture');
         $serializedI18ns = QubitMapping::serializeI18ns(new QubitTerm(), 
$subjectI18ns);
-
+// FIXME: these IDs are wrong
         $serialized['subjects'][] = array('id' => $subject->id, 'i18n' => 
$serializedI18ns);
       }
 
       // Place access points (terms)
       foreach ($this->getPlaceAccessPoints() as $place)
       {
-        $term = $place->getTerm();
+        $term = QubitTerm::getById($place->id);
 
         $placeI18ns = $term->termI18ns->indexBy('culture');
         $serializedI18ns = QubitMapping::serializeI18ns(new QubitTerm(), 
$placeI18ns);
-
+// FIXME: these IDs are wrong
         $serialized['places'][] = array('id' => $place->id, 'i18n' => 
$serializedI18ns);
 
       }
 
       // Name access points (actors)
+      // FIXME use QubitPdoActor class
       foreach ($this->getNameAccessPoints() as $name)
       {
-        $nameI18ns = $name->object->actorI18ns->indexBy('culture');
-        $serializedI18ns = QubitMapping::serializeI18ns(new QubitActor(), 
$nameI18ns);
+        $nameSerialized = $name->serialize();
+        $nameSerialized['id'] = $name->id;
+        unset($nameSerialized['slug']);
+        unset($nameSerialized['sourceCulture']);
 
-        $serialized['names'][] = array('id' => $name->object->id, 'i18n' => 
$serializedI18ns);
+        $serialized['names'][] = $nameSerialized;
       }
 
       // Creators (actors)
+      // FIXME use QubitPdoActor class
       foreach ($this->getCreators() as $creator)
       {
-/*
-        $creatorI18ns = $creator->actorI18ns->indexBy('culture');
-        $serializedI18ns = QubitMapping::serializeI18ns(new QubitActor(), 
$creatorI18ns);
 
-        $serialized['creators'][] = array('id' => $creator->id, 'i18n' => 
$serializedI18ns);
-*/
+//        $creatorI18ns = $creator->actorI18ns->indexBy('culture');
+//        $serializedI18ns = QubitMapping::serializeI18ns(new QubitActor(), 
$creatorI18ns);
+//        $serialized['creators'][] = array('id' => $creator->id, 'i18n' => 
$serializedI18ns);
+
         // FIXME: obviously this doesn't handle I18n properly
         $serialized['creators'][] = array('id' => $creator['id'], 'i18n' => 
array(
                                     array('authorizedFormOfName' => 
$creator['name'],
@@ -909,33 +844,41 @@
       }
 
       // Notes
+      // FIXME: same as above
       foreach ($this->getNotes() as $note)
       {
+/*
         $noteI18ns = $note->noteI18ns->indexBy('culture');
         $serializedI18ns = QubitMapping::serializeI18ns(new QubitNote(), 
$noteI18ns);
-
         $serialized['notes'][] = array('id' => $note->id, 'i18n' => 
$serializedI18ns);
-      }
+*/
+        $serialized['notes'][] = array('id' => $note->id, 'i18n' => array(
+                                 array('content' => $note->content),
+                                 array('culture' => $note->culture)
+        ));
 
-      $serialized['sourceCulture'] = $this->source_culture;
+      }
 
-      foreach(QubitMapping::getI18nFields('QubitInformationObject') as 
$camelName)
+      // get all i18n-ized versions of this object
+      $this->getI18ns();
+      foreach ($this->i18ns as $objectI18n)
       {
-        $fieldName = sfInflector::underscore($camelName);
-
-        if (!empty($this->data[$fieldName]))
+        // index all values on the i18n-ized object
+        foreach (QubitMapping::getI18nFields('QubitInformationObject') as 
$camelName)
         {
-          $I18ns['culture'] = 'en'; // FIXME: OBVIOUSLY THIS IS A BAD HACK
-          $I18ns[lcfirst($camelName)] = $this->data[$fieldName];
+          $fieldName = sfInflector::underscore($camelName);
+
+          if (!is_null($objectI18n->$fieldName))
+          {
+            $doc[lcfirst($camelName)] = $objectI18n->$fieldName;
+          }
         }
+        $doc['culture'] = $objectI18n->culture;
+        $i18ns[] = $doc;
       }
 
-      $serialized['i18n'] = array($I18ns);
-//var_dump($serialized);
-//var_dump($this->data); exit;
-
-//      $thisI18ns = $this->informationObjectI18ns->indexBy('culture');
-//      $serialized['i18n'] = QubitMapping::serializeI18ns($this, $thisI18ns);
+      $serialized['sourceCulture'] = $this->source_culture;
+      $serialized['i18n'] = $i18ns;
 
       return $serialized;
     }

Modified: 
trunk/plugins/qtElasticSearchPlugin/lib/qtElasticSearchPlugin.class.php
==============================================================================
--- trunk/plugins/qtElasticSearchPlugin/lib/qtElasticSearchPlugin.class.php     
Fri Mar 30 13:54:21 2012        (r11328)
+++ trunk/plugins/qtElasticSearchPlugin/lib/qtElasticSearchPlugin.class.php     
Fri Mar 30 14:46:33 2012        (r11329)
@@ -76,11 +76,12 @@
     if ($this->batchMode && count($this->batchDocs) > 0)
     {
       $this->index->addDocuments($this->batchDocs);
+      $this->index->flush();
     }
 
     // I don't understand how the last card is played
     // But somehow the vital connection is made
-    $this->index->flush();
+    $this->index->refresh();
   }
 
   protected function initialize()
@@ -133,7 +134,7 @@
       if (count($this->batchDocs) >= $this->batchSize)
       {
         $this->index->addDocuments($this->batchDocs);
-        $this->index->refresh();
+        $this->index->flush();
 
         $this->batchDocs = array();
       }
@@ -141,7 +142,7 @@
     else
     {
       $this->index->getType($type)->addDocument($document);
-      $this->index->refresh();
+      $this->index->flush();
     }
   }
 
@@ -228,7 +229,7 @@
 
       if ($options['verbose'])
       {
-        $this->logger->log('"'.$term->__toString().'" inserted 
('.$this->timer->elapsed().'s) ('.($key+1).'/'.count($terms).')', 
'qtElasticSearch::QubitTerm');
+        $this->logger->log('QubitTerm "'.$term->__toString().'" inserted 
('.$this->timer->elapsed().'s) ('.($key+1).'/'.count($terms).')', 
'qtElasticSearch');
       }
     }
 
@@ -245,37 +246,21 @@
 
       if ($options['verbose'])
       {
-        $this->logger->log('"'.$repository->__toString().'" inserted 
('.$this->timer->elapsed().'s) ('.($key+1).'/'.count($repositories).')', 
'qtElasticSearch::QubitRepository');
+        $this->logger->log('QubitRepository "'.$repository->__toString().'" 
inserted ('.$this->timer->elapsed().'s) 
('.($key+1).'/'.count($repositories).')', 'qtElasticSearch');
       }
     }
 
     // information objects
     $total = $total + $this->populateInformationObjects($options);
 
-    // index actors
-    // FIXME: replicate IO PDO mechanism to index actors
-    $criteria = new Criteria;
-    $criteria->add(QubitActor::ID, QubitActor::ROOT_ID, Criteria::NOT_EQUAL);
-    $criteria = QubitActor::addGetOnlyActorsCriteria($criteria);
-
-    $actors = QubitActor::get($criteria);
-    $total = $total + count($actors);
-
-    foreach ($actors as $key => $actor)
-    {
-      $this->save($actor);
-
-      if ($options['verbose'])
-      {
-        $this->logger->log('"'.$actor->__toString().'" inserted 
('.$this->timer->elapsed().'s) ('.($key+1).'/'.count($actors).')', 
'qtElasticSearch::QubitActor');
-      }
-    }
+    // actors
+    $total = $total + $this->addActors($options);
 
     // if there are still documents in the batch queue, send them
     if ($this->batchMode && count($this->batchDocs) > 0)
     {
       $this->index->addDocuments($this->batchDocs);
-      $this->index->refresh();
+      $this->index->flush();
       $this->batchDocs = array();
     }
 
@@ -332,12 +317,8 @@
       $sql  = 'SELECT
                   io.id,
                   io.lft,
-                  io.rgt,
-                  i18n.culture,
-                  i18n.title';
+                  io.rgt';
       $sql .= ' FROM '.QubitInformationObject::TABLE_NAME.' io';
-      $sql .= ' JOIN '.QubitInformationObjectI18n::TABLE_NAME.' i18n
-                  ON io.id = i18n.id';
       $sql .= ' WHERE io.parent_id = ?';
       $sql .= ' ORDER BY io.lft';
 
@@ -356,13 +337,17 @@
       // full: 9266 IOs in 209s (44/s)
       $serialized = $object->serialize();
 /*
-      if 
($this->array_compare($this->serialize(QubitInformationObject::getById($item->id)),
 $serialized))
+      if ($comp = 
$this->array_compare($this->serialize(QubitInformationObject::getById($item->id)),
 $serialized))
       {
         // WARNING: PDO object is not serialized correctly
+        echo '=== QubitInformationObject #'.$item->id.': '."\n";
+        echo var_dump($comp[0]);
+        echo '=== QubitPdoInformationObject #'.$item->id.': '."\n";
+        echo var_dump($comp[1]);
       }
 */
       // 9266 IOs in 221s (42/s)
-      $document = new Elastica_Document($object->id, $serialized);
+      $document = new Elastica_Document($item->id, $serialized);
       $document->setType('QubitInformationObject');
 
       // add this document to the batch queue
@@ -372,7 +357,7 @@
       if (count($this->batchDocs) >= $this->batchSize)
       {
         $this->index->addDocuments($this->batchDocs);
-        $this->index->refresh();
+        $this->index->flush();
 
         $this->batchDocs = array();
       }
@@ -382,7 +367,7 @@
 
       if ($options['verbose'])
       {
-        $this->logger->log('"'.$item->title.'" inserted 
('.$this->timer->elapsed().'s) ('.self::$counter.'/'.$totalRows.')', 
'qtElasticSearch::QubitInformationObject');
+        $this->logger->log('QubitInformationObject "#'.$item->id.'" inserted 
('.$this->timer->elapsed().'s) ('.self::$counter.'/'.$totalRows.')', 
'qtElasticSearch');
       }
 
       // Descend hierarchy
@@ -397,6 +382,73 @@
     }
   }
 
+  public function addActors($options = array())
+  {
+    if (!isset(self::$conn))
+    {
+      self::$conn = Propel::getConnection();
+    }
+
+    $sql  = 'SELECT
+                  actor.id';
+    $sql .= ' FROM '.QubitActor::TABLE_NAME.' actor';
+    $sql .= ' JOIN '.QubitObject::TABLE_NAME.' object';
+    $sql .= ' ON actor.id = object.id';
+    $sql .= ' WHERE actor.id != ?';
+    $sql .= ' AND object.class_name = ?';
+    $sql .= ' ORDER BY actor.lft';
+
+    $actors = QubitPdo::fetchAll($sql, array(QubitActor::ROOT_ID, 
'QubitActor'));
+    $numRows = count($actors);
+
+    // Loop through results, and add to search index
+    foreach ($actors as $item)
+    {
+      // 12312 actors in 2.6s (4735 /s)
+      $object = new QubitPdoActor($item->id);
+
+      // 12312 actors in 16.4s (750 /s)
+      $serialized = $object->serialize();
+
+      // 12120 actors in 75.1s (161 /s)
+/*
+      if ($comp = 
$this->array_compare($this->serialize(QubitActor::getById($item->id)), 
$serialized))
+      {
+        // WARNING: PDO object is not serialized correctly
+        echo '=== QubitActor #'.$item->id.': '."\n";
+        echo var_dump($comp[0]);
+        echo '=== QubitPdoActor #'.$item->id.': '."\n";
+        echo var_dump($comp[1]);
+      }
+*/
+      // 12121 actors in 22.3s (543 /s)
+      $document = new Elastica_Document($item->id, $serialized);
+      $document->setType('QubitActor');
+
+      // add this document to the batch queue
+      $this->batchDocs[] = $document;
+
+      // if we have a full batch, send in bulk
+      if (count($this->batchDocs) >= $this->batchSize)
+      {
+        $this->index->addDocuments($this->batchDocs);
+        $this->index->flush();
+
+        $this->batchDocs = array();
+      }
+
+      // Log it
+      self::$counter++;
+
+      if ($options['verbose'])
+      {
+        $this->logger->log('QubitActor "#'.$item->id.'" inserted 
('.$this->timer->elapsed().'s) ('.self::$counter.'/'.$numRows.')', 
'qtElasticSearch');
+      }
+    }
+
+    return $numRows;
+  }
+
   public function array_compare($array1, $array2) {
     $diff = false;
     // Left-to-right

-- 
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/qubit-commits?hl=en.

Reply via email to