Skip to content

Commit

Permalink
Merge 74bfbda into b0cecb2
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Kalkbrenner committed Apr 9, 2019
2 parents b0cecb2 + 74bfbda commit c196d1d
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/Component/Facet/FacetInterface.php
Expand Up @@ -3,7 +3,7 @@
namespace Solarium\Component\Facet;

/**
* Facet base class.
* Facet interface.
*
* @see http://wiki.apache.org/solr/SimpleFacetParameters
*/
Expand Down
30 changes: 20 additions & 10 deletions src/Component/FacetSet.php
Expand Up @@ -3,6 +3,16 @@
namespace Solarium\Component;

use Solarium\Component\Facet\FacetInterface;
use Solarium\Component\Facet\Field;
use Solarium\Component\Facet\Interval;
use Solarium\Component\Facet\JsonAggregation;
use Solarium\Component\Facet\JsonQuery;
use Solarium\Component\Facet\JsonRange;
use Solarium\Component\Facet\JsonTerms;
use Solarium\Component\Facet\MultiQuery;
use Solarium\Component\Facet\Pivot;
use Solarium\Component\Facet\Query;
use Solarium\Component\Facet\Range;
use Solarium\Component\RequestBuilder\ComponentRequestBuilderInterface;
use Solarium\Component\RequestBuilder\FacetSet as RequestBuilder;
use Solarium\Component\ResponseParser\ComponentParserInterface;
Expand All @@ -21,16 +31,16 @@ class FacetSet extends AbstractComponent implements FacetSetInterface
* @var array
*/
protected $facetTypes = [
FacetSetInterface::FACET_FIELD => 'Solarium\Component\Facet\Field',
FacetSetInterface::FACET_QUERY => 'Solarium\Component\Facet\Query',
FacetSetInterface::FACET_MULTIQUERY => 'Solarium\Component\Facet\MultiQuery',
FacetSetInterface::FACET_RANGE => 'Solarium\Component\Facet\Range',
FacetSetInterface::FACET_PIVOT => 'Solarium\Component\Facet\Pivot',
FacetSetInterface::FACET_INTERVAL => 'Solarium\Component\Facet\Interval',
FacetSetInterface::JSON_FACET_AGGREGATION => 'Solarium\Component\Facet\JsonAggregation',
FacetSetInterface::JSON_FACET_TERMS => 'Solarium\Component\Facet\JsonTerms',
FacetSetInterface::JSON_FACET_QUERY => 'Solarium\Component\Facet\JsonQuery',
FacetSetInterface::JSON_FACET_RANGE => 'Solarium\Component\Facet\JsonRange',
FacetSetInterface::FACET_FIELD => Field::class,
FacetSetInterface::FACET_QUERY => Query::class,
FacetSetInterface::FACET_MULTIQUERY => MultiQuery::class,
FacetSetInterface::FACET_RANGE => Range::class,
FacetSetInterface::FACET_PIVOT => Pivot::class,
FacetSetInterface::FACET_INTERVAL => Interval::class,
FacetSetInterface::JSON_FACET_AGGREGATION => JsonAggregation::class,
FacetSetInterface::JSON_FACET_TERMS => JsonTerms::class,
FacetSetInterface::JSON_FACET_QUERY => JsonQuery::class,
FacetSetInterface::JSON_FACET_RANGE => JsonRange::class,
];

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Component/Result/Facet/Aggregation.php
Expand Up @@ -5,7 +5,7 @@
/**
* Aggregation.
*/
class Aggregation
class Aggregation implements FacetResultInterface
{
/**
* Value.
Expand Down
2 changes: 1 addition & 1 deletion src/Component/Result/Facet/Buckets.php
Expand Up @@ -9,7 +9,7 @@
* value and its count. You can access the values as an array using
* {@link getValues()} or iterate this object.
*/
class Buckets implements \IteratorAggregate, \Countable
class Buckets implements FacetResultInterface, \IteratorAggregate, \Countable
{
/**
* Value array.
Expand Down
10 changes: 10 additions & 0 deletions src/Component/Result/Facet/FacetResultInterface.php
@@ -0,0 +1,10 @@
<?php

namespace Solarium\Component\Result\Facet;

/**
* Facet result interface.
*/
interface FacetResultInterface
{
}
2 changes: 1 addition & 1 deletion src/Component/Result/Facet/Field.php
Expand Up @@ -9,7 +9,7 @@
* value and its count. You can access the values as an array using
* {@link getValues()} or iterate this object.
*/
class Field implements \IteratorAggregate, \Countable
class Field implements FacetResultInterface, \IteratorAggregate, \Countable
{
/**
* Value array.
Expand Down
4 changes: 3 additions & 1 deletion src/Component/Result/Facet/Pivot/Pivot.php
Expand Up @@ -2,10 +2,12 @@

namespace Solarium\Component\Result\Facet\Pivot;

use Solarium\Component\Result\Facet\FacetResultInterface;

/**
* Select field pivot result.
*/
class Pivot implements \IteratorAggregate, \Countable
class Pivot implements FacetResultInterface, \IteratorAggregate, \Countable
{
/**
* Value array.
Expand Down
2 changes: 1 addition & 1 deletion src/Component/Result/Facet/Query.php
Expand Up @@ -8,7 +8,7 @@
* Since a query facet has only a single result, the count for the query, this
* is a very simple object.
*/
class Query
class Query implements FacetResultInterface
{
/**
* Value (count).
Expand Down
12 changes: 6 additions & 6 deletions src/Component/Result/FacetSet.php
Expand Up @@ -2,7 +2,7 @@

namespace Solarium\Component\Result;

use Solarium\Component\Facet\FacetInterface;
use Solarium\Component\Result\Facet\FacetResultInterface;

/**
* Select component facetset result.
Expand All @@ -12,14 +12,14 @@ class FacetSet implements \IteratorAggregate, \Countable
/**
* Facet array.
*
* @var array
* @var FacetResultInterface[]
*/
protected $facets;

/**
* Constructor.
*
* @param array $facets
* @param FacetResultInterface[] $facets
*/
public function __construct(array $facets)
{
Expand All @@ -31,17 +31,17 @@ public function __construct(array $facets)
*
* @param mixed $key
*
* @return FacetInterface|null
* @return FacetResultInterface|null
*/
public function getFacet($key): ?FacetInterface
public function getFacet($key): ?FacetResultInterface
{
return $this->facets[$key] ?? null;
}

/**
* Get all facet results.
*
* @return array
* @return FacetResultInterface[]
*/
public function getFacets(): array
{
Expand Down
6 changes: 3 additions & 3 deletions tests/Component/ResponseParser/FacetSetTest.php
Expand Up @@ -125,7 +125,7 @@ public function testParse()
$this->assertEquals(5, $facets['keyD']->getAfter());
$this->assertEquals(1, count($facets['keyE']));

$this->query = new Query();
$this->assertEquals(23, $result->getFacet('keyB')->getValue());
}

public function testParseExtractFromResponse()
Expand Down Expand Up @@ -241,8 +241,6 @@ public function testParseExtractFromResponse()
2,
$pivots[0]->getStats()
);

$this->query = new Query();
}

public function testParseNoData()
Expand Down Expand Up @@ -356,5 +354,7 @@ public function testParseJsonFacet()
$this->assertEquals(['top_authors', 'highpop'], array_keys($nested_facets));

$this->assertFalse(isset($facets['empty_buckets']));

$this->assertEquals('Fantasy', $result->getFacet('top_genres')->getBuckets()[0]->getValue());
}
}
3 changes: 2 additions & 1 deletion tests/QueryType/Select/Result/FacetSetTest.php
Expand Up @@ -4,6 +4,7 @@

use PHPUnit\Framework\TestCase;
use Solarium\Component\Facet\AbstractFacet;
use Solarium\Component\Result\Facet\FacetResultInterface;
use Solarium\Component\Result\FacetSet;

class FacetSetTest extends TestCase
Expand Down Expand Up @@ -61,7 +62,7 @@ public function testCount()
}
}

class DummyFacet extends AbstractFacet
class DummyFacet extends AbstractFacet implements FacetResultInterface
{
/**
* Get the facet type.
Expand Down

0 comments on commit c196d1d

Please sign in to comment.