add facet to tags, correct auto indexation
authorymh <ymh.work@gmail.com>
Thu, 29 Apr 2010 03:05:12 +0200
changeset 104 17b95f521b01
parent 103 4227dc4dd211
child 105 0e0ffcf5f191
add facet to tags, correct auto indexation
engine/solr/solr/conf/schema.xml
engine/sonyengine/mosatags.sonyengine.war
web/thdProject/lib/model/doctrine/ThdFilm.class.php
web/thdProject/lib/model/doctrine/ThdSegment.class.php
web/thdProject/lib/model/doctrine/ThdTagTable.class.php
web/thdProject/lib/model/doctrine/ThdVideo.class.php
web/thdProject/plugins/uvmcSolrSearchPlugin/lib/uvmcSolrEventListener.class.php
--- a/engine/solr/solr/conf/schema.xml	Wed Apr 28 20:08:07 2010 +0200
+++ b/engine/solr/solr/conf/schema.xml	Thu Apr 29 03:05:12 2010 +0200
@@ -52,7 +52,7 @@
     </fieldType>
     <fieldType name="tags" class="solr.TextField" sortMissingLast="true" omitNorms="true" >
       <analyzer>
-        <tokenizer class="solr.PatternTokenizerFactory" pattern=",*" />
+        <tokenizer class="solr.StandardTokenizerFactory" pattern=",*" />
         <filter class="solr.LowerCaseFilterFactory"/>
         <filter class="solr.TrimFilterFactory" />
         <filter class="solr.SnowballPorterFilterFactory" language="French" />
@@ -94,7 +94,7 @@
    <field name="title" type="title"  indexed="true" stored="false" required="false" />
    <field name="original_title" type="title"  indexed="true" stored="false" required="false" />
    <field name="desc" type="textdata"  indexed="true" stored="false" required="false" />
-   <field name="tags" type="tags"  indexed="true" stored="false" required="false" />
+   <field name="tags" type="tags"  indexed="true" stored="true" required="false" multiValued="true" />
    <field name="directors" type="personsList"  indexed="true" stored="false" required="false" />
    <field name="actors" type="personsList"  indexed="true" stored="false" required="false" />
    <field name="all" type="textdata" indexed="true" stored="true" required="false" multiValued="true" />    
Binary file engine/sonyengine/mosatags.sonyengine.war has changed
--- a/web/thdProject/lib/model/doctrine/ThdFilm.class.php	Wed Apr 28 20:08:07 2010 +0200
+++ b/web/thdProject/lib/model/doctrine/ThdFilm.class.php	Thu Apr 29 03:05:12 2010 +0200
@@ -26,7 +26,7 @@
         $directors = $this->getSolrTextValue($this->getDirectors());
         $actors = $this->getSolrTextValue($this->getActors());
         $original_title = $this->getSolrTextValue($this->getOriginal_title());
-        $tags = $this->getSolrTextValue($this->getTagsToText());
+        $tags = $this->getTags();
         //$all = implode(" ",array($title,$desc,$directors,$actors,$original_title,$tags));
 
         $fields = array('type'           => $this->getSolrTextValue($type),
--- a/web/thdProject/lib/model/doctrine/ThdSegment.class.php	Wed Apr 28 20:08:07 2010 +0200
+++ b/web/thdProject/lib/model/doctrine/ThdSegment.class.php	Thu Apr 29 03:05:12 2010 +0200
@@ -48,61 +48,4 @@
     return $tags;
   }
 
-      /*public function getSolrDocumentFields()
-    {           // keys of this array are fields' name of solr's schema.xml
-        $type = "ThdFilm";
-        $fields = array('type'           => $type,
-                        'id'             => $this->getId(),
-                        'title'          => array('value' => $this->getTitle(), 'boost' => 1.0),
-                        'tags'           => array('value' => $this->getTags(), 'boost' => 1.0),
-                        'desc'           => array('value' => $this->getDesc(), 'boost' => 1.0),
-                        'uniqueid'       => array('value' => $this->getUniqueid(), 'boost' => 1.0),
-        );
-
-        return $fields;
-    }*/
-
-
-
-/*
-    public function getTagsArray() {
-
-        $tags = $this->getTags();
-        $res = array();
-
-        foreach (explode(',',$tags) as $tag_name) {
-            $res[] = trim($tag_name);
-        }
-
-        return $res;
-    }
-
-
-    public function postInsert($event) {
-
-        $q = Doctrine_Query::create()
-           ->from('ThdSegment s')
-           ->innerJoin('s.ThdVideo v')
-           ->innerJoin('v.ThdFilm f')
-           ->where('s.id = ?', $this->id);
-
-        $segment = $q->fetchOne();
-
-        $tags_array = array();
-
-        $tags = $this->getTagsArray();
-        foreach ($tags as $tag_name) {
-            $tags_array[] = array('segment_id'=>$segment->ThdVideo->ThdFilm->uniqueid,'name'=>$tag_name);
-        }
-
-        sfContext::getInstance()->getLogger()->info("insert segment " . print_r($tags_array,true));
-
-    	$dispatcher = sfContext::getInstance()->getEventDispatcher();
-    	$dispatcher->notify(new sfEvent($this, 'iri_sonyengine.tag_add', array('object'=>$tags_array, 'retrain'=>true)));
-
-    	$dispatcher->notify(new sfEvent($this, 'uvmc_solr.update_document', array('object' => $segment->ThdVideo->ThdFilm, 'commit' => true)));
-
-
-    }*/
-
 }
--- a/web/thdProject/lib/model/doctrine/ThdTagTable.class.php	Wed Apr 28 20:08:07 2010 +0200
+++ b/web/thdProject/lib/model/doctrine/ThdTagTable.class.php	Thu Apr 29 03:05:12 2010 +0200
@@ -4,5 +4,5 @@
  */
 class ThdTagTable extends Doctrine_Table
 {
-
+//http://localhost:8080/solr/select?q=*%3A*&rows=0&facet=true&facet.limit=-1&facet.field=tags
 }
\ No newline at end of file
--- a/web/thdProject/lib/model/doctrine/ThdVideo.class.php	Wed Apr 28 20:08:07 2010 +0200
+++ b/web/thdProject/lib/model/doctrine/ThdVideo.class.php	Thu Apr 29 03:05:12 2010 +0200
@@ -22,6 +22,24 @@
       $segmentTagObj->setTagId($tagObj->getId());
       $segmentTagObj->save();
     }
+    
+    $q = Doctrine_Query::create()
+           ->from('ThdVideo v')
+           ->innerJoin('v.ThdFilm f')
+           ->where('v.id = ?', $this->id);
+
+    $segment = $q->fetchOne();
+
+    foreach ($tags as $tag_name) {
+        $tags_array[] = array('segment_id'=>$this->ThdFilm->uniqueid,'name'=>$tag_name);
+    }
+
+    sfContext::getInstance()->getLogger()->info("insert segment " . print_r($tags_array,true));
+
+    $dispatcher = sfContext::getInstance()->getEventDispatcher();
+    $dispatcher->notify(new sfEvent($this, 'iri_sonyengine.tag_add', array('object'=>$tags_array, 'retrain'=>true)));
+
+    $dispatcher->notify(new sfEvent($this, 'uvmc_solr.update_document', array('object' => $this->ThdFilm, 'commit' => true)));
 
     return $segmentObj;
   }
--- a/web/thdProject/plugins/uvmcSolrSearchPlugin/lib/uvmcSolrEventListener.class.php	Wed Apr 28 20:08:07 2010 +0200
+++ b/web/thdProject/plugins/uvmcSolrSearchPlugin/lib/uvmcSolrEventListener.class.php	Thu Apr 29 03:05:12 2010 +0200
@@ -195,7 +195,18 @@
         if (isset($fieldProperty['value']))
         {
           $boost = isset($fieldProperty['boost']) ? (float) $fieldProperty['boost'] : false;
-          $document->addField($fieldName, $fieldProperty['value'], $boost);
+          $value = $fieldProperty['value'];
+          if (is_array($value))
+          {
+          	foreach($value as $multivalue)
+          	{
+          		$document->addField($fieldName, $multivalue, $boost);
+          	}
+          }
+          else
+          {
+            $document->addField($fieldName, $value, $boost);
+          }
         }
         else
         {