classes/search/PaperSearchDAO.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 //$Id$
00017 
00018 import('search.PaperSearch');
00019 import('paper.Paper');
00020 
00021 class PaperSearchDAO extends DAO {
00027    function insertKeyword($keyword) {
00028       static $paperSearchKeywordIds = array();
00029       if (isset($paperSearchKeywordIds[$keyword])) return $paperSearchKeywordIds[$keyword];
00030       $result =& $this->retrieve(
00031          'SELECT keyword_id FROM paper_search_keyword_list WHERE keyword_text = ?',
00032          $keyword
00033       );
00034       if($result->RecordCount() == 0) {
00035          $result->Close();
00036          unset($result);
00037          if ($this->update(
00038             'INSERT INTO paper_search_keyword_list (keyword_text) VALUES (?)',
00039             $keyword,
00040             true,
00041             false
00042          )) {
00043             $keywordId = $this->getInsertId('paper_search_keyword_list', 'keyword_id');
00044          } else {
00045             $keywordId = null; // Bug #2324
00046          }
00047       } else {
00048          $keywordId = $result->fields[0];
00049          $result->Close();
00050          unset($result);
00051       }
00052 
00053       $paperSearchKeywordIds[$keyword] = $keywordId;
00054 
00055       return $keywordId;
00056    }
00057 
00064    function &getPhraseResults(&$conference, $phrase, $publishedFrom = null, $publishedTo = null, $type = null, $limit = 500, $cacheHours = 24) {
00065       import('db.DBRowIterator');
00066       if (empty($phrase)) {
00067          $results = false;
00068          $returner = new DBRowIterator($results);
00069          return $returner;
00070       }
00071 
00072       $sqlFrom = '';
00073       $sqlWhere = '';
00074 
00075       for ($i = 0, $count = count($phrase); $i < $count; $i++) {
00076          if (!empty($sqlFrom)) {
00077             $sqlFrom .= ', ';
00078             $sqlWhere .= ' AND ';
00079          }
00080          $sqlFrom .= 'paper_search_object_keywords o'.$i.' NATURAL JOIN paper_search_keyword_list k'.$i;
00081          if (strstr($phrase[$i], '%') === false) $sqlWhere .= 'k'.$i.'.keyword_text = ?';
00082          else $sqlWhere .= 'k'.$i.'.keyword_text LIKE ?';
00083          if ($i > 0) $sqlWhere .= ' AND o0.object_id = o'.$i.'.object_id AND o0.pos+'.$i.' = o'.$i.'.pos';
00084 
00085          $params[] = $phrase[$i];
00086       }
00087 
00088       if (!empty($type)) {
00089          $sqlWhere .= ' AND (o.type & ?) != 0';
00090          $params[] = $type;
00091       }
00092 
00093       if (!empty($publishedFrom)) {
00094          $sqlWhere .= ' AND pa.date_published >= ' . $this->datetimeToDB($publishedFrom);
00095       }
00096 
00097       if (!empty($publishedTo)) {
00098          $sqlWhere .= ' AND pa.date_published <= ' . $this->datetimeToDB($publishedTo);
00099       }
00100 
00101       if (!empty($conference)) {
00102          $sqlWhere .= ' AND i.conference_id = ?';
00103          $params[] = $conference->getId();
00104       }
00105 
00106       $result =& $this->retrieveCached(
00107          'SELECT  o.paper_id,
00108             COUNT(*) AS count
00109          FROM  published_papers pa,
00110             papers p,
00111             sched_confs i,
00112             paper_search_objects o
00113          NATURAL JOIN ' . $sqlFrom . '
00114          WHERE pa.paper_id = o.paper_id AND
00115             p.paper_id = pa.paper_id AND
00116             p.status = ' . STATUS_PUBLISHED . ' AND
00117             i.sched_conf_id = pa.sched_conf_id AND ' .
00118             $sqlWhere . '
00119          GROUP BY o.paper_id
00120          ORDER BY count DESC
00121          LIMIT ' . $limit,
00122          $params,
00123          3600 * $cacheHours // Cache for 24 hours
00124       );
00125 
00126       $returner = new DBRowIterator($result);
00127       return $returner;
00128    }
00129 
00136    function deletePaperKeywords($paperId, $type = null, $assocId = null) {
00137       $sql = 'SELECT object_id FROM paper_search_objects WHERE paper_id = ?';
00138       $params = array($paperId);
00139 
00140       if (isset($type)) {
00141          $sql .= ' AND type = ?';
00142          $params[] = $type;
00143       }
00144 
00145       if (isset($assocId)) {
00146          $sql .= ' AND assoc_id = ?';
00147          $params[] = $assocId;
00148       }
00149 
00150       $result =& $this->retrieve($sql, $params);
00151       while (!$result->EOF) {
00152          $objectId = $result->fields[0];
00153          $this->update('DELETE FROM paper_search_object_keywords WHERE object_id = ?', $objectId);
00154          $this->update('DELETE FROM paper_search_objects WHERE object_id = ?', $objectId);
00155          $result->MoveNext();
00156       }
00157       $result->Close();
00158       unset($result);
00159    }
00160 
00168    function insertObject($paperId, $type, $assocId) {
00169       $result =& $this->retrieve(
00170          'SELECT object_id FROM paper_search_objects WHERE paper_id = ? AND type = ? AND assoc_id = ?',
00171          array($paperId, $type, $assocId)
00172       );
00173       if ($result->RecordCount() == 0) {
00174          $this->update(
00175             'INSERT INTO paper_search_objects (paper_id, type, assoc_id) VALUES (?, ?, ?)',
00176             array($paperId, $type, (int) $assocId)
00177          );
00178          $objectId = $this->getInsertId('paper_search_objects', 'object_id');
00179 
00180       } else {
00181          $objectId = $result->fields[0];
00182          $this->update(
00183             'DELETE FROM paper_search_object_keywords WHERE object_id = ?',
00184             $objectId
00185          );
00186       }
00187       $result->Close();
00188       unset($result);
00189 
00190       return $objectId;
00191    }
00192 
00200    function insertObjectKeyword($objectId, $keyword, $position) {
00201       $keywordId = $this->insertKeyword($keyword);
00202       if ($keywordId === null) return null; // Bug #2324
00203       $this->update(
00204          'INSERT INTO paper_search_object_keywords (object_id, keyword_id, pos) VALUES (?, ?, ?)',
00205          array($objectId, $keywordId, $position)
00206       );
00207       return $keywordId;
00208    }
00209 }
00210 
00211 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7