コード例 #1
0
 public function actionIndex()
 {
     $solr = new Solr('deal-category');
     $solr->getService()->deleteByQuery('*:*');
     $cats = KeywordCategory::model()->findAll();
     $allkeywords = '';
     foreach ($cats as $c) {
         $sql = "select term from Keyword where category = {$c->id}";
         $command = Yii::app()->db->createCommand($sql);
         $rows = $command->queryColumn();
         $doc = $solr->getDoc();
         $doc->id = trim($c->name);
         $doc->keywords = implode(" ", $rows);
         $allkeywords .= $doc->keywords . ' ';
         d($doc);
         $solr->getService()->addDocument($doc);
     }
     $doc = $solr->getDoc();
     $doc->id = "Services & Others";
     $doc->keywords = $allkeywords;
     $solr->getService()->addDocument($doc);
     $solr->getService()->commit();
     $solr->getService()->optimize();
     $this->render('index');
 }
コード例 #2
0
 public function actionUpdateCategory($id, $category)
 {
     $solr = new Solr('search-engine');
     $solr_arc = new Solr('archive');
     $res = $solr->query('id:"' . $id . '"');
     $oldDoc = (array) $res->response->docs[0];
     $doc = $solr->getDoc();
     $doc->id = $id;
     $doc->category = $category;
     foreach ($oldDoc as $k => $v) {
         switch ($k) {
             case 'title':
             case 'dealsource':
             case 'price':
             case 'discount':
             case 'worth':
             case 'description':
             case 'imgsrc':
             case 'expiry':
             case 'merchant':
             case 'location':
             case 'bought':
             case 'created':
                 $doc->{$k} = $v;
                 break;
         }
     }
     try {
         $solr->getService()->addDocument($doc);
         $solr->getService()->commit();
         $solr->getService()->optimize();
         $solr_arc->getService()->addDocument($doc);
         $solr_arc->getService()->commit();
         $solr_arc->getService()->optimize();
         echo 'SUCCESS';
     } catch (Exception $e) {
         echo $e->getMessage();
         echo $e->getTrace();
     }
     Yii::app()->end();
 }