My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
FacetService  
Represents a store's facet service.
Autogenerated
Updated Jan 13, 2010 by innovat...@gmail.com

note: this page is automatically generated from embedded documentation in the PHP source.

Overview

Represents 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'));
 

See:
http://n2.talis.com/wiki/Facet_Service

Constructors

Methods

Constructor Detail

FacetService

public FacetService(mixed uri, mixed credentials, mixed request_factory)

Create a new instance of this class

Param:
string uri URI of the facet service
Credentials credentials the credentials to use for authenticated requests (optional)

Method Detail

facets

public void facets(mixed query, mixed fields, mixed top)

Perform a facet query

Param:
string query the query to execute
array fields the list of fields to facet on
in top the number of facet results to return
Return:
HttpResponse

facets_to_array

public 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.

Param:
string query the query to execute
array fields the list of fields to facet on
in top the number of facet results to return
Return:
array see parse_facet_xml for the structure of this array

make_facet_uri

public void make_facet_uri(mixed query, mixed fields, mixed top)

parse_facet_xml

public 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:

  • value => the value of the field
  • number => the associated number returned by the facet service
Param:
string xml the facet response as an XML document
Return:
array

Generated by PHPDoctor 2RC2


Sign in to add a comment
Powered by Google Project Hosting