Bitrix Site Manager

Using complex logic in filter

Most system forms display information in the form of report tables. To define the subset of data to be displayed in a form report table, the system provides filters. With filters, a user can provide numeric, textual or other kind of information which is used as the criteria to match against data selected from the database. If the data selected satisfies the provided criteria, it is displayed in the report. Filter is the part of the page body; it is mostly positioned on top of the form.

The following illustration shows the filter of a user web form (partially collapsed for better visibility).

Filter fields marked with ? on the right of the field allow using queries. On the picture above, the following filter fields are enabled with the query language: ID, Status ID, User ID, Visitor ID, Session ID, e-mail.

How to use queries

A query is a logic expression. For example, you want to filter a table with user data by field Name. If you type in the following text:

John & Smith

the output will contain all users having both words in their names, either partially or in full. This query is equivalent to typing these two words separated with a space: John Smith.

If you need to display all users having either John or Smith in their names, you would have to type the following query:

Brown | Smith

In case you need to use the negation, a special logical operator is provided: "~". For example:

(Brown | Smith) & ~John.

This query means to display all users having either Brown or Smith in their names, but not John.

The last query made use of round brackets. The use of brackets is stipulated by the priority of operator | which is lower than that of operator & (see table Logic Operators Priority below). On the other hand, if you do not use round brackets here, this query would mean to display all users having Brown in their names, or users having Smith in their names but not John.

Round brackets can be used to build more complex queries.

In addition to the above described operators, the system provides wildcard operators. For example, you cannot remember the name of a person but sure that the last name starts from Wil and ends with son, while the first name is either Blythe or Blithe. The following query will match these conditions: Wil%son & Bl_the. In this query, symbol % (percent sign) means zero or more symbols, and symbol _ (underscore) means any one symbol.

If you need to include any reserved symbol in the query, enclose the query phrase in single or double quotation marks. For example: "~NICK~" | '&Leon&'. Similarly, if you need to find a phrase containing space(s), enclose it  in single or double quotation marks, for example: "Microsoft Internet Explorer" | 'Netscape Navigator'.

In all cases, the search is not case sensitive.

Query operators

& Logical operator and can be omitted. A query John & Smith is equivalent to John Smith.
| Logical operator or allow searching for records containing at least one of operands.
~ Logical operator not searches for records not containing an operand stated after the operator. Additionally, it negates expression after the operator.
( ) Round brackets define the logical operators precedence.
% Wildcard operator. Means zero or more symbols.
_ Wildcard operator. Means any one symbol.

Logical operators priority

~ 1
& 2
| 3