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

Table of Contents

Introduction

This page introduces filter expressions. They are usefull to define AFS search engine queries.

Simple filter expressions

To filter on specific facet value, one must define following elements:

These elements must be defined in this order and none can be omitted.

Filter identifier

Filter identifier is created using the helper function filter(). It is also possible to create it using other method which is detailled later (see Combine simple filter expressions).

For example, you can define a filter on the categorie identified by MATERIAL as following:

filter('MATERIAL')

Filter operators

Operators must be used on filter identifiers. One operator, and only one, can be applied to one defined filter identifier.

Operators define the way provided facet values are compared with values defined by each document/product.

Standard operators are available. Here is the list of all available operators:

Here are examples for some of the operators:

filter('MATERIAL')->equal
filter('PRICE')->less_equal

Filter value

Values must be defined on filter operators. One value, and only one, can be applied to one filter operator.

Allowed value types are:

Note
Date values must be defined as string value with appropriate format. See Date format for more details.

Here are examples of AFS search engine filter definitions along with their corresponding expressions:

Advanced filter expressions

Filter expressions, like the ones defined earlier (ID->operator->value), can be combined or grouped in order to build complex filter expressions.

Combine simple filter expressions

Combination should be defined on simple filter expressions or groups (for details on groups, see below Group filter expressions).

Simple filter expressions can be combined in order to make a new filter expression. Two combination types are available:

This is really usefull when you want to filter on multiple values for specific facet. This is also true when you want to build intervals. Here are examples of such conditions:

Group filter expressions

Grouping filter expressions defines priority for combined expressions.

Group expression is created with group() function. Usage example follows:

Special notes

Date format

Date value should match one of the following formats:

with:

For more details on date format and their usage, please refer to AFS search engine documentation.

Example of filter builder

It can happen that one wants to create several filters of the same type. In such case, it may be tedious to write appropriate filter expressions for each filter. So you are encouraged to make your own function to create appropriate filter expressions.

For example, let's suppose you often want to combine multiple values for specific facet identifier. List of facet values can be transfered as array to your specific function. Here is an example of such function:

function myExpressionBuilder($id, array $values)
{
if (empty($values))
return null;
$value = array_shift($values);
$result = filter($id)->equal->value($value);
while (! empty($values))
$result = $result->or->filter($id)->equal->value(array_shift($values));
return $result;
}

Previous function definition will help you build following filter expressions: