![]() |
Antidot PHP API
version 0.16.0
##PHP API to simplify integration of Antidot components
|
This page introduces filter expressions. They are usefull to define AFS search engine queries.
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 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:
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:
equal:
equal to comparison,not_equal:
not equal to comparison,less:
less than comparison,less_equal:
less than or equal to comparison,greater:
greater than comparison,greater_equal:
greater than or equal to comparison.Here are examples for some of the operators:
Values must be defined on filter operators. One value, and only one, can be applied to one filter operator.
Allowed value types are:
string:
it may be a string value surrounded by double quotes ("
) or a string representation of an integer, float, boolean or date value,integer
,float
,boolean
.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:
MATERIAL="copper"
PRICE=42.666
Filter expressions, like the ones defined earlier (ID->operator->value), can be combined or grouped in order to build complex 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:
and:
Filter expressions on both sides of the and
operator must be verified for a document/product to make it appears in AFS search engine reply.or:
At least one filter expression on whichever side of the or
operator must be verified for a document/product to make it appears in AFS search engine reply.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:
MATERIAL="copper" or MATERIAL="gold"
PRICE<=42.666 or PRICE>12.3
Grouping filter expressions defines priority for combined expressions.
Group expression is created with group() function. Usage example follows:
(MATERIAL="copper" and PRICE<42.666) or (MATERIAL="gold" and PRICE<=123.456)
MATERIAL="platinium" or (MATERIAL="gold" and PRICE>345)
Date value should match one of the following formats:
yyyy-MM-dd HH:mm
yyyy-MM-dd HH
yyyy-MM-dd
yyyy-MM
yyyy
with:
yyyy:
represents years,MM:
represents months (with leading 0 when necessary),dd:
represents days (with leading 0 when necessary),HH:
represents hours (with leading 0 when necessary),mm:
represents minutes (with leading 0 when necessary),For more details on date format and their usage, please refer to AFS search engine documentation.
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:
Previous function definition will help you build following filter expressions:
MATERIAL="copper"
MATERIAL="copper" or MATERIAL="silver" or MATERIAL="gold"