Skip to content

Algebraic Logical Query

feiben edited this page May 28, 2017 · 7 revisions

Algebraic Logical Query supports much more complex filter for specific records that satisfying logical relationship. Just as what we define in SQL where clause.

Here is what algebraic logic defines:

e.g. A[  
        O[R[col1, 0, 50, 0,0],  
        R[col2, -1000, 1500, 0,1]],  
        T[col3 against(\"keyword1 + keyword2, keyword3\")],  
        R[col4, 1000, 2000, 1,1]  
      ]  
means:  
(0<col1<50 OR -1000<col2<=1500)  
AND  
("col3 against(\"keyword1 + keyword2, keyword3\")")  
AND  
(1000<=col4<=2000)  

The FORM is one of the following four forms:  
A[node, node, node,....node],  
O[node, node, node,....node],  
R[col, lower, upper, lower_inclisive, upper_inclusive],  
T[statement like: col3 against(\"keyword1 + keyword2\")]  

where A stands for logical AND, O stands for logical OR, R stands for range query with lower and upper bound, 
and T is the fulltext query statement.  
 
nothing more.  

each node is a FORM.  

A SQL statement of WHERE clause can be translated to this form easily:

String exp = "O[R[score,75,98,1,1], R[score, -10000, 50,0,0]]";

stands for such a relationship:

where S.\"score\" between 75 and 98 or S.\"score\" < 50

The interface is:

String table = "sales";
String statement = "A[R[score,75,98,1,1], R[score, -10000, 50,0,0], T[statement like: col3 against(\"keyword1 + keyword2\")]]";
FTQueryResult result_set = db_instance.queryRelational(table, statement);  

Clone this wiki locally