예제 #1
0
 public static function getInstance()
 {
     if (self::$classInstance === null) {
         self::$classInstance = new self();
     }
     return self::$classInstance;
 }
예제 #2
0
 public function getSearchAllResult($searchVal)
 {
     if (empty($searchVal)) {
         return array('result' => TRUE, 'list' => array());
     }
     if (($cache = $this->photoCacheDao->findCacheByKey($this->photoCacheDao->getKeyAll($searchVal))) !== NULL) {
         $data = json_decode($cache->data);
         $ids = $data->ids;
         $type = $data->type;
     } else {
         $ids = array();
         if (preg_match('/^(?:#|@)\\S+/', $searchVal) === 1) {
             switch ($searchVal[0]) {
                 case '#':
                     $tagIdList = $this->photoDao->getSearchResultAllListByTag($searchVal);
                     $ids = $this->photoDao->getPhotoIdListByTagIdList($tagIdList);
                     $type = 'hash';
                     break;
                 case '@':
                     $userIdList = $this->getSearchResultAllListByUsername(trim($searchVal, '@'));
                     $ids = $this->photoDao->findPhotoIdListByUserIdList($userIdList);
                     $type = 'user';
                     break;
             }
         } else {
             if (mb_strlen($searchVal) < PHOTO_BOL_SearchIndexDao::getInstance()->getMinWordLen()) {
                 $ids = $this->photoDao->getSearchResultAllListByDescription($searchVal);
             } else {
                 $arr = array();
                 foreach (explode(' ', $searchVal) as $val) {
                     $arr[] = '+' . trim($val) . '*';
                 }
                 $data = $this->indexDao->findIndexedData(implode(' ', $arr), array(self::ENTITY_TYPE_PHOTO));
                 foreach ($data as $index) {
                     $ids[] = $index->entityId;
                 }
             }
             $type = 'desc';
         }
         try {
             $cache = new PHOTO_BOL_PhotoCache();
             $cache->key = $this->photoCacheDao->getKeyAll($searchVal);
             $cache->data = json_encode(array('type' => $type, 'ids' => $ids));
             $cache->createTimestamp = time();
             $this->photoCacheDao->save($cache);
         } catch (Exception $e) {
         }
     }
     return array('type' => $type, 'ids' => $ids);
 }