Creating Complex Filters
Example 1 — Using an Explicit Or
The following example generates a composite search filter with Field1 equal to string X or Field2 containing string Y:
import PT_SEARCH:SearchFilterGenerator;
Local PT_SEARCH:SearchFilterGenerator &fg = create PT_SEARCH:SearchFilterGenerator();
&fg.MatchAny();
&fg.EqualsString("Field1", &str_X);
&fg.ContainsWord("Field2", &str_Y);
&fg.EndMatchAny();
&fg.SetQueryFilter(&qry);
See MatchAny method: SearchFilterGenerator class for more information.
Example 2 — Using an Implicit And
The following example generates a composite search filter with Field1 equal to string X and Field2 containing string Y:
import PT_SEARCH:SearchFilterGenerator;
Local PT_SEARCH:SearchFilterGenerator &fg = create PT_SEARCH:SearchFilterGenerator();
/* The & is the default connector; therefore, MatchAll is implied and does not */
/* have to be explicitly specified. */
&fg.EqualsString("Field1", &str_X);
&fg.ContainsWord("Field2", &str_Y);
&fg.SetQueryFilter(&qry);
See MatchAll method: SearchFilterGenerator class for more information.
Example 3 — Specifying a Complex, Composite Filter
To generate the following composite search filter ((Field1 = string X & Field2 > number N1) & ((Field3 >= number N2 & Field3 <= number N3) | (Field4 = string A | Field4 = string B | Field4 = string C)))
import PT_SEARCH:SearchFilterGenerator;
Local PT_SEARCH:SearchFilterGenerator &fg = create PT_SEARCH:SearchFilterGenerator();
If &fg.MatchAllReturnTrue() Then
&fg.EqualsString("Field1", &str_X);
&fg.GreaterThanNumber("Field2", &N1);
&fg.EndMatchAll();
End-If;
If &fg.MatchAnyReturnTrue() Then
If &fg.MatchAllReturnTrue() Then
&fg.GreaterThanEqualsNumber("Field3", &N2);
&fg.LessThanEqualsNumber("Field3", &N3);
&fg.EndMatchAll();
End-If;
If &fg.MatchAnyReturnTrue() Then
&fg.EqualsString("Field4", &str_A);
&fg.EqualsString("Field4", &str_B);
&fg.EqualsString("Field4", &str_C);
&fg.EndMatchAny();
End-If;
&fg.EndMatchAny();
End-If;
&fg.SetQueryFilter(&qry);
Example 4 — Specifying a Numeric Filter Between Two Values
The following example generates a composite search filter with BU equal to 001 and price between 10 and 200:
import PT_SEARCH:SearchFilterGenerator;
Local PT_SEARCH:SearchFilterGenerator &fg = create PT_SEARCH:SearchFilterGenerator();
&fg.EqualsString("BU", "001");
If &fg.MatchAllReturnTrue() Then
&fg.GreaterThanEqualsNumber("PRICE", 10);
&fg.LessThanEqualsNumber("PRICE", 200);
&fg.EndMatchAll();
End-If;
&fg.SetQueryFilter(&qry);
See GreaterThanEqualsNumber method: SearchFilterGenerator class and LessThanEqualsNumber method: SearchFilterGenerator class for more information.
Example 5 — Specifying a String Filter Within a Set of Values
The following example generates a composite search filter with BU equal to 001 and status in (Open, Pending, Approved):
import PT_SEARCH:SearchFilterGenerator;
Local PT_SEARCH:SearchFilterGenerator &fg = create PT_SEARCH:SearchFilterGenerator();
&fg.EqualsString("BU", "001");
If &fg.MatchAnyReturnTrue() Then
&fg.EqualsString("STATUS", "Open");
&fg.EqualsString("STATUS", "Pending");
&fg.EqualsString("STATUS", "Approved");
&fg.EndMatchAny();
End-If;
&fg.SetQueryFilter(&qry);
See EqualsString method: SearchFilterGenerator class for more information.
Example 6 — Specifying a String Filter Not in a Set of Values
The following example generates a composite search filter with BU equal to 001 and status not in (Open, Pending, Approved):
import PT_SEARCH:SearchFilterGenerator;
Local PT_SEARCH:SearchFilterGenerator &fg = create PT_SEARCH:SearchFilterGenerator();
&fg.EqualsString("BU", "001");
If &fg.MatchAllReturnTrue() Then
&fg.NotEqualsString("STATUS", "Open");
&fg.NotEqualsString("STATUS", "Pending");
&fg.NotEqualsString("STATUS", "Approved");
&fg.EndMatchAll();
End-If;
&fg.SetQueryFilter(&qry);
See NotEqualsString method: SearchFilterGenerator class for more information.