Open Journal Systems  3.0.0
 All Data Structures 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  import('lib.pkp.classes.submission.Submission'); // STATUS_PUBLISHED
77  $result = $this->retrieveCached(
78  'SELECT
79  o.submission_id,
80  MAX(s.context_id) AS journal_id,
81  MAX(i.date_published) AS i_pub,
82  MAX(ps.date_published) AS s_pub,
83  COUNT(*) AS count
84  FROM
85  submissions s,
86  published_submissions ps,
87  issues i,
88  submission_search_objects o NATURAL JOIN ' . $sqlFrom . '
89  WHERE
90  s.submission_id = o.submission_id AND
91  s.status = ' . STATUS_PUBLISHED . ' AND
92  ps.submission_id = s.submission_id AND
93  i.issue_id = ps.issue_id AND
94  i.published = 1 AND ' . $sqlWhere . '
95  GROUP BY o.submission_id
96  ORDER BY count DESC
97  LIMIT ' . $limit,
98  $params,
99  3600 * $cacheHours // Cache for 24 hours
100  );
101 
102  $returner = array();
103  while (!$result->EOF) {
104  $row = $result->getRowAssoc(false);
105  $returner[$row['submission_id']] = array(
106  'count' => $row['count'],
107  'journal_id' => $row['journal_id'],
108  'issuePublicationDate' => $this->datetimeFromDB($row['i_pub']),
109  'publicationDate' => $this->datetimeFromDB($row['s_pub'])
110  );
111  $result->MoveNext();
112  }
113  $result->Close();
114 
115  return $returner;
116  }
117 }
118 
119 ?>
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