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
558d81ee
Commit
558d81ee
authored
Jan 03, 2013
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for pivot facet
parent
05cea9ed
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
864 additions
and
5 deletions
+864
-5
examples/2.1.5.1.5-facet-pivot.php
examples/2.1.5.1.5-facet-pivot.php
+60
-0
examples/index.html
examples/index.html
+1
-0
library/Solarium/QueryType/Select/Query/Component/Facet/Pivot.php
...Solarium/QueryType/Select/Query/Component/Facet/Pivot.php
+192
-0
library/Solarium/QueryType/Select/Query/Component/FacetSet.php
...ry/Solarium/QueryType/Select/Query/Component/FacetSet.php
+18
-0
library/Solarium/QueryType/Select/RequestBuilder/Component/FacetSet.php
...um/QueryType/Select/RequestBuilder/Component/FacetSet.php
+17
-0
library/Solarium/QueryType/Select/ResponseParser/Component/FacetSet.php
...um/QueryType/Select/ResponseParser/Component/FacetSet.php
+29
-1
library/Solarium/QueryType/Select/Result/Facet/Pivot/Pivot.php
...ry/Solarium/QueryType/Select/Result/Facet/Pivot/Pivot.php
+97
-0
library/Solarium/QueryType/Select/Result/Facet/Pivot/PivotItem.php
...olarium/QueryType/Select/Result/Facet/Pivot/PivotItem.php
+117
-0
tests/Solarium/Tests/QueryType/Select/Query/Component/Facet/PivotTest.php
...ests/QueryType/Select/Query/Component/Facet/PivotTest.php
+116
-0
tests/Solarium/Tests/QueryType/Select/Query/Component/FacetSetTest.php
...m/Tests/QueryType/Select/Query/Component/FacetSetTest.php
+15
-0
tests/Solarium/Tests/QueryType/Select/RequestBuilder/Component/FacetSetTest.php
...ueryType/Select/RequestBuilder/Component/FacetSetTest.php
+24
-0
tests/Solarium/Tests/QueryType/Select/ResponseParser/Component/FacetSetTest.php
...ueryType/Select/ResponseParser/Component/FacetSetTest.php
+41
-4
tests/Solarium/Tests/QueryType/Select/Result/Facet/Pivot/PivotItemTest.php
...sts/QueryType/Select/Result/Facet/Pivot/PivotItemTest.php
+73
-0
tests/Solarium/Tests/QueryType/Select/Result/Facet/Pivot/PivotTest.php
...m/Tests/QueryType/Select/Result/Facet/Pivot/PivotTest.php
+64
-0
No files found.
examples/2.1.5.1.5-facet-pivot.php
0 → 100644
View file @
558d81ee
<?php
require
(
__DIR__
.
'/init.php'
);
htmlHeader
();
// create a client instance
$client
=
new
Solarium\Client
(
$config
);
// get a select query instance
$query
=
$client
->
createSelect
();
// get the facetset component
$facetSet
=
$query
->
getFacetSet
();
// create two facet pivot instances
$facet
=
$facetSet
->
createFacetPivot
(
'cat-popularity-instock'
);
$facet
->
addFields
(
'cat,popularity,inStock'
);
$facet
->
setMinCount
(
0
);
$facet
=
$facetSet
->
createFacetPivot
(
'popularity-cat'
);
$facet
->
addFields
(
'popularity,cat'
);
// this executes the query and returns the result
$resultset
=
$client
->
select
(
$query
);
// display the total number of documents found by solr
echo
'NumFound: '
.
$resultset
->
getNumFound
();
// display facet results
$facetResult
=
$resultset
->
getFacetSet
()
->
getFacet
(
'cat-popularity-instock'
);
echo
'<h3>cat » popularity » instock</h3>'
;
foreach
(
$facetResult
as
$pivot
){
display_pivot_facet
(
$pivot
);
}
$facetResult
=
$resultset
->
getFacetSet
()
->
getFacet
(
'popularity-cat'
);
echo
'<h3>popularity » cat</h3>'
;
foreach
(
$facetResult
as
$pivot
){
display_pivot_facet
(
$pivot
);
}
htmlFooter
();
/**
* Recursively render pivot facets
*
* @param $pivot
*/
function
display_pivot_facet
(
$pivot
)
{
echo
'<ul>'
;
echo
'<li>Field: '
.
$pivot
->
getField
()
.
'</li>'
;
echo
'<li>Value: '
.
$pivot
->
getValue
()
.
'</li>'
;
echo
'<li>Count: '
.
$pivot
->
getCount
()
.
'</li>'
;
foreach
(
$pivot
->
getPivot
()
as
$nextPivot
)
{
display_pivot_facet
(
$nextPivot
);
}
echo
'</ul>'
;
}
\ No newline at end of file
examples/index.html
View file @
558d81ee
...
...
@@ -41,6 +41,7 @@
<li><a
href=
"2.1.5.1.2-facet-query.php"
>
2.1.5.1.2 Facet query
</a></li>
<li><a
href=
"2.1.5.1.3-facet-multiquery.php"
>
2.1.5.1.3 Facet multiquery
</a></li>
<li><a
href=
"2.1.5.1.4-facet-range.php"
>
2.1.5.1.4 Facet range
</a></li>
<li><a
href=
"2.1.5.1.5-facet-pivot.php"
>
2.1.5.1.5 Facet pivot
</a></li>
</ul>
<li><a
href=
"2.1.5.2-morelikethis.php"
>
2.1.5.2 MoreLikeThis
</a></li>
<li><a
href=
"2.1.5.3-highlighting.php"
>
2.1.5.3 Highlighting
</a></li>
...
...
library/Solarium/QueryType/Select/Query/Component/Facet/Pivot.php
0 → 100644
View file @
558d81ee
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace
Solarium\QueryType\Select\Query\Component\Facet
;
use
Solarium\QueryType\Select\Query\Component\FacetSet
;
/**
* Facet pivot
*
* @link http://wiki.apache.org/solr/SimpleFacetParameters#Pivot_.28ie_Decision_Tree.29_Faceting
*/
class
Pivot
extends
Facet
{
/**
* Fields to use
*
* @var array
*/
protected
$fields
=
array
();
/**
* Initialize options
*
* @return void
*/
protected
function
init
()
{
foreach
(
$this
->
options
as
$name
=>
$value
)
{
switch
(
$name
)
{
case
'fields'
:
$this
->
addFields
(
$value
);
break
;
}
}
}
/**
* Get the facet type
*
* @return string
*/
public
function
getType
()
{
return
FacetSet
::
FACET_PIVOT
;
}
/**
* Set the facet mincount
*
* @param int $minCount
* @return self Provides fluent interface
*/
public
function
setMinCount
(
$minCount
)
{
return
$this
->
setOption
(
'mincount'
,
$minCount
);
}
/**
* Get the facet mincount
*
* @return int
*/
public
function
getMinCount
()
{
return
$this
->
getOption
(
'mincount'
);
}
/**
* Specify a field to return in the resultset
*
* @param string $field
* @return self Provides fluent interface
*/
public
function
addField
(
$field
)
{
$this
->
fields
[
$field
]
=
true
;
return
$this
;
}
/**
* Specify multiple fields to return in the resultset
*
* @param string|array $fields can be an array or string with comma
* separated fieldnames
*
* @return self Provides fluent interface
*/
public
function
addFields
(
$fields
)
{
if
(
is_string
(
$fields
))
{
$fields
=
explode
(
','
,
$fields
);
$fields
=
array_map
(
'trim'
,
$fields
);
}
foreach
(
$fields
as
$field
)
{
$this
->
addField
(
$field
);
}
return
$this
;
}
/**
* Remove a field from the field list
*
* @param string $field
* @return self Provides fluent interface
*/
public
function
removeField
(
$field
)
{
if
(
isset
(
$this
->
fields
[
$field
]))
{
unset
(
$this
->
fields
[
$field
]);
}
return
$this
;
}
/**
* Remove all fields from the field list.
*
* @return self Provides fluent interface
*/
public
function
clearFields
()
{
$this
->
fields
=
array
();
return
$this
;
}
/**
* Get the list of fields
*
* @return array
*/
public
function
getFields
()
{
return
array_keys
(
$this
->
fields
);
}
/**
* Set multiple fields
*
* This overwrites any existing fields
*
* @param array $fields
* @return self Provides fluent interface
*/
public
function
setFields
(
$fields
)
{
$this
->
clearFields
();
$this
->
addFields
(
$fields
);
return
$this
;
}
}
library/Solarium/QueryType/Select/Query/Component/FacetSet.php
View file @
558d81ee
...
...
@@ -72,6 +72,11 @@ class FacetSet extends Component
*/
const
FACET_RANGE
=
'range'
;
/**
* Facet type pivot
*/
const
FACET_PIVOT
=
'pivot'
;
/**
* Facet type mapping
*
...
...
@@ -82,6 +87,7 @@ class FacetSet extends Component
self
::
FACET_QUERY
=>
'Solarium\QueryType\Select\Query\Component\Facet\Query'
,
self
::
FACET_MULTIQUERY
=>
'Solarium\QueryType\Select\Query\Component\Facet\MultiQuery'
,
self
::
FACET_RANGE
=>
'Solarium\QueryType\Select\Query\Component\Facet\Range'
,
self
::
FACET_PIVOT
=>
'Solarium\QueryType\Select\Query\Component\Facet\Pivot'
,
);
/**
...
...
@@ -508,4 +514,16 @@ class FacetSet extends Component
return
$this
->
createFacet
(
self
::
FACET_RANGE
,
$options
,
$add
);
}
/**
* Get a facet pivot instance
*
* @param mixed $options
* @param bool $add
* @return Facet\Pivot
*/
public
function
createFacetPivot
(
$options
=
null
,
$add
=
true
)
{
return
$this
->
createFacet
(
self
::
FACET_PIVOT
,
$options
,
$add
);
}
}
library/Solarium/QueryType/Select/RequestBuilder/Component/FacetSet.php
View file @
558d81ee
...
...
@@ -44,6 +44,7 @@ use Solarium\QueryType\Select\Query\Component\Facet\Field as FacetField;
use
Solarium\QueryType\Select\Query\Component\Facet\MultiQuery
as
FacetMultiQuery
;
use
Solarium\QueryType\Select\Query\Component\Facet\Query
as
FacetQuery
;
use
Solarium\QueryType\Select\Query\Component\Facet\Range
as
FacetRange
;
use
Solarium\QueryType\Select\Query\Component\Facet\Pivot
as
FacetPivot
;
use
Solarium\Exception\UnexpectedValueException
;
/**
...
...
@@ -89,6 +90,9 @@ class FacetSet extends RequestBuilder implements ComponentRequestBuilderInterfac
case
FacetsetComponent
::
FACET_RANGE
:
$this
->
addFacetRange
(
$request
,
$facet
);
break
;
case
FacetsetComponent
::
FACET_PIVOT
:
$this
->
addFacetPivot
(
$request
,
$facet
);
break
;
default
:
throw
new
UnexpectedValueException
(
'Unknown facet type'
);
}
...
...
@@ -190,4 +194,17 @@ class FacetSet extends RequestBuilder implements ComponentRequestBuilderInterfac
$request
->
addParam
(
"f.
$field
.facet.range.include"
,
$includeValue
);
}
}
/**
* Add params for a range facet to request
*
* @param Request $request
* @param FacetPivot $facet
* @return void
*/
public
function
addFacetPivot
(
$request
,
$facet
)
{
$request
->
addParam
(
'facet.pivot'
,
implode
(
','
,
$facet
->
getFields
()));
$request
->
addParam
(
'facet.pivot.mincount'
,
$facet
->
getMinCount
(),
true
);
}
}
library/Solarium/QueryType/Select/ResponseParser/Component/FacetSet.php
View file @
558d81ee
...
...
@@ -43,11 +43,13 @@ use Solarium\QueryType\Select\Query\Component\Facet\Field as QueryFacetField;
use
Solarium\QueryType\Select\Query\Component\Facet\Query
as
QueryFacetQuery
;
use
Solarium\QueryType\Select\Query\Component\Facet\MultiQuery
as
QueryFacetMultiQuery
;
use
Solarium\QueryType\Select\Query\Component\Facet\Range
as
QueryFacetRange
;
use
Solarium\QueryType\Select\Query\Component\Facet\Pivot
as
QueryFacetPivot
;
use
Solarium\QueryType\Select\Result\FacetSet
as
ResultFacetSet
;
use
Solarium\QueryType\Select\Result\Facet\Field
as
ResultFacetField
;
use
Solarium\QueryType\Select\Result\Facet\Query
as
ResultFacetQuery
;
use
Solarium\QueryType\Select\Result\Facet\MultiQuery
as
ResultFacetMultiQuery
;
use
Solarium\QueryType\Select\Result\Facet\Range
as
ResultFacetRange
;
use
Solarium\QueryType\Select\Result\Facet\Pivot\Pivot
as
ResultFacetPivot
;
use
Solarium\Exception\RuntimeException
;
use
Solarium\Core\Query\ResponseParser
as
ResponseParserAbstract
;
...
...
@@ -81,9 +83,15 @@ class FacetSet extends ResponseParserAbstract implements ComponentParserInterfac
case
'facet_ranges'
:
$method
=
'createFacetRange'
;
break
;
case
'facet_pivot'
:
$method
=
'createFacetPivot'
;
break
;
}
foreach
(
$facets
as
$k
=>
$facet
)
{
$facetSet
->
$method
(
$k
);
$facetObject
=
$facetSet
->
$method
(
$k
);
if
(
$key
==
'facet_pivot'
)
{
$facetObject
->
setFields
(
$k
);
}
}
}
}
...
...
@@ -104,6 +112,9 @@ class FacetSet extends ResponseParserAbstract implements ComponentParserInterfac
case
QueryFacetSet
::
FACET_RANGE
:
$result
=
$this
->
facetRange
(
$query
,
$facet
,
$data
);
break
;
case
QueryFacetSet
::
FACET_PIVOT
:
$result
=
$this
->
facetPivot
(
$query
,
$facet
,
$data
);
break
;
default
:
throw
new
RuntimeException
(
'Unknown facet type'
);
}
...
...
@@ -218,4 +229,21 @@ class FacetSet extends ResponseParserAbstract implements ComponentParserInterfac
}
}
/**
* Add a facet result for a range facet
*
* @param Query $query
* @param QueryFacetPivot $facet
* @param array $data
* @return ResultFacetPivot
*/
protected
function
facetPivot
(
$query
,
$facet
,
$data
)
{
$key
=
implode
(
','
,
$facet
->
getFields
());
if
(
isset
(
$data
[
'facet_counts'
][
'facet_pivot'
][
$key
]))
{
$data
=
$data
[
'facet_counts'
][
'facet_pivot'
][
$key
];
return
new
ResultFacetPivot
(
$data
);
}
}
}
library/Solarium/QueryType/Select/Result/Facet/Pivot/Pivot.php
0 → 100644
View file @
558d81ee
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace
Solarium\QueryType\Select\Result\Facet\Pivot
;
/**
* Select field pivot result
*
*/
class
Pivot
implements
\IteratorAggregate
,
\Countable
{
/**
* Value array
*
* @var array
*/
protected
$pivot
=
array
();
/**
* Constructor
*
* @param array $data
* @return void
*/
public
function
__construct
(
$data
)
{
foreach
(
$data
as
$pivotData
)
{
$this
->
pivot
[]
=
new
PivotItem
(
$pivotData
);
}
}
/**
* Get pivot results
*
* @return Pivot[]
*/
public
function
getPivot
()
{
return
$this
->
pivot
;
}
/**
* IteratorAggregate implementation
*
* @return \ArrayIterator
*/
public
function
getIterator
()
{
return
new
\ArrayIterator
(
$this
->
pivot
);
}
/**
* Countable implementation
*
* @return int
*/
public
function
count
()
{
return
count
(
$this
->
pivot
);
}
}
library/Solarium/QueryType/Select/Result/Facet/Pivot/PivotItem.php
0 → 100644
View file @
558d81ee
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace
Solarium\QueryType\Select\Result\Facet\Pivot
;
/**
* Select field pivot result
*
*/
class
PivotItem
extends
Pivot
{
/**
* Field name
*
* @var string
*/
protected
$field
;
/**
* Field value
*
* @var mixed
*/
protected
$value
;
/**
* Count
*
* @var int
*/
protected
$count
;
/**
* Constructor
*
* @param array $data
* @return void
*/
public
function
__construct
(
$data
)
{
$this
->
field
=
$data
[
'field'
];
$this
->
value
=
$data
[
'value'
];
$this
->
count
=
$data
[
'count'
];
if
(
isset
(
$data
[
'pivot'
]))
{
foreach
(
$data
[
'pivot'
]
as
$pivotData
)
{
$this
->
pivot
[]
=
new
PivotItem
(
$pivotData
);
}
}
}
/**
* Get field name
*
* @return string
*/
public
function
getField
()
{
return
$this
->
field
;
}
/**
* Get field value
*
* @return mixed
*/
public
function
getValue
()
{
return
$this
->
value
;
}
/**
* Get count
*
* @return int
*/
public
function
getCount
()
{
return
$this
->
count
;
}
}
tests/Solarium/Tests/QueryType/Select/Query/Component/Facet/PivotTest.php
0 → 100644
View file @
558d81ee
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
namespace
Solarium\Tests\QueryType\Select\Query\Component\Facet
;
use
Solarium\QueryType\Select\Query\Component\Facet\Pivot
;
use
Solarium\QueryType\Select\Query\Component\FacetSet
;
class
PivotTest
extends
\PHPUnit_Framework_TestCase
{
/**
* @var Pivot
*/
protected
$facet
;
public
function
setUp
()
{
$this
->
facet
=
new
Pivot
;
}
public
function
testConfigMode
()
{
$options
=
array
(
'fields'
=>
array
(
'abc'
,
'def'
),
'mincount'
=>
5
,
);
$this
->
facet
->
setOptions
(
$options
);
$this
->
assertEquals
(
$options
[
'fields'
],
$this
->
facet
->
getFields
());
$this
->
assertEquals
(
$options
[
'mincount'
],
$this
->
facet
->
getMinCount
());
}
public
function
testGetType
()
{
$this
->
assertEquals
(
FacetSet
::
FACET_PIVOT
,
$this
->
facet
->
getType
()
);
}
public
function
testAddField
()
{
$expectedFields
=
$this
->
facet
->
getFields
();
$expectedFields
[]
=
'newfield'
;
$this
->
facet
->
addField
(
'newfield'
);
$this
->
assertEquals
(
$expectedFields
,
$this
->
facet
->
getFields
());
}
public
function
testClearFields
()
{
$this
->
facet
->
addField
(
'newfield'
);
$this
->
facet
->
clearFields
();
$this
->
assertEquals
(
array
(),
$this
->
facet
->
getFields
());
}
public
function
testAddFields
()
{
$fields
=
array
(
'field1'
,
'field2'
);
$this
->
facet
->
clearFields
();
$this
->
facet
->
addFields
(
$fields
);
$this
->
assertEquals
(
$fields
,
$this
->
facet
->
getFields
());
}
public
function
testAddFieldsAsStringWithTrim
()
{
$this
->
facet
->
clearFields
();
$this
->
facet
->
addFields
(
'field1, field2'
);
$this
->
assertEquals
(
array
(
'field1'
,
'field2'
),
$this
->
facet
->
getFields
());
}
public
function
testRemoveField
()
{
$this
->
facet
->
clearFields
();
$this
->
facet
->
addFields
(
array
(
'field1'
,
'field2'
));
$this
->
facet
->
removeField
(
'field1'
);
$this
->
assertEquals
(
array
(
'field2'
),
$this
->
facet
->
getFields
());
}
public
function
testSetFields
()
{
$this
->
facet
->
clearFields
();
$this
->
facet
->
addFields
(
array
(
'field1'
,
'field2'
));
$this
->
facet
->
setFields
(
array
(
'field3'
,
'field4'
));
$this
->
assertEquals
(
array
(
'field3'
,
'field4'
),
$this
->
facet
->
getFields
());
}
}
tests/Solarium/Tests/QueryType/Select/Query/Component/FacetSetTest.php
View file @
558d81ee
...
...
@@ -403,6 +403,21 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$observer
->
createFacetRange
(
$options
,
$add
);
}
/**
* @dataProvider createFacetAddProvider
*/
public
function
testCreateFacetPivot
(
$add
)
{
$options
=
array
(
'optionA'
=>
1
,
'optionB'
=>
2
);
$observer
=
$this
->
getMock
(
'Solarium\QueryType\Select\Query\Component\FacetSet'
,
array
(
'createFacet'
));
$observer
->
expects
(
$this
->
once
())
->
method
(
'createFacet'
)
->
with
(
$this
->
equalTo
(
FacetSet
::
FACET_PIVOT
),
$this
->
equalTo
(
$options
),
$add
);
$observer
->
createFacetPivot
(
$options
,
$add
);
}
public
function
testSetAndGetExtractFromResponse
()
{
$this
->
facetSet
->
setExtractFromResponse
(
true
);
...
...
tests/Solarium/Tests/QueryType/Select/RequestBuilder/Component/FacetSetTest.php
View file @
558d81ee
...
...
@@ -37,6 +37,7 @@ use Solarium\QueryType\Select\Query\Component\Facet\Field as FacetField;
use
Solarium\QueryType\Select\Query\Component\Facet\Query
as
FacetQuery
;
use
Solarium\QueryType\Select\Query\Component\Facet\MultiQuery
as
FacetMultiQuery
;
use
Solarium\QueryType\Select\Query\Component\Facet\Range
as
FacetRange
;
use
Solarium\QueryType\Select\Query\Component\Facet\Pivot
as
FacetPivot
;
class
FacetSetTest
extends
\PHPUnit_Framework_TestCase
{
...
...
@@ -174,6 +175,29 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$request
->
getUri
();
}
public
function
testBuildWithPivotFacet
()
{
$this
->
component
->
addFacet
(
new
FacetPivot
(
array
(
'key'
=>
'f1'
,
'fields'
=>
'cat,inStock'
,
'mincount'
=>
123
)
));
$request
=
$this
->
builder
->
buildComponent
(
$this
->
component
,
$this
->
request
);
$this
->
assertEquals
(
null
,
$request
->
getRawData
()
);
$this
->
assertEquals
(
'?facet=true&facet.pivot=cat,inStock&facet.pivot.mincount=123'
,
urldecode
(
$request
->
getUri
())
);
}
}
class
UnknownFacet
extends
FacetField
...
...
tests/Solarium/Tests/QueryType/Select/ResponseParser/Component/FacetSetTest.php
View file @
558d81ee
...
...
@@ -48,6 +48,7 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$this
->
facetSet
->
createFacet
(
'query'
,
array
(
'key'
=>
'keyB'
));
$this
->
facetSet
->
createFacet
(
'multiquery'
,
array
(
'key'
=>
'keyC'
,
'query'
=>
array
(
'keyC_A'
=>
array
(
'query'
=>
'id:1'
),
'keyC_B'
=>
array
(
'query'
=>
'id:2'
))));
$this
->
facetSet
->
createFacet
(
'range'
,
array
(
'key'
=>
'keyD'
));
$this
->
facetSet
->
createFacet
(
'pivot'
,
array
(
'key'
=>
'keyE'
,
'fields'
=>
'cat,price'
));
$this
->
query
=
new
Query
;
}
...
...
@@ -83,14 +84,27 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
1
,
)
)
)
),
'facet_pivot'
=>
array
(
'cat,price'
=>
array
(
array
(
'field'
=>
'cat'
,
'value'
=>
'abc'
,
'count'
=>
'123'
,
'pivot'
=>
array
(
array
(
'field'
=>
'price'
,
'value'
=>
1
,
'count'
=>
12
),
array
(
'field'
=>
'price'
,
'value'
=>
2
,
'count'
=>
8
),
)
)
),
),
)
);
$result
=
$this
->
parser
->
parse
(
$this
->
query
,
$this
->
facetSet
,
$data
);
$facets
=
$result
->
getFacets
();
$this
->
assertEquals
(
array
(
'keyA'
,
'keyB'
,
'keyC'
,
'keyD'
),
array_keys
(
$facets
));
$this
->
assertEquals
(
array
(
'keyA'
,
'keyB'
,
'keyC'
,
'keyD'
,
'keyE'
),
array_keys
(
$facets
));
$this
->
assertEquals
(
array
(
'value1'
=>
12
,
'value2'
=>
3
),
...
...
@@ -127,6 +141,11 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$facets
[
'keyD'
]
->
getAfter
()
);
$this
->
assertEquals
(
1
,
count
(
$facets
[
'keyE'
])
);
$this
->
query
=
new
Query
;
}
...
...
@@ -161,7 +180,20 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
1
,
)
)
)
),
'facet_pivot'
=>
array
(
'cat,price'
=>
array
(
array
(
'field'
=>
'cat'
,
'value'
=>
'abc'
,
'count'
=>
'123'
,
'pivot'
=>
array
(
array
(
'field'
=>
'price'
,
'value'
=>
1
,
'count'
=>
12
),
array
(
'field'
=>
'price'
,
'value'
=>
2
,
'count'
=>
8
),
)
)
),
),
)
);
...
...
@@ -171,7 +203,7 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$result
=
$this
->
parser
->
parse
(
$this
->
query
,
$facetSet
,
$data
);
$facets
=
$result
->
getFacets
();
$this
->
assertEquals
(
array
(
'keyA'
,
'keyB'
,
'keyC_A'
,
'keyC_B'
,
'keyD'
),
array_keys
(
$facets
));
$this
->
assertEquals
(
array
(
'keyA'
,
'keyB'
,
'keyC_A'
,
'keyC_B'
,
'keyD'
,
'cat,price'
),
array_keys
(
$facets
));
$this
->
assertEquals
(
array
(
'value1'
=>
12
,
'value2'
=>
3
),
...
...
@@ -214,6 +246,11 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$facets
[
'keyD'
]
->
getAfter
()
);
$this
->
assertEquals
(
1
,
count
(
$facets
[
'cat,price'
])
);
$this
->
query
=
new
Query
;
}
...
...
tests/Solarium/Tests/QueryType/Select/Result/Facet/Pivot/PivotItemTest.php
0 → 100644
View file @
558d81ee
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
namespace
Solarium\Tests\QueryType\Select\Result\Facet\Pivot
;
use
Solarium\QueryType\Select\Result\Facet\Pivot\PivotItem
;
class
PivotItemTest
extends
\PHPUnit_Framework_TestCase
{
protected
$values
,
$pivotItem
;
public
function
setUp
()
{
$this
->
values
=
array
(
'field'
=>
'cat'
,
'value'
=>
'abc'
,
'count'
=>
'123'
,
'pivot'
=>
array
(
array
(
'field'
=>
'cat'
,
'value'
=>
1
,
'count'
=>
12
),
array
(
'field'
=>
'cat'
,
'value'
=>
2
,
'count'
=>
8
),
)
);
$this
->
pivotItem
=
new
PivotItem
(
$this
->
values
);
}
public
function
testGetField
()
{
$this
->
assertEquals
(
$this
->
values
[
'field'
],
$this
->
pivotItem
->
getField
());
}
public
function
testGetValue
()
{
$this
->
assertEquals
(
$this
->
values
[
'value'
],
$this
->
pivotItem
->
getValue
());
}
public
function
testGetCount
()
{
$this
->
assertEquals
(
$this
->
values
[
'count'
],
$this
->
pivotItem
->
getCount
());
}
public
function
testCount
()
{
$this
->
assertEquals
(
count
(
$this
->
values
[
'pivot'
]),
count
(
$this
->
pivotItem
));
}
}
tests/Solarium/Tests/QueryType/Select/Result/Facet/Pivot/PivotTest.php
0 → 100644
View file @
558d81ee
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
namespace
Solarium\Tests\QueryType\Select\Result\Facet\Pivot
;
use
Solarium\QueryType\Select\Result\Facet\Pivot\Pivot
;
use
Solarium\QueryType\Select\Result\Facet\Pivot\PivotItem
;
class
PivotTest
extends
\PHPUnit_Framework_TestCase
{
protected
$values
,
$facet
;
public
function
setUp
()
{
$this
->
values
=
array
(
array
(
'field'
=>
'cat'
,
'value'
=>
1
,
'count'
=>
12
),
array
(
'field'
=>
'cat'
,
'value'
=>
2
,
'count'
=>
8
),
);
$this
->
facet
=
new
Pivot
(
$this
->
values
);
}
public
function
testGetPivot
()
{
$expected
=
array
(
new
PivotItem
(
$this
->
values
[
0
]),
new
PivotItem
(
$this
->
values
[
1
]),
);
$this
->
assertEquals
(
$expected
,
$this
->
facet
->
getPivot
());
}
public
function
testCount
()
{
$this
->
assertEquals
(
count
(
$this
->
values
),
count
(
$this
->
facet
));
}
}
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