Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkp/pkp-lib#10139 fix Author search pulls in keywords too #4380

Open
wants to merge 2 commits into
base: stable-3_3_0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 33 additions & 30 deletions classes/search/ArticleSearchDAO.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,45 +30,46 @@ class ArticleSearchDAO extends SubmissionSearchDAO {
*/
public function getPhraseResults($journal, $phrase, $publishedFrom = null, $publishedTo = null, $type = null, $limit = 500) {
if (empty($phrase)) return array();

$sqlFrom = '';
$sqlWhere = '';
$params = array();

for ($i = 0, $count = count($phrase); $i < $count; $i++) {
if (!empty($sqlFrom)) {
$sqlFrom .= ', ';
$sqlWhere .= ' AND ';
}
$sqlFrom .= $i > 0 ? ', ' : '';
$sqlFrom .= 'submission_search_object_keywords o'.$i.' NATURAL JOIN submission_search_keyword_list k'.$i;
if (strstr($phrase[$i], '%') === false) $sqlWhere .= 'k'.$i.'.keyword_text = ?';
else $sqlWhere .= 'k'.$i.'.keyword_text LIKE ?';
if ($i > 0) $sqlWhere .= ' AND o0.object_id = o'.$i.'.object_id AND o0.pos+'.$i.' = o'.$i.'.pos';

$sqlWhere .= $i > 0 ? ' AND ' : '';
$sqlWhere .= 'k'.$i.'.keyword_text LIKE ?';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might change a bit the behavior (e.g. _, a wildcard, would be searched with an exact match previously), but I didn't inspect further, in general it should be ok...

$params[] = $phrase[$i];
if ($i > 0) {
$sqlWhere .= ' AND o0.object_id = o'.$i.'.object_id AND o0.pos+'.$i.' = o'.$i.'.pos';
}
}

if (!empty($type)) {
$sqlWhere .= ' AND (o.type & ?) != 0';
$sqlWhere .= ' AND o.type = ?';
$params[] = $type;
}

}
if (!empty($publishedFrom)) {
$sqlWhere .= ' AND p.date_published >= ' . $this->datetimeToDB($publishedFrom);
$sqlWhere .= ' AND p.date_published >= ?';
$params[] = $this->datetimeToDB($publishedFrom);
}

if (!empty($publishedTo)) {
$sqlWhere .= ' AND p.date_published <= ' . $this->datetimeToDB($publishedTo);
$sqlWhere .= ' AND p.date_published <= ?';
$params[] = $this->datetimeToDB($publishedTo);
}

if (!empty($journal)) {
$sqlWhere .= ' AND i.journal_id = ?';
$params[] = $journal->getId();
}

import('lib.pkp.classes.submission.PKPSubmission'); // STATUS_PUBLISHED
$result = $this->retrieve(
'SELECT

$query = "
SELECT
o.submission_id,
MAX(s.context_id) AS journal_id,
MAX(i.date_published) AS i_pub,
Expand All @@ -77,23 +78,25 @@ public function getPhraseResults($journal, $phrase, $publishedFrom = null, $publ
FROM
submissions s
JOIN publications p ON (p.publication_id = s.current_publication_id)
JOIN publication_settings ps ON (ps.publication_id = p.publication_id AND ps.setting_name=\'issueId\' AND ps.locale=\'\')
JOIN publication_settings ps ON (ps.publication_id = p.publication_id AND ps.setting_name='issueId' AND ps.locale='')
JOIN issues i ON (CAST(i.issue_id AS CHAR(20)) = ps.setting_value AND i.journal_id = s.context_id)
JOIN submission_search_objects o ON (s.submission_id = o.submission_id)
JOIN journals j ON j.journal_id = s.context_id
LEFT JOIN journal_settings js ON j.journal_id = js.journal_id AND js.setting_name = \'publishingMode\'
NATURAL JOIN ' . $sqlFrom . '
LEFT JOIN journal_settings js ON j.journal_id = js.journal_id AND js.setting_name = 'publishingMode'
NATURAL JOIN {$sqlFrom}
WHERE
(js.setting_value <> \'' . PUBLISHING_MODE_NONE . '\' OR
js.setting_value IS NULL) AND j.enabled = 1 AND
s.status = ' . STATUS_PUBLISHED . ' AND
i.published = 1 AND ' . $sqlWhere . '
(js.setting_value <> '".PUBLISHING_MODE_NONE."' OR js.setting_value IS NULL) AND
j.enabled = 1 AND
s.status = ".STATUS_PUBLISHED." AND
i.published = 1 AND
{$sqlWhere}
GROUP BY o.submission_id
ORDER BY count DESC
LIMIT ' . $limit,
$params
);

LIMIT {$limit}
";

$result = $this->retrieve($query, $params);

$returner = [];
foreach ($result as $row) {
$returner[$row->submission_id] = [
Expand Down
Loading