public class FilterBuilder extends Object
The FilterBuilder class is a utility that is intended to be used to create
filters for eSales queries. The methods in this class are all static and return some kind of Filter
limiting your
search.
// create some simple attribute filters
Filter a = FilterBuilder.attribute("artist", "Presley");
Filter b = FilterBuilder.attribute("song", "Jumpin' Jack Flash");
Filter c = FilterBuilder.attribute("description", "Rock nostalgia");
System.out.println("Created some attribute filters:");
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println();
// lets combine them
Filter kingOfRock = FilterBuilder.and(a, c);
System.out.println(kingOfRock);
Filter classic = FilterBuilder.and(b, c);
System.out.println(classic);
Filter justCool = FilterBuilder.or(a, b);
System.out.println(justCool);
Filter coolOldie = FilterBuilder.and(justCool, c);
System.out.println(coolOldie);
System.out.println();
// lets add some more stuff into the mix
Filter lamers = FilterBuilder.attribute("artist", "Sofarock");
lamers = FilterBuilder.or(lamers, FilterBuilder.attribute("artist", "amazonics"));
Filter noLamers = FilterBuilder.not(lamers);
System.out.println(noLamers);
// combine more than 2 filters at once by simply supplying them all
Filter theOriginal = FilterBuilder.and(classic, noLamers, c);
System.out.println(theOriginal);
Modifier and Type | Method | Description |
---|---|---|
static Filter |
and(Filter[] filters) |
Create a new AND filter to match the intersection of the results that all
filters would return. |
static Filter |
and(Filter q1,
Filter q2,
Filter... filters) |
Create a new AND filter to match the intersection of results that
q1 , q2 and each of the
filters would return. |
static Filter |
attribute(String[] attributes,
String value) |
Create a new attribute filter, limiting results to products where all processed parts (after tokenization and
normalization) of the specified
value are present within any of the given attributes . |
static Filter |
attribute(String attribute,
String value) |
Create a new attribute filter, limiting results to products where all processed parts (after tokenization and
normalization) of the specified
value are present within the given attribute . |
static Filter |
empty() |
Return a empty filter representing no results.
|
static Filter |
fromString(String filter) |
Create a new filter, limiting results to products inside the specified filter.
|
static Filter |
fromString(String filter,
boolean needsParentheses) |
Create a new filter, limiting results to products inside the specified filter.
|
static Filter |
incremental(String[] attributes,
String value) |
Create a new INCREMENTAL filter, limiting the result to products where all processed parts (after tokenization and
normalization) of the specified
value are present within any of the given attributes . |
static Filter |
incremental(String attribute,
String value) |
Create a new INCREMENTAL filter, limiting the result to products where all processed parts (after tokenization and
normalization) of the specified
value are present within the given attribute . |
static Filter |
not(Filter operand) |
Create a new NOT filter matching every result that the given
operand doesn't match. |
static Filter |
or(Filter[] filters) |
Create a new OR filter to match the union of results that each of the
filters would return. |
static Filter |
or(Filter q1,
Filter q2,
Filter... filters) |
Create a new OR filter to match the union of results that
q1 , q2 and each of the
filters would return. |
static Filter |
range(String[] attributes,
String from,
String to) |
Create a new range filter, limiting results to values between
from (inclusive) and to
(exclusive), for any of the specified attributes . |
static Filter |
range(String[] attributes,
String from,
String to,
boolean fromInc,
boolean toInc) |
Create a new range filter limiting results to values between
from and to , for any of the
specified attributes . |
static Filter |
range(String attribute,
String from,
String to) |
Create a new range filter, limiting results to values between
from (inclusive) and to
(exclusive), for the specified attribute . |
static Filter |
range(String attribute,
String from,
String to,
boolean fromInc,
boolean toInc) |
Create a new range filter limiting results to values between
from and to , for the specified
attribute . |
static Filter |
universe() |
Return a universe filter representing all results.
|
public static Filter and(Filter q1, Filter q2, Filter... filters)
q1
, q2
and each of the
filters
would return.q1
- the first operandq2
- the second operandfilters
- additional operandspublic static Filter or(Filter q1, Filter q2, Filter... filters)
q1
, q2
and each of the
filters
would return.q1
- the first operandq2
- the second operandfilters
- additional operandspublic static Filter not(Filter operand)
operand
doesn't match.operand
- the operand to negatepublic static Filter and(Filter[] filters)
filters
would return.filters
- additional operandspublic static Filter or(Filter[] filters)
filters
would return.filters
- additional operandspublic static Filter attribute(String[] attributes, String value)
value
are present within any of the given attributes
.attributes
- the attributes to search withinvalue
- the value to matchpublic static Filter attribute(String attribute, String value)
value
are present within the given attribute
.attribute
- the attribute to search withinvalue
- the value to matchpublic static Filter fromString(String filter)
filter
- the string representation of the filter to matchpublic static Filter fromString(String filter, boolean needsParentheses)
filter
- the string representation of the filter to matchneedsParentheses
- true if parentheses is needed when this filter is part of a composite filter.public static Filter incremental(String[] attributes, String value)
value
are present within any of the given attributes
. The last
value token matches if any attribute contains a value to which it is a prefix (after tokenization).attributes
- the attributes to search withinvalue
- the value to matchpublic static Filter incremental(String attribute, String value)
value
are present within the given attribute
. The last value
token matches if any attribute contains a value to which it is a prefix (after tokenization).attribute
- the attributes to search withinvalue
- the value to matchpublic static Filter range(String[] attributes, String from, String to)
from
(inclusive) and to
(exclusive), for any of the specified attributes
.attributes
- the attributesfrom
- the lower boundto
- the upper boundpublic static Filter range(String attribute, String from, String to)
from
(inclusive) and to
(exclusive), for the specified attribute
.attribute
- the attributefrom
- the lower boundto
- the upper boundpublic static Filter range(String[] attributes, String from, String to, boolean fromInc, boolean toInc)
from
and to
, for any of the
specified attributes
. Whether or not the bounds should be considered inclusive or exclusive is determined by
the specified fromInc
and toInc
parameters.attributes
- the attributesfrom
- the lower boundto
- the upper boundfromInc
- if the lower bound is to be considered inclusivetoInc
- if the upper bound is to be considered inclusivepublic static Filter range(String attribute, String from, String to, boolean fromInc, boolean toInc)
from
and to
, for the specified
attribute
. Whether or not the bounds should be considered inclusive or exclusive is determined by the
specified fromInc
and toInc
parameters.attribute
- the attributesfrom
- the lower boundto
- the upper boundfromInc
- if the lower bound is to be considered inclusivetoInc
- if the upper bound is to be considered inclusivepublic static Filter universe()
public static Filter empty()
Copyright © 2021 Apptus Technologies AB. All rights reserved.