-
Notifications
You must be signed in to change notification settings - Fork 138
Support pagination with Solr Result Grouping #145
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |||||||||||||||||||||||||||||||||||||||
| namespace Knp\Component\Pager\Event\Subscriber\Paginate; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| use Knp\Component\Pager\Event\ItemsEvent; | ||||||||||||||||||||||||||||||||||||||||
| use Solarium\QueryType\Select\Query\Query; | ||||||||||||||||||||||||||||||||||||||||
| use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -19,11 +20,23 @@ public function items(ItemsEvent $event) | |||||||||||||||||||||||||||||||||||||||
| list($client, $query) = $values; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if ($client instanceof \Solarium\Client && $query instanceof \Solarium\QueryType\Select\Query\Query) { | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if ($grouping = $query->getComponent(Query::COMPONENT_GROUPING, false)) { | ||||||||||||||||||||||||||||||||||||||||
| $grouping->setNumberOfGroups(true); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+24
to
+26
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| $query->setStart($event->getOffset())->setRows($event->getLimit()); | ||||||||||||||||||||||||||||||||||||||||
| $solrResult = $client->select($query); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| $event->items = $solrResult->getIterator(); | ||||||||||||||||||||||||||||||||||||||||
| $event->count = $solrResult->getNumFound(); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if ($event->count === null && $grouping) { | ||||||||||||||||||||||||||||||||||||||||
| $groups = $solrResult->getComponent('grouping')->getGroups(); | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
31
to
+35
|
||||||||||||||||||||||||||||||||||||||||
| $firstGroup = reset($groups); | ||||||||||||||||||||||||||||||||||||||||
| $event->count = $firstGroup->getNumberOfGroups(); | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+35
to
+37
|
||||||||||||||||||||||||||||||||||||||||
| $groups = $solrResult->getComponent('grouping')->getGroups(); | |
| $firstGroup = reset($groups); | |
| $event->count = $firstGroup->getNumberOfGroups(); | |
| $groupingComponent = $solrResult->getComponent('grouping'); | |
| if ($groupingComponent !== null) { | |
| $groups = $groupingComponent->getGroups(); | |
| if (!empty($groups)) { | |
| $firstGroup = reset($groups); | |
| if (false !== $firstGroup) { | |
| $event->count = $firstGroup->getNumberOfGroups(); | |
| } else { | |
| $event->count = 0; | |
| } | |
| } else { | |
| $event->count = 0; | |
| } | |
| } else { | |
| $event->count = 0; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$groupingis only conditionally assigned inside theif ($grouping = ...)block, but it’s later referenced inif ($event->count === null && $grouping). IfgetNumFound()returns null and the query has no grouping component, this will read an undefined variable (PHP notice/warning). Initialize$grouping(e.g., tonull/false) before the firstifso it’s always defined.