Class SearchQueryBuilder
java.lang.Object
com.oracle.content.sdk.request.core.SearchQueryBuilder
This helper class will construct the raw "filter" string to use when specifying
a filter for
SearchAssetsRequest
. A type is usually specified
when creating the builder, then field expressions can be added using andField(String, QueryOperator, String)
)}
or orField(String, QueryOperator, String)
. For example to construct a search query string
such as 'type eq "fruit" AND fields.color EQ "red"', which searches items of type 'fruit' that also
has a field called 'color' with the value of red.
String redFruitFilterQuery filterBuilder =
new SearchQueryBuilder("fruit").andField("color", QueryOperator.EQUALS, "red").build();
More complex nested expressions can be constructed using startGroup(QueryOperator)
. For example,
to create a query such as 'type eq "menu_type" AND (fields.item_type eq "breakfast" OR fields.item_type eq "lunch")':
String searchQuery = new SearchQueryBuilder("menu_type") .startGroup(SearchQueryBuilder.QueryOperator.AND) .orField( "item_type", SearchQueryBuilder.QueryOperator.EQUALS, "breakfast") .orField( "item_type", SearchQueryBuilder.QueryOperator.EQUALS, "lunch") .endGroup() .build();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Enumerates the possible query operator values -
Constructor Summary
ConstructorsConstructorDescriptionStart with a blank builderSearchQueryBuilder
(String type) Constructor that takes a type and starts the filter with the expression type eq 'typename', where 'typename' is the parameter. -
Method Summary
Modifier and TypeMethodDescriptionSpecify your own clause such as "and", "or".addExpression
(String expression) Add an additional filter expression using "and" to an expression already started.andField
(String field, SearchQueryBuilder.QueryOperator operator, String value) Adds a filter expression of form "AND field operator value" to the filter request.build()
Return the fully constructed filter string to use for search callendGroup()
End expression group with parenthesis.static String
getFieldList
(List<String> fieldList) static String
getFieldName
(String fieldName) If the field name is not a top-level name such as "type" or "name" or "description" it must be prefixed with "fields."static String
matchIdList
(String field, List<String> stringList, boolean groupExpression) Given a list of strings, returns a query expression to match any of the strings.Given a list of strings, adds to the filter a query expression to match any of the strings.orField
(String field, SearchQueryBuilder.QueryOperator operator, String value) Adds a filter expression of form "OR field operator value" to the filter.startExpression
(String expression) Called to start an expression at the beginning of the filter with a fully formed expressionstartExpression
(String field, SearchQueryBuilder.QueryOperator operator, String value) Called to start an expression at the beginning of the filter.startGroup
(SearchQueryBuilder.QueryOperator operator) Start a new expression group with parenthesis, for example "AND (expression)".
-
Constructor Details
-
SearchQueryBuilder
Constructor that takes a type and starts the filter with the expression type eq 'typename', where 'typename' is the parameter. This is the most common way to start an expression, but a blank expression can be created as well by callingSearchQueryBuilder()
and then callingstartExpression(String, QueryOperator, String)
- Parameters:
type
- String for the type to match
-
SearchQueryBuilder
public SearchQueryBuilder()Start with a blank builder
-
-
Method Details
-
getFieldName
If the field name is not a top-level name such as "type" or "name" or "description" it must be prefixed with "fields."- Parameters:
fieldName
- Name of field- Returns:
- Name of field with "fields." prefix if necessary
-
startExpression
public SearchQueryBuilder startExpression(String field, SearchQueryBuilder.QueryOperator operator, String value) Called to start an expression at the beginning of the filter.- Parameters:
field
- name of the field to matchoperator
- the operation to use (e.g. "co" or "eq")value
- the value to match- Returns:
- builder
-
startExpression
Called to start an expression at the beginning of the filter with a fully formed expression- Parameters:
expression
- expression to start- Returns:
- builder
-
addExpression
Add an additional filter expression using "and" to an expression already started.- Parameters:
expression
- fully formed filter expression- Returns:
- builder
-
addClause
Specify your own clause such as "and", "or". This isn't restricted to the QueryOperator enum but in general should be used for clause and operators.- Parameters:
clause
- field such as "and", "or"field
- name of the field to matchoperator
- the operation to use (e.g. "co" or "eq")value
- the value to match- Returns:
- builder
-
andField
public SearchQueryBuilder andField(String field, SearchQueryBuilder.QueryOperator operator, String value) Adds a filter expression of form "AND field operator value" to the filter request.- Parameters:
field
- name of the field to matchoperator
- seeSearchQueryBuilder.QueryOperator
for possible valuesvalue
- the value to match- Returns:
- builder
-
startGroup
Start a new expression group with parenthesis, for example "AND (expression)".- Parameters:
operator
- Operator to proceed the group expression- Returns:
- builder
-
startGroup
-
endGroup
End expression group with parenthesis.- Returns:
- builder
-
orField
public SearchQueryBuilder orField(String field, SearchQueryBuilder.QueryOperator operator, String value) Adds a filter expression of form "OR field operator value" to the filter.- Parameters:
field
- name of the field to matchoperator
- seeSearchQueryBuilder.QueryOperator
for possible valuesvalue
- the value to match- Returns:
- builder
-
matchList
Given a list of strings, adds to the filter a query expression to match any of the strings. For example, if string list contains "a, b, c", then and call is matchList("id", list), then result would be "id eq a OR id eq b OR id eq c"- Parameters:
field
- field to match such as "id"stringList
- list of string valuesgroupExpression
- if true, will put expressions in a group ( expr )- Returns:
- matching expression.
-
matchIdList
Given a list of strings, returns a query expression to match any of the strings. For example, if string list contains "a, b, c", then and call is matchIdList("id", list), then result would be "id eq a OR id eq b OR id eq c"- Parameters:
field
- field to match such as "id"stringList
- list of string valuesgroupExpression
- if true, will put expressions in a group ( expr )- Returns:
- matching expression.
-
getFieldList
-
build
Return the fully constructed filter string to use for search call- Returns:
- filter expression to use for search
-