Antidot PHP API  version 0.16.0
##PHP API to simplify integration of Antidot components
 All Classes Files Functions Variables Groups Pages
AFS search reply API

Table of Contents

Introduction

This API greatly simplifies treatment of Antidot search engine replies. Main objective here is to add nearly no PHP code and make usage of PHP templates.

Snippets of code are usable as is and can be joined to build a fully functional example step by step. If you prefer you can get access to full code example full_example.php.

If you have not read it yet you can start by reading AFS search query API.

Reponse helper

This is the main helper (see AfsSearchQueryManager for more details). It should be initilized with result of AfsSearchQueryManager::send method, the facet manager, the current query and the query coder (see AFS search query coder/decoder API and AFS search query API for details on these parameters).

Here an example to initialize AFS response helper:

On initialization, error checking is performed. When no error occured, AfsResponseHelper::get_replysets returns a list of AfsReplysetHelper. By the way, following helpers are also initialized:

Spellcheck replies can be retrieved by calling AfsResponseHelper::get_spellchecks, so that new query can be suggested to customer.

Details on each helper are available in their own documentation pages, so from now on only common features will be detailled.

Helper generalities

Here are common main features of the helpers.

Getters

One main feature of helpers is that each getter get_XXX() can also be called like a property of the class.

For example, the two following statements are equivalent:

$helper->get_error_msg();
$helper->error_msg;

This convenient feature can only be used for getters that do not require parameter.

Helper formats

Other main feature of helpers is that they can generate formatted output. In fact, starting from the main helper, you can get access to specialized getters or to formmatted array. This array is made of key/value pairs. Keys correspond to equivalent names of the helper getters. Values correspond to values the helper should have provided by calling corresponding getter.

For example, let's consider an instance of AfsMetaHelper:

Array format is the default format generated when initializing instance of AfsResponseHelper. This format greatly simplifies usage of PHP template engine such as Twig (see full_example.php).

Main drawback of this format is that it does not allow to access all data which are available by using helper format. This is mainly due to client data which are freely formatted and cannot be translated in key-value pairs.

Specific helpers

Here some specific helpers are presented. They are not instanciated directly or indirectly by AfsResponseHelper but they can be really usefull.

Client data helpers

Client data are really specific to each customer. So there is no generic way to integrate them in standard flow of treatments. To help you managing your own data, two kinds of client data helpers are available:

Instances of these classes are generally not created directly. A AfsClientDataManager is provided to generate appropriate client data helpers. Like for AfsReplyHelper, it is initialized with a reply which should contain at least one client data. Then client data can be retrieved by id which has been provided on indexation side. If no id as been provided, it is defaultly set to main.

XML client data can be retrieved by XPath. There is no limitation except that XPath are limited to version 1.0.

JSON client data can be retrieved by array key. Only the first array level is considered. More details are vailable there: AfsJsonClientDataHelper::get_text.

Main common feature of these helpers is that they both manage highlight in client data. Default callbacks are used for highlighted text but specific ones can be defined.

Next step

Full detailled example with template

You are going to find in following link detailled example using PHP template engine. This example explains how to use this API and configure it in order to set up a fully functional integration. But you are advised to consider looking forward and see a more lightweight example in next section.

Detailled example with PHP template engine: Detailled integration example with PHP template engine

Lightweight example with template

If you compare this example with previous one you will nocite that the number of required configuration lines has been greatly reduced. However, same functionnalities are available and there is no difference in produced HTML pages.

Detailled lightweight example with PHP template engine: Lightweight integration example with PHP template engine

Full detailled example without template

Alternate example without template engine is also available: Integration example without PHP template engine