Author: mj
Date: Thu Feb 16 11:19:22 2012
New Revision: 10918

Log:
Snapshot commit against issue 2199 for branch to 2.x.  Faceting and i18n 
indexing (in progress).

Added:
   trunk/plugins/qtElasticSearchPlugin/lib/QubitMapping.class.php
Modified:
   trunk/plugins/qtElasticSearchPlugin/lib/model/QubitActorMapping.class.php
   
trunk/plugins/qtElasticSearchPlugin/lib/model/QubitInformationObjectMapping.class.php
   trunk/plugins/qtElasticSearchPlugin/lib/qtElasticSearchPlugin.class.php
   trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Facet/Abstract.php
   
trunk/plugins/qtElasticSearchPlugin/modules/search/actions/indexAction.class.php
   
trunk/plugins/qtElasticSearchPlugin/modules/search/templates/_searchResults.php

Added: trunk/plugins/qtElasticSearchPlugin/lib/QubitMapping.class.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/plugins/qtElasticSearchPlugin/lib/QubitMapping.class.php      Thu Feb 
16 11:19:22 2012        (r10918)
@@ -0,0 +1,50 @@
+<?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/>.
+  */
+
+  /**
+   * Parent class to provide global model mapping methods for storing objects
+   * within an ElasticSearch document index.
+   *
+   * @package    qtElasticSearchPlugin
+   * @author     MJ Suhonos <[email protected]>
+   * @version    svn:$Id: QubitMapping.class.php 10316 2011-11-14 22:40:18Z mj 
$
+   */
+
+  class QubitMapping
+  {
+    public static function getI18nFields($class)
+    {
+      // use reflection on i18n object to get property list from class 
constants
+      if (class_exists($class . 'I18n'))
+      {
+        $reflect = new ReflectionClass($class . 'I18n');
+        $i18nFields = $reflect->getConstants();
+
+        // these constants cannot be accessed by __get()
+        unset($i18nFields['DATABASE_NAME']);
+        unset($i18nFields['TABLE_NAME']);
+
+        // id and culture are not used for indexing
+        unset($i18nFields['ID']);
+        unset($i18nFields['CULTURE']);
+
+        return array_map(array('sfInflector', 'camelize'), 
array_map('strtolower', array_keys($i18nFields)));
+      }
+    }
+
+  }

Modified: 
trunk/plugins/qtElasticSearchPlugin/lib/model/QubitActorMapping.class.php
==============================================================================
--- trunk/plugins/qtElasticSearchPlugin/lib/model/QubitActorMapping.class.php   
Thu Feb 16 11:04:24 2012        (r10917)
+++ trunk/plugins/qtElasticSearchPlugin/lib/model/QubitActorMapping.class.php   
Thu Feb 16 11:19:22 2012        (r10918)
@@ -25,12 +25,14 @@
    * @version    svn:$Id: QubitActorMapping.class.php 10316 2011-11-14 
22:40:18Z mj $
    */
 
-  class QubitActorMapping
+  class QubitActorMapping extends QubitMapping
   {
     static function getProperties()
     {
       // TODO ...
-      return array();
+      return array('slug' => array('type' => 'string'),
+                   'i18n' => array('type' => 'nested')
+      );
     }
 
     static function serialize($object)
@@ -38,7 +40,7 @@
       $serialized = array();
 
       $objectI18ns = $object->actorI18ns->indexBy('culture');
-
+/*
       // Add other forms of name
       $criteria = new Criteria;
       $criteria->addJoin(QubitOtherNameI18n::ID, QubitOtherName::ID);
@@ -50,7 +52,7 @@
       {
         $serialized[$otherName->culture]['otherNames'][] = $otherName->name;
       }
-
+*/
       // get all i18n-ized versions of this object
       foreach ($objectI18ns as $culture => $objectI18n)
       {
@@ -60,31 +62,18 @@
           $value = call_user_func(array($objectI18n, 'get' . $method));
           if (!is_null($value))
           {
-            $serialized[$culture][lcfirst($method)] = $value;
+            $i18ns[$culture][lcfirst($method)] = $value;
           }
         }
       }
 
