Rank class

更新时间:
复制 MD 格式

The Rank class configures the ranking strategy for a search request. OpenSearch uses a two-stage ranking pipeline: rough sort narrows the candidate set, and fine sort reorders the top results using a more precise expression.

Use Rank to specify which expressions to apply at each stage and how many documents to rerank.

Constructor

Rank()

No parameters required.

Parameters

firstRankName

Sets or gets the name of the rough sort expression.

Rough sort runs first and filters the full candidate set down to a smaller pool. Set this to the name of an expression configured in your OpenSearch application. If you only need rough sort without fine sort, set firstRankName and leave secondRankName unset.

TypeString
SetterRank setFirstRankName(String firstRankName)
GetterString getFirstRankName()
Returns (setter)Rank — supports method chaining
Returns (getter)The configured rough sort expression name

secondRankName

Sets or gets the name of the fine sort expression.

Fine sort runs after rough sort and reorders the top reRankSize documents using a more precise scoring expression. Set this only when you want a second-stage reranking pass on top of rough sort results.

TypeString
SetterRank setSecondRankName(String secondRankName)
GetterString getSecondRankName()
Returns (setter)Rank — supports method chaining
Returns (getter)The configured fine sort expression name

reRankSize

Sets or gets the number of documents to rerank using the fine sort expression. Corresponds to the rerank_size parameter of the Config class.

Typeint
RequiredNo
Valid values[0, 2000]
Default200
SetterRank setReRankSize(int reRankSize)
Getterint getReRankSize()
Returns (setter)Rank — supports method chaining
Returns (getter)The configured rerank size

Example

The following example builds a Rank object with both rough sort and fine sort configured.

// Configure ranking strategy
Rank rank = new Rank()
    .setFirstRankName("rough_sort_expression")   // rough sort expression name
    .setSecondRankName("fine_sort_expression")   // fine sort expression name
    .setReRankSize(200);                          // rerank top 200 documents

To apply only rough sort without fine sort, omit setSecondRankName:

Rank rank = new Rank()
    .setFirstRankName("rough_sort_expression");