ocs  2.3.6
About: OCS (Open Conference System) is a Web publishing tool that will create a complete Web presence for your scholarly conference.
  Fossies Dox: ocs-2.3.6.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

PaperSearchDAO.inc.php
Go to the documentation of this file.
1 <?php
2 
16 //$Id$
17 
18 import('search.PaperSearch');
19 import('paper.Paper');
20 
21 class PaperSearchDAO extends DAO {
27  function insertKeyword($keyword) {
28  static $paperSearchKeywordIds = array();
29  if (isset($paperSearchKeywordIds[$keyword])) return $paperSearchKeywordIds[$keyword];
30  $result =& $this->retrieve(
31  'SELECT keyword_id FROM paper_search_keyword_list WHERE keyword_text = ?',
32  $keyword
33  );
34  if($result->RecordCount() == 0) {
35  $result->Close();
36  unset($result);
37  if ($this->update(
38  'INSERT INTO paper_search_keyword_list (keyword_text) VALUES (?)',
39  $keyword,
40  true,
41  false
42  )) {
43  $keywordId = $this->getInsertId('paper_search_keyword_list', 'keyword_id');
44  } else {
45  $keywordId = null; // Bug #2324
46  }
47  } else {
48  $keywordId = $result->fields[0];
49  $result->Close();
50  unset($result);
51  }
52 
53  $paperSearchKeywordIds[$keyword] = $keywordId;
54 
55  return $keywordId;
56  }
57 
64  function &getPhraseResults(&$conference, $phrase, $publishedFrom = null, $publishedTo = null, $type = null, $limit = 500, $cacheHours = 24) {
65  import('db.DBRowIterator');
66  if (empty($phrase)) {
67  $results = false;
68  $returner = new DBRowIterator($results);
69  return $returner;
70  }
71 
72  $sqlFrom = '';
73  $sqlWhere = '';
74 
75  for ($i = 0, $count = count($phrase); $i < $count; $i++) {
76  if (!empty($sqlFrom)) {
77  $sqlFrom .= ', ';
78  $sqlWhere .= ' AND ';
79  }
80  $sqlFrom .= 'paper_search_object_keywords o'.$i.' NATURAL JOIN paper_search_keyword_list k'.$i;
81  if (strstr($phrase[$i], '%') === false) $sqlWhere .= 'k'.$i.'.keyword_text = ?';
82  else $sqlWhere .= 'k'.$i.'.keyword_text LIKE ?';
83  if ($i > 0) $sqlWhere .= ' AND o0.object_id = o'.$i.'.object_id AND o0.pos+'.$i.' = o'.$i.'.pos';
84 
85  $params[] = $phrase[$i];
86  }
87 
88  if (!empty($type)) {
89  $sqlWhere .= ' AND (o.type & ?) != 0';
90  $params[] = $type;
91  }
92 
93  if (!empty($publishedFrom)) {
94  $sqlWhere .= ' AND pa.date_published >= ' . $this->datetimeToDB($publishedFrom);
95  }
96 
97  if (!empty($publishedTo)) {
98  $sqlWhere .= ' AND pa.date_published <= ' . $this->datetimeToDB($publishedTo);
99  }
100 
101  if (!empty($conference)) {
102  $sqlWhere .= ' AND i.conference_id = ?';
103  $params[] = $conference->getId();
104  }
105 
106  $result =& $this->retrieveCached(
107  'SELECT o.paper_id,
108  COUNT(*) AS count
109  FROM published_papers pa,
110  papers p,
111  sched_confs i,
112  paper_search_objects o
113  NATURAL JOIN ' . $sqlFrom . '
114  WHERE pa.paper_id = o.paper_id AND
115  p.paper_id = pa.paper_id AND
116  p.status = ' . STATUS_PUBLISHED . ' AND
117  i.sched_conf_id = pa.sched_conf_id AND ' .
118  $sqlWhere . '
119  GROUP BY o.paper_id
120  ORDER BY count DESC
121  LIMIT ' . $limit,
122  $params,
123  3600 * $cacheHours // Cache for 24 hours
124  );
125 
126  $returner = new DBRowIterator($result);
127  return $returner;
128  }
129 
136  function deletePaperKeywords($paperId, $type = null, $assocId = null) {
137  $sql = 'SELECT object_id FROM paper_search_objects WHERE paper_id = ?';
138  $params = array($paperId);
139 
140  if (isset($type)) {
141  $sql .= ' AND type = ?';
142  $params[] = $type;
143  }
144 
145  if (isset($assocId)) {
146  $sql .= ' AND assoc_id = ?';
147  $params[] = $assocId;
148  }
149 
150  $result =& $this->retrieve($sql, $params);
151  while (!$result->EOF) {
152  $objectId = $result->fields[0];
153  $this->update('DELETE FROM paper_search_object_keywords WHERE object_id = ?', $objectId);
154  $this->update('DELETE FROM paper_search_objects WHERE object_id = ?', $objectId);
155  $result->MoveNext();
156  }
157  $result->Close();
158  unset($result);
159  }
160 
168  function insertObject($paperId, $type, $assocId) {
169  $result =& $this->retrieve(
170  'SELECT object_id FROM paper_search_objects WHERE paper_id = ? AND type = ? AND assoc_id = ?',
171  array($paperId, $type, $assocId)
172  );
173  if ($result->RecordCount() == 0) {
174  $this->update(
175  'INSERT INTO paper_search_objects (paper_id, type, assoc_id) VALUES (?, ?, ?)',
176  array($paperId, $type, (int) $assocId)
177  );
178  $objectId = $this->getInsertId('paper_search_objects', 'object_id');
179 
180  } else {
181  $objectId = $result->fields[0];
182  $this->update(
183  'DELETE FROM paper_search_object_keywords WHERE object_id = ?',
184  $objectId
185  );
186  }
187  $result->Close();
188  unset($result);
189 
190  return $objectId;
191  }
192 
200  function insertObjectKeyword($objectId, $keyword, $position) {
201  $keywordId = $this->insertKeyword($keyword);
202  if ($keywordId === null) return null; // Bug #2324
203  $this->update(
204  'INSERT INTO paper_search_object_keywords (object_id, keyword_id, pos) VALUES (?, ?, ?)',
205  array($objectId, $keywordId, $position)
206  );
207  return $keywordId;
208  }
209 }
210 
211 ?>
config TEMPLATE inc php
Definition: config.inc.php:4
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
DAO class for paper search index.
insertObjectKeyword($objectId, $keyword, $position)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:62
Wrapper around ADORecordSet providing "factory" features for generating objects from DAOs.
getInsertId($table='', $id='', $callHooks=true)
Definition: DAO.inc.php:225
insertObject($paperId, $type, $assocId)
deletePaperKeywords($paperId, $type=null, $assocId=null)
& retrieveCached($sql, $params=false, $secsToCache=3600, $callHooks=true)
Definition: DAO.inc.php:91
datetimeToDB($dt)
Definition: DAO.inc.php:258
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:186
const STATUS_PUBLISHED
Definition: Paper.inc.php:27
& getPhraseResults(&$conference, $phrase, $publishedFrom=null, $publishedTo=null, $type=null, $limit=500, $cacheHours=24)