Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
ArticleSearchDAO.inc.php
1 <?php
2 
17 import('classes.search.ArticleSearch');
18 import('lib.pkp.classes.search.SubmissionSearchDAO');
19 
24  function ArticleSearchDAO() {
25  parent::SubmissionSearchDAO();
26  }
27 
34  function getPhraseResults($journal, $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  $params = array();
44 
45  for ($i = 0, $count = count($phrase); $i < $count; $i++) {
46  if (!empty($sqlFrom)) {
47  $sqlFrom .= ', ';
48  $sqlWhere .= ' AND ';
49  }
50  $sqlFrom .= 'submission_search_object_keywords o'.$i.' NATURAL JOIN submission_search_keyword_list k'.$i;
51  if (strstr($phrase[$i], '%') === false) $sqlWhere .= 'k'.$i.'.keyword_text = ?';
52  else $sqlWhere .= 'k'.$i.'.keyword_text LIKE ?';
53  if ($i > 0) $sqlWhere .= ' AND o0.object_id = o'.$i.'.object_id AND o0.pos+'.$i.' = o'.$i.'.pos';
54 
55  $params[] = $phrase[$i];
56  }
57 
58  if (!empty($type)) {
59  $sqlWhere .= ' AND (o.type & ?) != 0';
60  $params[] = $type;
61  }
62 
63  if (!empty($publishedFrom)) {
64  $sqlWhere .= ' AND ps.date_published >= ' . $this->datetimeToDB($publishedFrom);
65  }
66 
67  if (!empty($publishedTo)) {
68  $sqlWhere .= ' AND ps.date_published <= ' . $this->datetimeToDB($publishedTo);
69  }
70 
71  if (!empty($journal)) {
72  $sqlWhere .= ' AND i.journal_id = ?';
73  $params[] = $journal->getId();
74  }
75 
76  $result = $this->retrieveCached(
77  'SELECT
78  o.submission_id,
79  MAX(s.context_id) AS journal_id,
80  MAX(i.date_published) AS i_pub,
81  MAX(ps.date_published) AS s_pub,
82  COUNT(*) AS count
83  FROM
84  submissions s,
85  published_submissions ps,
86  issues i,
87  submission_search_objects o NATURAL JOIN ' . $sqlFrom . '
88  WHERE
89  s.submission_id = o.submission_id AND
90  ps.submission_id = s.submission_id AND
91  i.issue_id = ps.issue_id AND
92  i.published = 1 AND ' . $sqlWhere . '
93  GROUP BY o.submission_id
94  ORDER BY count DESC
95  LIMIT ' . $limit,
96  $params,
97  3600 * $cacheHours // Cache for 24 hours
98  );
99 
100  $returner = array();
101  while (!$result->EOF) {
102  $row = $result->getRowAssoc(false);
103  $returner[$row['submission_id']] = array(
104  'count' => $row['count'],
105  'journal_id' => $row['journal_id'],
106  'issuePublicationDate' => $this->datetimeFromDB($row['i_pub']),
107  'publicationDate' => $this->datetimeFromDB($row['s_pub'])
108  );
109  $result->MoveNext();
110  }
111  $result->Close();
112 
113  return $returner;
114  }
115 }
116 
117 ?>
DAO class for submission search index.
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
getPhraseResults($journal, $phrase, $publishedFrom=null, $publishedTo=null, $type=null, $limit=500, $cacheHours=24)
datetimeFromDB($dt)
Definition: DAO.inc.php:313
DAO class for article search index.
& retrieveCached($sql, $params=false, $secsToCache=3600, $callHooks=true)
Definition: DAO.inc.php:113
datetimeToDB($dt)
Definition: DAO.inc.php:293