|
FacetService
Represents a store's facet service.
Autogenerated note: this page is automatically generated from embedded documentation in the PHP source. OverviewRepresents a store's facet service. You use it in the usual way. Either indirectly via the Store: $store = new Store("http://api.talis.com/stores/mystore");
$fs = $store->get_facet_service();
Or directly if you know its URI: $fs = new FacetService("http://api.talis.com/stores/mystore/service/facet");
Using the FacetService class is pretty simple: just call the facets method passing in the query, an array of fields to facet on and optionally the number of terms to return for each facet. As usual this method returns an HttpResponse: $response = $fs->facets('query', array('field1','field2'));
if ($response->is_success()) {
// do something useful
}
else {
// mummy...
}
You can parse the XML response using the parse_facet_xml method which returns a nested array of data representing the facet data: array (
'field1' => array (
0 => array ( 'value' => 'term1', 'number' => '5' ),
1 => array ( 'value' => 'term2', 'number' => '4' ),
1 => array ( 'value' => 'term3', 'number' => '2' ),
),
'field2' => array (
0 => array ( 'value' => 'term4', 'number' => '5' ),
1 => array ( 'value' => 'term5', 'number' => '4' ),
1 => array ( 'value' => 'term6', 'number' => '2' ),
),
)
If you like living dangerously then you can combine both the previous steps into one using facets_to_array. If an error occurs this method simply returns an empty array: $facets = $fs->facets_to_array('query', array('field1','field2'));
Constructors
Methods
Constructor DetailFacetServicepublic FacetService(mixed uri, mixed credentials, mixed request_factory) Create a new instance of this class
Method Detailfacetspublic void facets(mixed query, mixed fields, mixed top) Perform a facet query
facets_to_arraypublic void facets_to_array(mixed query, mixed fields, mixed top) Perform a facet query and return the results as an array. An empty array is returned if there are any HTTP errors.
make_facet_uripublic void make_facet_uri(mixed query, mixed fields, mixed top) parse_facet_xmlpublic void parse_facet_xml(mixed xml) Parse the response from a facet query into an array. This method returns an associative array where the keys correspond to field name and the values are associative arrays with two keys:
Generated by PHPDoctor 2RC2 | |