-      return $serialized;
-    }
-
-    public static function getI18nFields($class)
-    {
-      // use reflection on i18n object to get property list from class 
constants
-      if (class_exists($class . 'I18n'))
+      foreach ($i18ns as $culture => $doc)
       {
-        $reflect = new ReflectionClass($class . 'I18n');
-        $i18nFields = $reflect->getConstants();
-
-        // these constants cannot be accessed by __get()
-        unset($i18nFields['DATABASE_NAME']);
-        unset($i18nFields['TABLE_NAME']);
-
-        // id and culture are not used for indexing
-        unset($i18nFields['ID']);
-        unset($i18nFields['CULTURE']);
-
-        return array_map(array('sfInflector', 'camelize'), 
array_map('strtolower', array_keys($i18nFields)));
+        $doc['culture'] = $culture;
+        $serialized['i18n'][] = $doc;
       }
+
+      return $serialized;
     }
+
   }
\ No newline at end of file

Modified: 
trunk/plugins/qtElasticSearchPlugin/lib/model/QubitInformationObjectMapping.class.php
==============================================================================
--- 
trunk/plugins/qtElasticSearchPlugin/lib/model/QubitInformationObjectMapping.class.php
       Thu Feb 16 11:04:24 2012        (r10917)
+++ 
trunk/plugins/qtElasticSearchPlugin/lib/model/QubitInformationObjectMapping.class.php
       Thu Feb 16 11:19:22 2012        (r10918)
@@ -25,12 +25,54 @@
    * @version    svn:$Id: QubitInformationObjectMapping.class.php 10316 
2011-11-14 22:40:18Z mj $
    */
 
