-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapachesolr-numResults.patch
46 lines (45 loc) · 2.02 KB
/
apachesolr-numResults.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
apachesolr.module | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/apachesolr.module b/apachesolr.module
index 324f10c..6f2a763 100644
--- a/apachesolr.module
+++ b/apachesolr.module
@@ -1458,6 +1458,38 @@ function apachesolr_do_query(DrupalSolrQueryInterface $current_query) {
$keys = htmlspecialchars($keys, ENT_NOQUOTES, 'UTF-8');
$keys = str_replace("'", ''', $keys);
$response = $query->search($keys);
+
+ // Are results being returned to us in grouped format?
+ // If so, make it appear as if they aren't.
+ // Solr can do this itself using group.main=true, but won't return a count
+ // We do this here rather than in *_process_response so the grouping is totally
+ // transparent to other code such as users of the static response cache
+ if (empty($response->response) && isset($response->grouped)) {
+ $group_truncate = $query->getParam('group.truncate');
+ $group_names = array_keys(get_object_vars($response->grouped));
+ if (count($group_names) > 1) {
+ watchdog(
+ 'Apache Solr',
+ 'Multiple group commands are not currently supported - using first group returned.',
+ WATCHDOG_WARNING
+ );
+ }
+ if (isset($response->grouped->{$group_names[0]}->ngroups)) {
+ $response->response->numFound = $response->grouped->{$group_names[0]}->ngroups;
+ }
+ else {
+ $response->response->numFound = $response->grouped->{$group_names[0]}->matches;
+ }
+ $response->response->docs = array();
+ foreach ($response->grouped->{$group_names[0]}->groups as $group) {
+ foreach ($group->doclist->docs as $key => $doc) {
+ $group->doclist->docs[$key]->groupValue = $group_names[0];
+ }
+ $response->response->docs = array_merge($response->response->docs, $group->doclist->docs);
+ }
+ unset($response->grouped);
+ }
+
// The response is cached so that it is accessible to the blocks and anything
// else that needs it beyond the initial search.
apachesolr_static_response_cache($searcher, $response);