/**
  * Helper method for building hierarchical facets:
  * Convert facet list to a hierarchical array
  *
  * @param string    $facet     Facet name
  * @param array     $facetList Facet list
  * @param UrlHelper $urlHelper Query URL helper for building facet URLs
  *
  * @return array Facet hierarchy
  */
 public function buildFacetArray($facet, $facetList, $urlHelper = false)
 {
     $result = parent::buildFacetArray($facet, $facetList, $urlHelper);
     if ($urlHelper !== false) {
         // Recreate href's for any facet items that have children/ancestors
         // applied to remove them from the filters
         $result = $this->removeAncestorAndChildFilters($facet, $result);
     }
     return $result;
 }
 /**
  * Tests for flattenFacetHierarchy
  */
 public function testFlattenFacetHierarchy()
 {
     $facetList = $this->helper->flattenFacetHierarchy($this->helper->buildFacetArray('format', $this->facetList));
     $this->assertEquals($facetList[0]['value'], '0/Book/');
     $this->assertEquals($facetList[1]['value'], '1/Book/BookPart/');
     $this->assertEquals($facetList[2]['value'], '1/Book/Section/');
     $this->assertEquals($facetList[3]['value'], '0/AV/');
     $this->assertEquals($facetList[4]['value'], '0/Audio/');
     $this->assertEquals($facetList[5]['value'], '1/Audio/Spoken/');
     $this->assertEquals($facetList[6]['value'], '1/Audio/Music/');
 }
Exemple #3
0
 /**
  * Get facet information from the search results.
  *
  * @return array
  * @throws \Exception
  */
 public function getFacetSet()
 {
     $facetSet = $this->results->getFacetList($this->mainFacets);
     foreach ($this->hierarchicalFacets as $hierarchicalFacet) {
         if (isset($facetSet[$hierarchicalFacet])) {
             if (!$this->hierarchicalFacetHelper) {
                 throw new \Exception(get_class($this) . ': hierarchical facet helper unavailable');
             }
             $facetArray = $this->hierarchicalFacetHelper->buildFacetArray($hierarchicalFacet, $facetSet[$hierarchicalFacet]['list']);
             $facetSet[$hierarchicalFacet]['list'] = $this->hierarchicalFacetHelper->flattenFacetHierarchy($facetArray);
         }
     }
     return $facetSet;
 }