-  class QubitInformationObjectMapping
+  class QubitInformationObjectMapping extends QubitMapping
   {
     static function getProperties()
     {
-      // TODO ...
-      return array();
+      return array('slug' => array('type' => 'string', 'index' => 'no'),
+                   'referenceCode' => array('type' => 'string', 'index' => 
'not_analyzed'),
+                   'identifier' => array('type' => 'string', 'index' => 
'not_analyzed'),
+                   'sourceCulture' => array('type' => 'string', 'index' => 
'not_analyzed', 'include_in_all' => false),
+
+                   // SEE BELOW
+                   'levelOfDescription' => array('type' => 'object', 
'properties' =>
+                     array('id' => array('type' => 'integer', 'index' => 
'not_analyzed', 'include_in_all' => false),
+                           'slug' => array('type' => 'string', 'index' => 
'no'),
+                     )
+                   ),
+                   'repository' => array('type' => 'object', 'properties' =>
+                     array('id' => array('type' => 'integer', 'index' => 
'not_analyzed', 'include_in_all' => false),
+/*
+                           'i18n' => array('type' => 'object', 'properties' =>
+                           array('name' => array('type' => 'multi_field', 
'fields' =>
+                             array('name' => array('type' => 'string'),
+                                   'stored' => array('type' => 'string', 
'index' => 'not_analyzed')
+                             )
+                           )
+                         )
+                       )
+*/
+                     )
+                   ),
+
+                    // i18n fields
+                   'i18n' => array('type' => 'nested', 'include_in_root' => 
true, 'properties' => array(
+                     'culture' => array('type' => 'string', 'index' => 
'not_analyzed', 'include_in_all' => false),
+
+                     'creator' => array('type' => 'object', 'properties' => 
array(
+                       'name' => array('type' => 'string'),
+                       'history' => array('type' => 'string')
+                       ),
+                     ),
+
+                     'names' => array('type' => 'object', 'properties' => 
array(
+                       'name' => array('type' => 'string') // override 
collision with i18n.creator.name
+                       )
+                     ),
+
+                     )
+                   ),
+      );
     }
 
     static function serialize($object)
@@ -39,36 +81,54 @@
 
       $objectI18ns = $object->informationObjectI18ns->indexBy('culture');
 
-      // indexed?
       $serialized['slug'] = $object->slug;
       $serialized['referenceCode'] = $object->referenceCode;
       $serialized['identifier'] = $object->identifier;
+      $serialized['sourceCulture'] = $object->sourceCulture;
+/*
+      $serialized['parent']['id'] = $object->parentId;
+      $serialized['parent']['slug'] = $object->parent->slug;
 
       // used for filtering
       $serialized['publicationStatusId'] = 
$object->getPublicationStatus()->status->id;
 
-      // linking information; NOT indexed
-//        $serialized['parent']['id'] = $object->parentId;
-//        $serialized['parent']['slug'] = $object->parent->slug;
-
       // use for linking "part of" in results; NOT indexed
       $root = $object->getCollectionRoot();
       $serialized['collectionRoot']['id'] = $root->id;
       $serialized['collectionRoot']['slug'] = $root->slug;
       $serialized['collectionRoot']['title'] = $root->title;
+*/
+
+      $serialized['levelOfDescription']['id'] = $object->levelOfDescriptionId;
+
+      // TODO: not sure if this is required
+/*
+      $lod = $object->getLevelOfDescription();
+      $lodI18ns = $lod->termI18ns->indexBy('culture');
+      foreach ($lodI18ns as $culture => $lodI18n)
+      {
+        $serialized['levelOfDescription']['i18n'][] = array('culture' => 
$culture, 'name' => $lod->getName(array('culture' => $culture)));
+      }
+*/
 
-      // repository information for linking and filtering; indexed
-      if ($repository = $object->getRepository(array('inherit' => true)))
+      // NB: repository ID is usually only stored on the collection root object
+      if ($repository = $object->getRepository(array('inherit' => 
empty($object->repositoryId))))
       {
         $serialized['repository']['id'] = $repository->id;
         $serialized['repository']['slug'] = $repository->slug;
 
-        foreach ($objectI18ns as $culture => $objectI18n)
+        // TODO: not sure if this is required
+/*
+        $repositoryI18ns = $repository->actorI18ns->indexBy('culture');
+        foreach ($repositoryI18ns as $culture => $objectI18n)
         {
-          $serialized['repository'][$culture]['name'] = 
$repository->getAuthorizedFormOfName();
+          $serialized['repository']['i18n'][] = array('culture' => $culture, 
'name' => $repository->getAuthorizedFormOfName(array('culture' => $culture)));
+//          $i18ns[$culture]['repositoryName'] = 
$repository->getAuthorizedFormOfName();
         }
+*/
       }
 
+/*
       // embed digital object information; indexed?
       if ($digitalObject = $object->getDigitalObject())
       {
@@ -95,37 +155,34 @@
         }
         $serialized['dates'][] = $save_date;
       }
-
+*/
       foreach ($objectI18ns as $culture => $objectI18n)
       {
-        $serialized[$culture]['creator'] = 
$object->getCreatorsNameString(array('culture' => $culture));
-        $serialized[$culture]['creatorHistory'] = 
$object->getCreatorsHistoryString(array('culture' => $culture));
-
-        if ($level = $object->getLevelOfDescription())
-        {
-          $serialized[$culture]['levelOfDescription'] = 
$level->getName(array('culture' => $culture));
-        }
+        // FIXME: this is inefficient, use foreach getCreators()
+        $i18ns[$culture]['creator'][] = array('name' => 
$object->getCreatorsNameString(array('culture' => $culture)),
+                                              'history' => 
$object->getCreatorsHistoryString(array('culture' => $culture)));
 
         foreach ($object->getNotes() as $note)
         {
-          $serialized[$culture]['notes'][] = $note->getContent(array('culture' 
=> $culture));
+          $i18ns[$culture]['notes'][] = $note->getContent(array('culture' => 
$culture));
         }
 
         foreach ($object->getNameAccessPoints() as $name)
         {
-          $serialized[$culture]['names'][] = 
$name->object->getAuthorizedFormOfName(array('culture' => $culture));
+          $i18ns[$culture]['names'][] = array('name' => 
$name->object->getAuthorizedFormOfName(array('culture' => $culture)),
+                                              'id' => $name->object->id);
         }
 
         foreach ($object->getSubjectAccessPoints() as $subject)
         {
           $term = $subject->getTerm();
-          $serialized[$culture]['subjects'][] = $term->getName(array('culture' 
=> $culture));
+          $i18ns[$culture]['subjects'][] = $term->getName(array('culture' => 
$culture));
 
           if ($term->otherNames)
           {
             foreach ($term->otherNames as $otherName)
             {
-              $serialized[$culture]['subjects'][] = 
$otherName->getName(array('culture' => $culture));
+              $i18ns[$culture]['subjects'][] = 
$otherName->getName(array('culture' => $culture));
             }
           }
         }
@@ -133,13 +190,13 @@
         foreach ($object->getPlaceAccessPoints() as $place)
         {
           $term = $place->getTerm();
-          $serialized[$culture]['places'][] = $term->getName(array('culture' 
=> $culture));
+          $i18ns[$culture]['places'][] = $term->getName(array('culture' => 
$culture));
 
           if ($term->otherNames)
           {
             foreach ($term->otherNames as $otherName)
             {
-              $serialized[$culture]['places'][] = 
$otherName->getName(array('culture' => $culture));
+              $i18ns[$culture]['places'][] = 
$otherName->getName(array('culture' => $culture));
             }
           }
         }
@@ -155,31 +212,18 @@
           $value = call_user_func(array($objectI18n, 'get' . $method));
           if (!is_null($value))
           {
-            $serialized[$culture][lcfirst($method)] = $value;
+            $i18ns[$culture][lcfirst($method)] = $value;
           }
         }
       }
 
