Skip to content
Snippets Groups Projects
Commit ef8b8cc3 authored by aydreeihn's avatar aydreeihn
Browse files

Issue: Duplicate Search Results

This commit ensures that we do not return duplicate results when searching for Tickets with an Advanced Search that contains keywords.
parent c0baa320
No related branches found
No related tags found
No related merge requests found
......@@ -77,16 +77,21 @@ $page = ($_GET['p'] && is_numeric($_GET['p']))?$_GET['p']:1;
$pageNav = new Pagenate(PHP_INT_MAX, $page, PAGE_LIMIT);
$tickets = $pageNav->paginateSimple($tickets);
// Creative twist here. Create a new query copying the query criteria, sort, limit,
// and offset. Then join this new query to the $tickets query and clear the
// criteria, sort, limit, and offset from the outer query.
$criteria = clone $tickets;
$criteria->annotations = $criteria->related = $criteria->aggregated = [];
$tickets->constraints = $tickets->extra = [];
$tickets = $tickets->filter(['ticket_id__in' => $criteria->values_flat('ticket_id')])
->limit(false)->offset(false)->order_by(false);
# Index hint should be used on the $criteria query only
$tickets->clearOption(QuerySet::OPT_INDEX_HINT);
if (isset($tickets->extra['tables'])) {
// Creative twist here. Create a new query copying the query criteria, sort, limit,
// and offset. Then join this new query to the $tickets query and clear the
// criteria, sort, limit, and offset from the outer query.
$criteria = clone $tickets;
$criteria->limit(500);
$criteria->annotations = $criteria->related = $criteria->aggregated =
$criteria->annotations = $criteria->ordering = [];
$tickets->constraints = $tickets->extra = [];
$tickets = $tickets->filter(['ticket_id__in' =>
$criteria->values_flat('ticket_id')]);
# Index hint should be used on the $criteria query only
$tickets->clearOption(QuerySet::OPT_INDEX_HINT);
$tickets->distinct('ticket_id');
}
$count = $queue->getCount($thisstaff) ?: (PAGE_LIMIT*3);
$pageNav->setTotal($count, true);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment