Skip to content

Commit

Permalink
Merge pull request #1 from uofa/WEB-1928-funnelback-upgrade
Browse files Browse the repository at this point in the history
Funnelback Upgrade - Access Facet Definition
  • Loading branch information
darrencoutts118 authored Jun 13, 2024
2 parents 727bd5a + 7538894 commit 7201669
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Funnelback/Facet.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct($facet_data)
{
$this->facetData = $facet_data;
$this->name = $facet_data['name'];
$this->facetItems = (!empty($facet_data['categories'])) ? $this->buildFacetItems($facet_data['categories'][0]['values']) : [];
$this->facetItems = (!empty($facet_data['allValues'])) ? $this->buildFacetItems($facet_data['allValues']) : [];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Funnelback/FacetItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct($facet_item_data)
$this->facetItemData = $facet_item_data;
$this->label = $facet_item_data['label'];
$this->count = $facet_item_data['count'];
$this->queryStringParam = $facet_item_data['queryStringParam'];
$this->queryStringParam = null;
}

/**
Expand Down
39 changes: 39 additions & 0 deletions src/Funnelback/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ class Response
*/
protected $facets;

/**
* The facets definitions.
*
* @var array
*/
protected $facetDefinitions;

/**
* The result summary.
*
Expand Down Expand Up @@ -97,6 +104,10 @@ public function __construct(ResponseInterface $http_response)
$this->results = $this->buildResults($result_packet['results']);
$this->facets = $this->buildFacets($response['facets']);
$this->spelling = $result_packet['spell'];

$profiles = $this->responseJson['question']['collection']['profiles'];
$profileName = array_keys($profiles)[0];
$this->facetDefinitions = $this->buildFacetDefinitions($profiles[$profileName]['facetedNavConfConfig']['facetDefinitions']);
}

/**
Expand Down Expand Up @@ -143,6 +154,16 @@ public function getFacets()
return $this->facets;
}

/**
* Get the facet definitions
*
* @return array
*/
public function getFacetDefinitions()
{
return $this->facetDefinitions;
}

/**
* Gets the best bets.
*
Expand Down Expand Up @@ -221,4 +242,22 @@ protected function buildFacets($facets_data)
}
return $facets;
}

/**
* Builds a list of facet metadata.
*
* @param array $facets_data
* The raw facet data.
*
* @return array
* A list of facet metadata
*/
protected function buildFacetDefinitions($facets_data)
{
$facets = [];
foreach ($facets_data as $facet_data) {
$facets[$facet_data['name']] = $facet_data;
}
return $facets;
}
}

0 comments on commit 7201669

Please sign in to comment.