Complex filters. EQL language

All filters in ELMA has a Query property. You can use this property to define selection criteria using EQL – ELMA Query Language.

In this article, we provide the description of EQL syntax followed by simple use cases.

EQL syntax

// Separate logic expression
public detachedExpression :
    expression EOF;
 
// Logic expression
expression :
    expression_or;
 
// Logic expression OR
expression_or :
    expression_and (OR expression_and)*
    ;
 
// Logic expression AND
expression_and :
    expression_comp (AND expression_comp)*
    ;
 
// Logic expression for comparison
expression_comp :
    property operator_comp atom
    | NOT expression_comp
    | property IS NULL
    | property IN atom_collection
    | property IN comma_expression
    | property LIKE CHARACTER_STRING
    | LPAREN expression RPAREN //-> PAR_L logicExpression PAR_R
    ;
 
// Comparison operator
operator_comp :
    EQUAL
    | NEQUAL
    | GE
    | GT
    | LE
    | LT
    ;
 
// Collection of atomic expressions
atom_collection :
    LPAREN constant (COMMA constant)* RPAREN
    ;
 
// Bracket expressions
comma_expression :
    LPAREN expression RPAREN
    ;
 
// Atomic expression
atom :
    property
    | constant
    ;
 
// Constant
constant :
    NUMBER
    | CHARACTER_STRING
    | TRUE
    | FALSE
    | constantFunction
    ;
 
// Function result
constantFunction :
    IDENTIFIER LPAREN RPAREN
    | IDENTIFIER atom_collection
    ;
 
// Property
property :
    IDENTIFIER
    ;
 
/*
 * Lexer Rules
 */
 
 
EQUAL :
    ’=’;
 
NEQUAL :
    ’<>’;
 
GE :
    ’>=’;
 
GT :
    ’>’;
 
LE :
    ’<=’;
 
LT :
    ’<’;
 
LPAREN :
    ’(’;
 
RPAREN :
    ’)’;
 
COMMA :
    ’,’;
 
CHARACTER_STRING :
    ( (’\’’ | ’‘’ | ’’’) (’\’\’’ | ’‘‘’ | ’’’’ | ~(’\’’ | ’‘’ | ’’’))* (’\’’ | ’‘’ | ’’’) );
 
NUMBER :
    ( (’0’..’9’)+ ((’.’) (’0’..’9’)+)? );
 
// Identifier
IDENTIFIER : 
    (Letter (Letter|IDDigit)*) { $type = CheckKeyword($text); } ; 
 
// Ignored symbols
WS :
    (’ ’ | ’\r’ | ’\n’ | ’\t’) { $channel = Hidden; }
    ;

How to create EQL queries?

The query in EQL is a sequence of logical operations connected by AND or OR connectors. To define what operation should be completed first, you can use round brackets (  ). EQL supports the following logical operations: =<>>=><=<LIKEIS NULLIN.

The query can include any property of the object that participates in selection (including user-defined properties and child objects).

You can compare basic properties (e.g. integer, string) with other properties of the same type or with constants (use simple quotes for string constants; use a period to separate integer and fraction parts of numbers).

To add (inverted comma) to a string, you need to repeat it twice: Name like ’%Task ’’1’’%’

If a property is a link to another object, you need to address the ID of this object in EQL: CreationAuthor = 1

If a property is a list, you can work with it using the comparison operators (=, <>, IN): InformTo IN (2,4)

Below are the functions that you can use as constants:

  • CurrentUser()– returns ID of the current user
  • Enum("name of enumeration’s value")– returns ID of the specified enumeration’s value
  • GUID ("unique identifier in string representation")– creates GUID from the string parameter passed to the function
  • DateTime(year, month, day[,hour[,minute[,second[,millisecond]]]])– returns date and time according to the parameters passed to the function
  • Reference(object type ID, object ID)– returns the value of Object Reference type for comparison.

Example of queries

  • Name like ’%Task ’’1’’%’– returns all tasks, where Name property contains Task ‘1’
  • CreationAuthor = 1 – returns all documents that were created by ELMA Administrator user
  • InformTo in (2, 4)– returns all tasks where users with ID=2 or ID=4 are in the list of co-executors
  • CreationDate > DateTime(2016, 8, 5) andCreationAuthorin (CurrentUser(), 2)– returns all tasks that were created after 08/05/2016 00:00 ( if no time specified, then 00:00 is set by default) either by the current user or by the user with ID=2
  • Status in (Enum(’NewOrder’), Enum(’Read’)) orPriority = Enum(’High’)– returns all tasks either with high priority or with the following statuses: New task and Viewed by executor
  • Recipient = CurrentUser() AND Statuses in (Status = Enum(’Read’) AND Recipient = CurrentUser()) – returns all read messages of the current user

See also: