Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
solarium
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
solarium
Commits
75fcd89d
Commit
75fcd89d
authored
Aug 22, 2016
by
Bas de Nooijer
Committed by
GitHub
Aug 22, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #441 from pavelsmolka/function_groups
Add support for grouping result using a function
parents
926e0b59
61f57d82
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
4 deletions
+44
-4
docs/queries/select-query/result-of-a-select-query/component-results/grouping-result.md
...lt-of-a-select-query/component-results/grouping-result.md
+6
-2
library/Solarium/QueryType/Select/ResponseParser/Component/Grouping.php
...um/QueryType/Select/ResponseParser/Component/Grouping.php
+3
-1
tests/Solarium/Tests/QueryType/Select/ResponseParser/Component/GroupingTest.php
...ueryType/Select/ResponseParser/Component/GroupingTest.php
+35
-1
No files found.
docs/queries/select-query/result-of-a-select-query/component-results/grouping-result.md
View file @
75fcd89d
...
@@ -11,7 +11,9 @@ In most cases only one type of grouping is used, but you can mix any number of q
...
@@ -11,7 +11,9 @@ In most cases only one type of grouping is used, but you can mix any number of q
Examples
Examples
--------
--------
Grouped by field:
```php
Grouped by field:
```
php
<?php
<?php
require
(
__DIR__
.
'/init.php'
);
require
(
__DIR__
.
'/init.php'
);
...
@@ -69,7 +71,9 @@ htmlFooter();
...
@@ -69,7 +71,9 @@ htmlFooter();
```
```
Grouped by query:
```php
Grouped by query:
```
php
<?php
<?php
require
(
__DIR__
.
'/init.php'
);
require
(
__DIR__
.
'/init.php'
);
...
...
library/Solarium/QueryType/Select/ResponseParser/Component/Grouping.php
View file @
75fcd89d
...
@@ -67,7 +67,9 @@ class Grouping implements ComponentParserInterface
...
@@ -67,7 +67,9 @@ class Grouping implements ComponentParserInterface
// parse field groups
// parse field groups
$valueResultClass
=
$grouping
->
getOption
(
'resultvaluegroupclass'
);
$valueResultClass
=
$grouping
->
getOption
(
'resultvaluegroupclass'
);
$documentClass
=
$query
->
getOption
(
'documentclass'
);
$documentClass
=
$query
->
getOption
(
'documentclass'
);
foreach
(
$grouping
->
getFields
()
as
$field
)
{
// check grouping fields as well as the grouping function (either can be used in the query)
foreach
(
array_merge
(
$grouping
->
getFields
(),
array
(
$grouping
->
getFunction
()))
as
$field
)
{
if
(
isset
(
$data
[
'grouped'
][
$field
]))
{
if
(
isset
(
$data
[
'grouped'
][
$field
]))
{
$result
=
$data
[
'grouped'
][
$field
];
$result
=
$data
[
'grouped'
][
$field
];
...
...
tests/Solarium/Tests/QueryType/Select/ResponseParser/Component/GroupingTest.php
View file @
75fcd89d
...
@@ -64,6 +64,7 @@ class GroupingTest extends \PHPUnit_Framework_TestCase
...
@@ -64,6 +64,7 @@ class GroupingTest extends \PHPUnit_Framework_TestCase
$this
->
query
=
new
Query
();
$this
->
query
=
new
Query
();
$this
->
grouping
=
$this
->
query
->
getGrouping
();
$this
->
grouping
=
$this
->
query
->
getGrouping
();
$this
->
grouping
->
addField
(
'fieldA'
);
$this
->
grouping
->
addField
(
'fieldA'
);
$this
->
grouping
->
setFunction
(
'functionF'
);
$this
->
grouping
->
addQuery
(
'cat:1'
);
$this
->
grouping
->
addQuery
(
'cat:1'
);
$data
=
array
(
$data
=
array
(
...
@@ -83,6 +84,21 @@ class GroupingTest extends \PHPUnit_Framework_TestCase
...
@@ -83,6 +84,21 @@ class GroupingTest extends \PHPUnit_Framework_TestCase
)
)
)
)
),
),
'functionF'
=>
array
(
'matches'
=>
8
,
'ngroups'
=>
3
,
'groups'
=>
array
(
array
(
'groupValue'
=>
true
,
'doclist'
=>
array
(
'numFound'
=>
5
,
'docs'
=>
array
(
array
(
'id'
=>
3
,
'name'
=>
'fun'
)
)
)
)
)
),
'cat:1'
=>
array
(
'cat:1'
=>
array
(
'matches'
=>
40
,
'matches'
=>
40
,
'doclist'
=>
array
(
'doclist'
=>
array
(
...
@@ -101,13 +117,15 @@ class GroupingTest extends \PHPUnit_Framework_TestCase
...
@@ -101,13 +117,15 @@ class GroupingTest extends \PHPUnit_Framework_TestCase
public
function
testGroupParsing
()
public
function
testGroupParsing
()
{
{
$this
->
assertEquals
(
2
,
count
(
$this
->
result
->
getGroups
()));
$this
->
assertEquals
(
3
,
count
(
$this
->
result
->
getGroups
()));
$fieldGroup
=
$this
->
result
->
getGroup
(
'fieldA'
);
$fieldGroup
=
$this
->
result
->
getGroup
(
'fieldA'
);
$queryGroup
=
$this
->
result
->
getGroup
(
'cat:1'
);
$queryGroup
=
$this
->
result
->
getGroup
(
'cat:1'
);
$functionGroup
=
$this
->
result
->
getGroup
(
'functionF'
);
$this
->
assertEquals
(
'Solarium\QueryType\Select\Result\Grouping\FieldGroup'
,
get_class
(
$fieldGroup
));
$this
->
assertEquals
(
'Solarium\QueryType\Select\Result\Grouping\FieldGroup'
,
get_class
(
$fieldGroup
));
$this
->
assertEquals
(
'Solarium\QueryType\Select\Result\Grouping\QueryGroup'
,
get_class
(
$queryGroup
));
$this
->
assertEquals
(
'Solarium\QueryType\Select\Result\Grouping\QueryGroup'
,
get_class
(
$queryGroup
));
$this
->
assertEquals
(
'Solarium\QueryType\Select\Result\Grouping\FieldGroup'
,
get_class
(
$functionGroup
));
}
}
public
function
testFieldGroupParsing
()
public
function
testFieldGroupParsing
()
...
@@ -142,4 +160,20 @@ class GroupingTest extends \PHPUnit_Framework_TestCase
...
@@ -142,4 +160,20 @@ class GroupingTest extends \PHPUnit_Framework_TestCase
$result
=
$this
->
parser
->
parse
(
$this
->
query
,
$this
->
grouping
,
array
());
$result
=
$this
->
parser
->
parse
(
$this
->
query
,
$this
->
grouping
,
array
());
$this
->
assertEquals
(
array
(),
$result
->
getGroups
());
$this
->
assertEquals
(
array
(),
$result
->
getGroups
());
}
}
public
function
testFunctionGroupParsing
()
{
$fieldGroup
=
$this
->
result
->
getGroup
(
'functionF'
);
$valueGroups
=
$fieldGroup
->
getValueGroups
();
$this
->
assertEquals
(
8
,
$fieldGroup
->
getMatches
());
$this
->
assertEquals
(
3
,
$fieldGroup
->
getNumberOfGroups
());
$this
->
assertEquals
(
1
,
count
(
$valueGroups
));
$valueGroup
=
$valueGroups
[
0
];
$this
->
assertEquals
(
5
,
$valueGroup
->
getNumFound
());
$docs
=
$valueGroup
->
getDocuments
();
$this
->
assertEquals
(
'fun'
,
$docs
[
0
]
->
name
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment