Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
MonographSearchDAO.inc.php
1 <?php
2 
17 import('classes.search.MonographSearch');
18 import('lib.pkp.classes.search.SubmissionSearchDAO');
19 
24  function MonographSearchDAO() {
25  parent::SubmissionSearchDAO();
26  }
27 
34  function getPhraseResults($press, $phrase, $publishedFrom = null, $publishedTo = null, $type = null, $limit = 500, $cacheHours = 24) {
35  import('lib.pkp.classes.db.DBRowIterator');
36  if (empty($phrase)) {
37  $results = false;
38  return new DBRowIterator($results);
39  }
40 
41  $sqlFrom = '';
42  $sqlWhere = '';
43 
44  for ($i = 0, $count = count($phrase); $i < $count; $i++) {
45  if (!empty($sqlFrom)) {
46  $sqlFrom .= ', ';
47  $sqlWhere .= ' AND ';
48  }
49  $sqlFrom .= 'submission_search_object_keywords o'.$i.' NATURAL JOIN submission_search_keyword_list k'.$i;
50  if (strstr($phrase[$i], '%') === false) $sqlWhere .= 'k'.$i.'.keyword_text = ?';
51  else $sqlWhere .= 'k'.$i.'.keyword_text LIKE ?';
52  if ($i > 0) $sqlWhere .= ' AND o0.object_id = o'.$i.'.object_id AND o0.pos+'.$i.' = o'.$i.'.pos';
53 
54  $params[] = $phrase[$i];
55  }
56 
57  if (!empty($type)) {
58  $sqlWhere .= ' AND (o.type & ?) != 0';
59  $params[] = $type;
60  }
61 
62  if (!empty($press)) {
63  $sqlWhere .= ' AND s.context_id = ?';
64  $params[] = $press->getId();
65  }
66 
67  $result = $this->retrieveCached(
68  $sql = 'SELECT
69  o.submission_id,
70  COUNT(*) AS count
71  FROM
72  submissions s,
73  published_submissions ps,
74  submission_search_objects o NATURAL JOIN ' . $sqlFrom . '
75  WHERE
76  s.submission_id = ps.submission_id AND o.submission_id = s.submission_id AND ' . $sqlWhere . '
77  GROUP BY o.submission_id
78  ORDER BY count DESC
79  LIMIT ' . $limit,
80  $params,
81  3600 * $cacheHours // Cache for 24 hours
82  );
83 
84  return new DBRowIterator($result);
85  }
86 }
87 
88 ?>
DAO class for submission search index.
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
getPhraseResults($press, $phrase, $publishedFrom=null, $publishedTo=null, $type=null, $limit=500, $cacheHours=24)
DAO class for monograph search index.
& retrieveCached($sql, $params=false, $secsToCache=3600, $callHooks=true)
Definition: DAO.inc.php:113