-      return $serialized;
-    }
-
-    public static function getI18nFields($class)
-    {
-      // use reflection on i18n object to get property list from class 
constants
-      if (class_exists($class . 'I18n'))
+      foreach ($i18ns as $culture => $doc)
       {
-        $reflect = new ReflectionClass($class . 'I18n');
-        $i18nFields = $reflect->getConstants();
-
-        // these constants cannot be accessed by __get()
-        unset($i18nFields['DATABASE_NAME']);
-        unset($i18nFields['TABLE_NAME']);
-
-        // id and culture are not used for indexing
-        unset($i18nFields['ID']);
-        unset($i18nFields['CULTURE']);
-
-        return array_map(array('sfInflector', 'camelize'), 
array_map('strtolower', array_keys($i18nFields)));
+        $doc['culture'] = $culture;
+        $serialized['i18n'][] = $doc;
       }
+
+      return $serialized;
     }
-  }
+
+  }
\ No newline at end of file

Modified: 
trunk/plugins/qtElasticSearchPlugin/lib/qtElasticSearchPlugin.class.php
==============================================================================
--- trunk/plugins/qtElasticSearchPlugin/lib/qtElasticSearchPlugin.class.php     
Thu Feb 16 11:04:24 2012        (r10917)
+++ trunk/plugins/qtElasticSearchPlugin/lib/qtElasticSearchPlugin.class.php     
Thu Feb 16 11:19:22 2012        (r10918)
@@ -92,21 +92,19 @@
       if ($e instanceof Elastica_Exception_Response) {
         $this->index->create(array(), true);
       }
-    }
 
