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 
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($publishedFrom)) {
63  $sqlWhere .= ' AND ps.date_published >= ' . $this->datetimeToDB($publishedFrom);
64  }
65 
66  if (!empty($publishedTo)) {
67  $sqlWhere .= ' AND ps.date_published <= ' . $this->datetimeToDB($publishedTo);
68  }
69 
70  if (!empty($journal)) {
71  $sqlWhere .= ' AND i.journal_id = ?';
72  $params[] = $journal->getId();
73  }
74 
75  $result = $this->retrieveCached(
76  'SELECT
77  o.submission_id,
78  MAX(s.context_id) AS journal_id,
79  MAX(i.date_published) AS i_pub,
80  MAX(ps.date_published) AS s_pub,
81  COUNT(*) AS count
82  FROM
83  submissions s,
84  published_submissions ps,
85  issues i,
86  submission_search_objects o NATURAL JOIN ' . $sqlFrom . '
87  WHERE
88  s.submission_id = o.submission_id AND
89  ps.submission_id = s.submission_id AND
90  i.issue_id = ps.issue_id AND
91  i.published = 1 AND ' . $sqlWhere . '
92  GROUP BY o.submission_id
93  ORDER BY count DESC
94  LIMIT ' . $limit,
95  $params,
96  3600 * $cacheHours // Cache for 24 hours
97  );
98 
99  $returner = array();
100  while (!$result->EOF) {
101  $row = $result->getRowAssoc(false);
102  $returner[$row['submission_id']] = array(
103  'count' => $row['count'],
104  'journal_id' => $row['journal_id'],
105  'issuePublicationDate' => $this->datetimeFromDB($row['i_pub']),
106  'publicationDate' => $this->datetimeFromDB($row['s_pub'])
107  );
108  $result->MoveNext();
109  }
110  $result->Close();
111  }
112 
113 }
114 
115 ?>
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