SearchParamsBuilder

更新时间:
复制 MD 格式

SearchParamsBuilder is a utility class for SearchParams that provides a fluent API for configuring search query parameters.

Constructors

SearchParamsBuilder.create(SearchParams otherSearchParams)

Creates a SearchParamsBuilder from an existing SearchParams object.

Signature

static SearchParamsBuilder SearchParamsBuilder.create(SearchParams otherSearchParams)

Parameters

ParameterTypeDescription
otherSearchParamsSearchParamsThe SearchParams object to initialize the builder from.

SearchParamsBuilder.create(Config config)

Creates a SearchParamsBuilder from a Config object.

Signature

static SearchParamsBuilder SearchParamsBuilder.create(Config config)

Parameters

ParameterTypeDescription
configConfigThe Config object to initialize the builder from.

Methods

addFilter(String filter)

Adds a filter expression to the query.

Signature

SearchParamsBuilder addFilter(String filter)

Parameters

ParameterTypeDescription
filterStringThe filter expression. Example: fieldName >= 1.

addFilter(String filter, String operator)

Adds a filter expression to the query and specifies how it combines with previously added filters.

Signature

SearchParamsBuilder addFilter(String filter, String operator)

Parameters

ParameterTypeDefaultDescription
filterStringThe filter expression. Example: fieldName >= 1.
operatorStringANDHow this filter combines with previously added filters. Valid values: AND, OR. AND requires all conditions to match. OR returns results matching any condition.

addCustomParam(String key, String value)

Adds a custom key-value parameter to the query.

Signature

SearchParamsBuilder addCustomParam(String key, String value)

Parameters

ParameterTypeDescription
keyStringThe parameter key.
valueStringThe parameter value.

addDisableFunction(String function, String value)

Disables a specific feature.

Signature

SearchParamsBuilder addDisableFunction(String function, String value)

Parameters

ParameterTypeDescription
functionStringThe name of the feature to disable.
valueStringThe value associated with the feature.

addDistinct(String key, int distCount, int distTimes, boolean reserved, String distFilter, boolean updateTotalHit, double grade)

Configures distinct extraction, which deduplicates search results by grouping documents with the same field value and returning only a specified number per group.

Signature

SearchParamsBuilder addDistinct(String key, int distCount, int distTimes, boolean reserved, String distFilter, boolean updateTotalHit, double grade)

Parameters

ParameterTypeDefaultDescription
keyStringThe field to group documents by. Must be an attribute field.
distCountint1The number of documents to return per group per extraction pass.
distTimesint1The number of extraction passes to perform.
reservedbooleantrueSpecifies whether to keep documents not selected during extraction. If true, remaining documents are included in the result set. If false, they are discarded.
distFilterStringAll documentsThe filter condition that determines which documents are eligible for extraction. Documents excluded by this filter are not extracted but are sorted together with the first group in the results.
updateTotalHitbooleanfalseSpecifies whether to subtract the count of discarded documents from totalHits. Only applies when reserved is false. If true, totalHits is adjusted, but the result may be approximate.
gradedoubleThe threshold for distinct extraction.

Usage

  • updateTotalHit only takes effect when reserved is false. When reserved is true, no documents are discarded and totalHits is unaffected.

  • Documents excluded by distFilter are not extracted but still appear in the results, sorted together with the first extraction group.

addSummary(String fieldName, Integer len, String element, String ellipsis, Integer snippet)

Configures a dynamic summary for search results. The summary highlights the portions of a text field that match the query.

Signature

SearchParamsBuilder addSummary(String fieldName, Integer len, String element, String ellipsis, Integer snippet)

Parameters

ParameterTypeDescription
fieldNameStringThe field to generate summaries from. Must be a text field (analyzed).
lenIntegerThe maximum length of each summary snippet, in bytes.
elementStringThe HTML element used to highlight matched terms. Example: em.
ellipsisStringThe string inserted where content is omitted. Example: "...".
snippetIntegerThe maximum number of summary snippets returned per query.
Field values may be trimmed or highlighted based on the dynamic summary rule.