-/*
-    // apply type mappings for each indexed object type
-    // TODO: can load these dynamically from the ./model directory
-    foreach (array('QubitInformationObject', 'QubitActor') as $type)
-    {
-      $mapping = new Elastica_Type_Mapping();
+      // apply type mappings for each indexed object type
+      // TODO: can load these dynamically from the ./model directory
+      foreach (array('QubitInformationObject', 'QubitActor') as $type)
+      {
+        $mapping = new Elastica_Type_Mapping();
 
-      $mapping->setType($this->index->getType($type));
-      $mapping->setProperties(call_user_func(array($type . 'Mapping', 
'getProperties')));
+        $mapping->setType($this->index->getType($type));
+        $mapping->setProperties(call_user_func(array($type . 'Mapping', 
'getProperties')));
 
-      $mapping->send();
+        $mapping->send();
+      }
     }
-*/
   }
 
   /*
@@ -114,9 +112,13 @@
    */
   public function save($object)
   {
-    // NB: serializing from the ORM is the most expensive part
     $type = get_class($object);
 
+    if (!class_exists($type . 'Mapping'))
+    {
+      return;
+    }
+
     $document = new Elastica_Document($object->id, $this->serialize($object));
     $document->setType($type);
 
@@ -150,7 +152,7 @@
   {
     if (empty($querystring))
     {
-      throw new Exception('No search terms specified.');
+      throw new Exception(sfContext::getInstance()->i18n->__('No search terms 
specified.'));
     }
 
     $query = new Elastica_Query_QueryString($querystring);
@@ -290,10 +292,10 @@
     if (class_exists(get_class($object) . 'Mapping'))
     {
       $serialized = call_user_func_array(array(get_class($object) . 'Mapping', 
'serialize'), array($object));
-    }
 
-    // TODO: trim empty/null/blank elements in the array
-    return $serialized;
+      // TODO: trim empty/null/blank elements in the array
+      return $serialized;
+    }
   }
 
 }
\ No newline at end of file

Modified: 
trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Facet/Abstract.php
==============================================================================
--- trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Facet/Abstract.php  
Thu Feb 16 11:04:24 2012        (r10917)
+++ trunk/plugins/qtElasticSearchPlugin/lib/vendor/Elastica/Facet/Abstract.php  
Thu Feb 16 11:19:22 2012        (r10918)
@@ -96,7 +96,7 @@
         * @param mixed $value The value of the param.
         * @return Elastica_Facet_Abstract
         */
-       protected function _setFacetParam($key, $value) {
+       public function _setFacetParam($key, $value) {
                $this->_facet[$key] = $value;
                return $this;
        }

Modified: 
trunk/plugins/qtElasticSearchPlugin/modules/search/actions/indexAction.class.php
==============================================================================
--- 
trunk/plugins/qtElasticSearchPlugin/modules/search/actions/indexAction.class.php
    Thu Feb 16 11:04:24 2012        (r10917)
+++ 
trunk/plugins/qtElasticSearchPlugin/modules/search/actions/indexAction.class.php
    Thu Feb 16 11:19:22 2012        (r10918)
@@ -40,15 +40,38 @@
       $this->response->setTitle("{$this->title} - 
{$this->response->getTitle()}");
     }
 
-    $query = $this->parseQuery();
+    $queryParsed = $this->parseQuery(); // Elastica_Query_QueryString
 
     if (!empty($this->error))
     {
       return;
     }
+/*
+    // =============================================
+    // fielded query limited to i18n sub-documents
+    //
+    // eg. "title:titre AND culture:fr"
+    // $queryParsed->setFields(array('i18n.*'));
+
+    $queryNested = new Elastica_Query_Nested();
+    $queryNested->setQuery($queryParsed);
+    $queryNested->setPath('i18n');
+
+    $query = new Elastica_Query($queryNested);
+    // =============================================
+*/
+    $query = new Elastica_Query($queryParsed);
 
-    $query = $this->filterQuery($query);
     $query = $this->facetQuery($query);
+    $query = $this->filterQuery($query);
+
+    // set paging for request
+    $query->setLimit($this->request->limit);
+
+    if (!empty($this->request->page))
+    {
+      $query->setFrom(($this->request->page - 1) * $this->request->limit);
+    }
 
     try
     {
@@ -77,6 +100,102 @@
 
       $this->pager->resultSet = $resultSet;
       $this->pager->page = $request->page ? $request->page : 1;
+
+      if ($resultSet->hasFacets())
+      {
+        // do some field-specific value mapping on facets
+        foreach ($resultSet->getFacets() as $name => $facet)
+        {
+          switch ($name)
+          {
+            case 'Language':
+              foreach ($facet['terms'] as $term)
+              {
+                $facets[$name]['terms'][$term['term']] = array('count' => 
$term['count'],
+                                                  'term' => 
sfCultureInfo::getInstance($this->context->user->getCulture())->getLanguage($term['term']));
+              }
+              $facets[$name]['field'] = 'i18n.culture';
+              break;
+
+            case 'Repository':
+              foreach ($facet['terms'] as $term)
+              {
+                $ids[$term['term']] = $term['count'];
+              }
+
+              $criteria = new Criteria;
+              $criteria->add(QubitRepository::ID, array_keys($ids), 
Criteria::IN);
+              unset($ids);
+
+              $repos = QubitRepository::get($criteria);
+
+              foreach ($repos as $repo)
+              {
+                $reponames[$repo->id] = 
$repo->getAuthorizedFormOfName(array('cultureFallback' => true, 'culture' => 
$this->context->user->getCulture()));
+              }
+
+              foreach ($facet['terms'] as $term)
+              {
+                $facets[$name]['terms'][$term['term']] = array('count' => 
$term['count'],
+                                                  'term' => 
$reponames[$term['term']]);
+              }
+              $facets[$name]['field'] = 'repository.id';
+              break;
+
+            case 'Level of Description':
+              foreach ($facet['terms'] as $term)
+              {
+                $ids[$term['term']] = $term['count'];
+              }
+
+              $criteria = new Criteria;
+              $criteria->add(QubitTerm::ID, array_keys($ids), Criteria::IN);
+              unset($ids);
+
+              $lods = QubitTerm::get($criteria);
+
+              foreach ($lods as $lod)
+              {
+                $lodnames[$lod->id] = $lod->getName(array('cultureFallback' => 
true, 'culture' => $this->context->user->getCulture()));
+              }
+
+              foreach ($facet['terms'] as &$term)
+              {
+                $facets[$name]['terms'][$term['term']] = array('count' => 
$term['count'],
+                                                  'term' => 
$lodnames[$term['term']]);
+              }
+              $facets[$name]['field'] = 'levelOfDescription.id';
+              break;
+
+            case 'Names':
+              foreach ($facet['terms'] as $term)
+              {
+                $ids[$term['term']] = $term['count'];
+              }
+
+              $criteria = new Criteria;
+              $criteria->add(QubitActor::ID, array_keys($ids), Criteria::IN);
+              unset($ids);
+
+              $nameAPs = QubitActor::get($criteria);
+
+              foreach ($nameAPs as $nameAP)
+              {
+                $nameAPnames[$nameAP->id] = 
$nameAP->getAuthorizedFormOfName(array('cultureFallback' => true, 'culture' => 
$this->context->user->getCulture()));
+              }
+
+              foreach ($facet['terms'] as &$term)
+              {
+                $facets[$name]['terms'][$term['term']] = array('count' => 
$term['count'],
+                                                  'term' => 
$nameAPnames[$term['term']]);
+              }
+              $facets[$name]['field'] = 'i18n.names.id';
+              break;
+          }
+        }
+
+        $this->pager->facets = $facets;
+      }
     }
     else if (empty($this->error))
     {
@@ -99,14 +218,27 @@
       return null;
     }
 
-    $query = new Elastica_Query($queryParsed);
-
-    // set paging for request
-    $query->setLimit($this->request->limit);
+    return $queryParsed;
+  }
 
-    if (!empty($this->request->page))
-    {
-      $query->setFrom(($this->request->page - 1) * $this->request->limit);
+  public function facetQuery($query)
+  {
+    $facet = new Elastica_Facet_Terms('Repository');
+    $facet->setField('repository.id');
+    $query->addFacet($facet);
+
+    $facet = new Elastica_Facet_Terms('Level of Description');
+    $facet->setField('levelOfDescription.id');
+    $query->addFacet($facet);
+
+    $i18n_facets = array('Language' => 'i18n.culture', 'Names' => 
'i18n.names.id');
+
+    foreach ($i18n_facets as $name => $field)
+    {
+      $facet = new Elastica_Facet_Terms($name);
+      $facet->_setFacetParam('nested', 'i18n');     // NB: requires Elastica 
patch
+      $facet->setField($field);
+      $query->addFacet($facet);
     }
 
     return $query;
@@ -135,16 +267,4 @@
 */
     return $query;
   }
-
-  public function facetQuery($query)
-  {
-/*
-    // TODO: add facets
-    $facet = new Elastica_Facet_Terms('en.title');
-    $facet->setField('en.title');
-    $facet->setSize(10);
-    //    $query->addFacet($facet);
-*/
-    return $query;
-  }
 }

Modified: 
trunk/plugins/qtElasticSearchPlugin/modules/search/templates/_searchResults.php
==============================================================================
--- 
trunk/plugins/qtElasticSearchPlugin/modules/search/templates/_searchResults.php 
    Thu Feb 16 11:04:24 2012        (r10917)
+++ 
trunk/plugins/qtElasticSearchPlugin/modules/search/templates/_searchResults.php 
    Thu Feb 16 11:19:22 2012        (r10918)
@@ -1,3 +1,13 @@
+<?php foreach($pager->facets as $name => $facet): ?>
+  <h2 style="font-size: 1.5em; margin-bottom: 0.5em;"><?php echo __($name); 
?></h2>
+    <?php foreach($facet['terms'] as $id => $term): ?>
+      <b><?php echo __($term['term']); ?>
+        [<a href=""><?php echo $facet['field'] .':'. $id; ?></a>]
+        (<?php echo $term['count']; ?>)</b><br/>
+    <?php endforeach; ?><br/>
+<?php endforeach; ?>
+<hr/>
+
 <div id="search-stats">
   <?php if (0 < $pager->resultSet->getTotalHits()): ?>
     <?php echo __('Showing results %1% to %2% of %3% (%4% seconds)', array(
@@ -18,63 +28,31 @@
 <div class="section">
   <?php foreach ($pager->resultSet->getResults() as $hit): ?>
     <?php $doc = $hit->getData(); ?>
+    <?php
+      foreach ($doc['i18n'] as $i18n)
+      {
+        $doc[$i18n['culture']] = $i18n;
+      }
+      unset($doc['i18n']);// continue;
+    ?>
 
     <div class="clearfix search-results <?php echo 0 == @++$row % 2 ? 'even' : 
'odd' ?>">
 
-      <?php if (isset($doc['digitalObject'])):/* ?>
-        <?php if ($doc['digitalObject']['mediaTypeId']): ?>
-          <?php echo 
link_to(image_tag(QubitDigitalObject::getGenericRepresentation($doc['digitalObject']['mediaTypeId'],
 QubitTerm::THUMBNAIL_ID)->getFullPath(), array('alt' => $doc['title'])), 
array('slug' => $doc['slug'], 'module' => 'informationobject')) ?>
-        <?php elseif (QubitTerm::AUDIO_ID == 
$doc['digitalObject']['mediaTypeId']): ?>
-          <?php echo link_to(image_tag('play.png', array('alt' => 
$doc['title'])), array('slug' => $doc['slug'], 'module' => 
'informationobject')) ?>
-        <?php elseif (null !== $doc['digitalObject']['thumbnail_FullPath']): ?>
-          <?php echo 
link_to(image_tag(public_path($doc['digitalObject']['thumbnail_FullPath']), 
array('alt' => $doc['title'])), array('slug' => $doc['slug'], 'module' => 
'informationobject')) ?>
-        <?php endif;?>
-      <?php */ endif; ?>
-
-      <h2><?php echo link_to($doc['en']['title'], array('slug' => 
$doc['slug'], 'module' => 'informationobject')) ?><?php if 
(QubitTerm::PUBLICATION_STATUS_DRAFT_ID == $doc['publicationStatusId']): ?> 
<span class="publicationStatus">draft</span><?php endif; ?></h2>
-
-      <?php if ($doc['en']['scopeAndContent']): ?>
-        <div class="field">
-          <?php echo 
highlight_text(truncate_text($doc['en']['scopeAndContent'], 256), 
$sf_request->query) ?>
-        </div>
-      <?php endif; ?>
-
-      <?php if ($doc['referenceCode']): ?>
-        <?php echo render_show(__('Reference code'), 
render_value($doc['referenceCode'])); ?>
-      <?php endif; ?>
-
-      <?php if (isset($doc['dates'])): ?>
-        <div class="field">
-          <h3><?php echo __('Date(s)') ?></h3>
-          <div>
-            <ul>
-              <?php foreach ($doc['dates'] as $date): ?>
-                <li>
-
-                  <?php echo $date['rendered'] ?> (<?php echo $date['type'] ?>)
-
-                  <?php if (isset($date['actor'])): ?>
-                    <?php echo link_to($date['actor'], array($date['actor'], 
'module' => 'actor')) ?>
-                  <?php endif; ?>
-
-                </li>
-              <?php endforeach; ?>
-            </ul>
-          </div>
-        </div>
-      <?php endif; ?>
+<!-- TEMPLATE -->
+      <div class="result">
+        <h3><a href="#"><?php echo $doc[$sf_user->getCulture()]['title'] ?: 
$doc[$doc['sourceCulture']]['title']; ?>
+          [<span style="font-style: italic;"><?php echo $pager->facets['Level 
of Description']['terms'][$doc['levelOfDescription']['id']]['term']; 
?></span>]</a>
+        </h3>
+        <ul class="breadcrumb">
+          <li><a href="#">Vancouver Maritime Museum Library</a></li>
+          <li><a href="#">11th Gun Battalion</a></li>
+          <li><a href="#">Visual Arts Projects</a></li>
+        </ul>
+        <p><?php echo $doc[$sf_user->getCulture()]['scopeAndContent'] ?: 
$doc[$doc['sourceCulture']]['scopeAndContent']; ?></p>
+      </div> <!-- /.result -->
+<!-- END -->
 
-      <?php if (isset($doc['levelOfDescription'])): ?>
-        <?php echo render_show(__('Level of description'), 
render_value($doc['levelOfDescription'])) ?>
-      <?php endif; ?>
-
-      <?php if (sfConfig::get('app_multi_repository') && null != 
isset($doc['repository']['id'])): ?>
-        <?php echo render_show(__('Repository'), 
link_to($doc['repository']['en']['name'], array('slug' => 
$doc['repository']['slug'], 'module' => 'repository'))) ?>
-      <?php endif; ?>
-
-      <?php if (isset($doc['collectionRoot']['id']) && 
$doc['collectionRoot']['id'] !== $hit->getId()): ?>
-        <?php echo render_show(__('Part of'), 
link_to($doc['collectionRoot']['title'], array('slug' => 
$doc['collectionRoot']['slug'], 'module' => 'informationobject'))) ?>
-      <?php endif; ?>
+<pre style="font-size: 1.3em; font-family: arial;"><?php var_dump($doc); 
?></pre>
 
     </div>
   <?php endforeach; ?>

-- 
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