Class BraveSuggestQuery
- All Implemented Interfaces:
BraveQueryBuilder<BraveSuggestQuery,SuggestSearchApiResponse>
The builder is not thread-safe and is intended for single-threaded use. It is stateful and
reusable: call reset() to clear its internal state before reusing it.
Builders are not intended to be instantiated directly; use the builder() factory
method to create a new instance.
-
Field Summary
Fields inherited from class net.ygbstudio.jbrave.core.builders.AbstractQueryUrlBuilder
delayedOperators, optionTracker, QUERY_PROMPT, urlEnd, urlStart -
Method Summary
Modifier and TypeMethodDescriptionstatic BraveSuggestQuerybuilder()Creates a new instance ofBraveSuggestQuery.count(int count) Adds the count option to the URL query.<T extends CountryIdentifier>
BraveSuggestQuerycountry(T country) Adds the country option to the URL query.execute()Executes the request and stores the response.@NotNull Optional<HttpResponse<String>> Returns the current HTTP response as anOptional.Returns the type of the API response.booleanChecks if the request has been executed.<T extends LanguageIdentifier>
BraveSuggestQuerylanguage(T searchLanguage) Adds the search language option to the URL query.Adds a search term to the URL query.reset()Clears the current instance ofBraveSuggestQueryby resetting its state to its initial values.rich(boolean rich) Adds the rich option to the URL query.Converts the current query to anHttpRequestinstance.withHeaders(@NotNull Consumer<VerticalHeaderBuilder<BraveVerticalRequest>> headers) Sets the request headers using the provided consumer.withRetries(int maxRetries) Sets the maximum number of retry attempts for rate-limited (HTTP 429) responses.withToken(@NotNull ClientInfo clientInfo) Sets the subscription token header using the providedClientInfoinstance.Methods inherited from class net.ygbstudio.jbrave.core.builders.AbstractQueryUrlBuilder
addInstanceVertical, addOption, addOptionCarrier, addQueryTerm, build, clear, isValidQuery, optionMissing, queryMissing, self, toURIMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.ygbstudio.jbrave.api.builders.BraveQueryBuilder
getEitherPOJO, getErrorPOJO, getPOJO, getRateLimitPolicy, getRateLimitRemaining, getRateLimits, toURI
-
Method Details
-
builder
Creates a new instance ofBraveSuggestQuery.- Returns:
- a new instance of
BraveSuggestQuery
-
query
Adds a search term to the URL query. Maximum of 400 characters and 50 words.If a query is already present, subsequent calls are ignored. Only one query term is supported per search request.
- Parameters:
queryTerm- the search term to add- Returns:
- the current instance of the builder
-
language
Adds the search language option to the URL query.- Type Parameters:
T- the search language type- Parameters:
searchLanguage- the search language to set- Returns:
- the current instance of the builder
- See Also:
-
country
Adds the country option to the URL query.- Type Parameters:
T- the country type- Parameters:
country- the country identifier to set- Returns:
- the current instance of the builder
- See Also:
-
rich
Adds the rich option to the URL query.- Parameters:
rich- whether to enable rich results- Returns:
- the current instance of the builder
-
count
Adds the count option to the URL query.- Parameters:
count- the number of results to return- Returns:
- the current instance of the builder
-
withToken
Sets the subscription token header using the providedClientInfoinstance.- Parameters:
clientInfo- theClientInfoinstance containing the subscription token- Returns:
- the current instance of
BraveSuggestQuery
-
withHeaders
@Contract("_ -> this") public BraveSuggestQuery withHeaders(@NotNull @NotNull Consumer<VerticalHeaderBuilder<BraveVerticalRequest>> headers) Sets the request headers using the provided consumer.- Parameters:
headers- a consumer that receives aVerticalHeaderBuilderand applies the request's headers to it- Returns:
- the current instance of
BraveSuggestQuery
-
withRetries
Sets the maximum number of retry attempts for rate-limited (HTTP 429) responses.Values less than or equal to zero fall back to the default retry policy (one retry). Retries sleep for the server-provided rate limit reset window before each attempt.
- Parameters:
maxRetries- the maximum number of retry attempts for rate-limited responses- Returns:
- the current instance of
BraveSuggestQuery
-
execute
Description copied from interface:BraveQueryBuilderExecutes the request and stores the response.This method is typically used to decouple request execution from response extraction.
You can extract the response later with
BraveQueryBuilder.getHttpResponse(),BraveQueryBuilder.getPOJO(), orBraveQueryBuilder.getErrorPOJO().Note: This builder stores the response object internally and repeated calls to extraction methods will not trigger multiple requests; however,
execute()will send a new request per method call.If the client added retries to the building chain,
execute()will activate retry logic under the hood.By default, rate-limited (HTTP 429) responses are retried once after sleeping the server-provided rate limit reset window. Use
withRetries(int)to change the policy; values less than or equal to zero retain the default (one retry).- Specified by:
executein interfaceBraveQueryBuilder<BraveSuggestQuery,SuggestSearchApiResponse> - Returns:
- the current builder instance
-
hasExecuted
public boolean hasExecuted()Description copied from interface:BraveQueryBuilderChecks if the request has been executed. Precisely, it will tell the caller whether the builder has an existing (complete) request in it or not.- Specified by:
hasExecutedin interfaceBraveQueryBuilder<BraveSuggestQuery,SuggestSearchApiResponse> - Returns:
trueif the request has been executed,falseotherwise
-
toHttpRequest
Converts the current query to anHttpRequestinstance.- Specified by:
toHttpRequestin interfaceBraveQueryBuilder<BraveSuggestQuery,SuggestSearchApiResponse> - Returns:
- the
HttpRequestinstance representing the current query
-
getHttpResponse
Returns the current HTTP response as anOptional.If the request has not been executed, this method will execute the request and return the
HttpResponse.- Specified by:
getHttpResponsein interfaceBraveQueryBuilder<BraveSuggestQuery,SuggestSearchApiResponse> - Returns:
- an
Optionalcontaining the current HTTP response.
-
getResponseType
Description copied from interface:BraveQueryBuilderReturns the type of the API response. The class returned by this method is the class of the concrete implementation ofApiResponsethat this builder is expected to produce as a result of its query.- Specified by:
getResponseTypein interfaceBraveQueryBuilder<BraveSuggestQuery,SuggestSearchApiResponse> - Returns:
- the class of the API response
-
reset
Clears the current instance ofBraveSuggestQueryby resetting its state to its initial values.- Specified by:
resetin interfaceBraveQueryBuilder<BraveSuggestQuery,SuggestSearchApiResponse> - Returns:
- the current instance of
BraveSuggestQuery
-