Skip to content

Commit

Permalink
pkp/pkp-lib#10178 Allow search by DOI in DOI manager
Browse files Browse the repository at this point in the history
  • Loading branch information
taslangraham committed Dec 18, 2024
1 parent be251ea commit 2a7c471
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
16 changes: 15 additions & 1 deletion classes/issue/Collector.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @file classes/issue/Collector.php
*
Expand All @@ -22,6 +23,7 @@
use Illuminate\Support\LazyCollection;
use InvalidArgumentException;
use PKP\core\interfaces\CollectorInterface;
use PKP\doi\Doi;
use PKP\plugins\Hook;

class Collector implements CollectorInterface
Expand Down Expand Up @@ -414,8 +416,11 @@ public function getQueryBuilder(): Builder
)
);

// Add support to search using DOI identifiers
// search phrases starting with number followed by a '.' will be interpreted as a DOI identifier. E.g: 10.1
$isSearchPhraseDoi = Doi::beginsWithDoiPrefixPattern($searchPhrase);
$words = array_filter(array_unique(explode(' ', $searchPhrase)), 'strlen');
if (count($words)) {
if (count($words) && !$isSearchPhraseDoi) {
$likePattern = DB::raw("CONCAT('%', LOWER(?), '%')");
foreach ($words as $word) {
$q->where(
Expand All @@ -441,6 +446,15 @@ public function getQueryBuilder(): Builder
);
}
}

if ($isSearchPhraseDoi) {
$q->whereIn('i.issue_id', function (Builder $query) {
$query->select('is.issue_id')
->from('issues as is')
->join('dois AS d', 'is.doi_id', '=', 'd.doi_id')
->whereLike('d.doi', "{$this->searchPhrase}%");
});
}
}

// Ordering for query-builder-based and legacy-based orderings
Expand Down
18 changes: 18 additions & 0 deletions classes/submission/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,22 @@ protected function addHasDoisFilterToQuery(Builder $q)
});
});
}

/** @copydoc PKP/classes/submission/Collector::addFilterByAssociatedDoiIdsToQuery() */
protected function addFilterByAssociatedDoiIdsToQuery(Builder $q)
{
$q->whereIn('s.submission_id', function (Builder $query) {
$query->select('p.submission_id')
->from('publication_galleys AS g')
->join('dois AS d', 'g.doi_id', '=', 'd.doi_id')
->join('publications AS p', 'g.publication_id', '=', 'p.publication_id')
->whereLike('d.doi', "{$this->searchPhrase}%")
->union(function (Builder $query) {
$query->select('p.submission_id')
->from('publications AS p')
->join('dois AS d', 'p.doi_id', '=', 'd.doi_id')
->whereLike('d.doi', "{$this->searchPhrase}%");
});
});
}
}

0 comments on commit 2a7c471

Please sign in to comment.