Merge pull request #59 from Codappix/feature/add-facet-keys

TASK: Add keys for better access to Facets
This commit is contained in:
Daniel Siepmann 2017-07-27 14:28:37 +02:00 committed by GitHub
commit 441ac7dd84
3 changed files with 5 additions and 5 deletions

View file

@ -87,7 +87,7 @@ class Facet implements FacetInterface
} }
foreach ($this->buckets as $bucket) { foreach ($this->buckets as $bucket) {
$this->options[] = new FacetOption($bucket); $this->options[$bucket['key']] = new FacetOption($bucket);
} }
} }
} }

View file

@ -140,7 +140,7 @@ class SearchResult implements SearchResultInterface
} }
foreach ($this->result->getAggregations() as $aggregationName => $aggregation) { foreach ($this->result->getAggregations() as $aggregationName => $aggregation) {
$this->facets[] = $this->objectManager->get(Facet::class, $aggregationName, $aggregation); $this->facets[$aggregationName] = $this->objectManager->get(Facet::class, $aggregationName, $aggregation);
} }
} }
} }

View file

@ -78,16 +78,16 @@ class FilterTest extends AbstractFunctionalTestCase
$this->assertSame(1, count($result->getFacets()), 'Did not receive the single defined facet.'); $this->assertSame(1, count($result->getFacets()), 'Did not receive the single defined facet.');
$facet = $result->getFacets()[0]; $facet = current($result->getFacets());
$this->assertSame('contentTypes', $facet->getName(), 'Name of facet was not as expected.'); $this->assertSame('contentTypes', $facet->getName(), 'Name of facet was not as expected.');
$this->assertSame('CType', $facet->getField(), 'Field of facet was not expected.'); $this->assertSame('CType', $facet->getField(), 'Field of facet was not expected.');
$options = $facet->getOptions(); $options = $facet->getOptions();
$this->assertSame(2, count($options), 'Did not receive the expected number of possible options for facet.'); $this->assertSame(2, count($options), 'Did not receive the expected number of possible options for facet.');
$option = $options[0]; $option = $options['HTML'];
$this->assertSame('HTML', $option->getName(), 'Option did not have expected Name.'); $this->assertSame('HTML', $option->getName(), 'Option did not have expected Name.');
$this->assertSame(1, $option->getCount(), 'Option did not have expected count.'); $this->assertSame(1, $option->getCount(), 'Option did not have expected count.');
$option = $options[1]; $option = $options['Header'];
$this->assertSame('Header', $option->getName(), 'Option did not have expected Name.'); $this->assertSame('Header', $option->getName(), 'Option did not have expected Name.');
$this->assertSame(1, $option->getCount(), 'Option did not have expected count.'); $this->assertSame(1, $option->getCount(), 'Option did not have expected count.');
} }