SearchRank
This class represents a database function that calculates the relevance score of a search vector against a search query. It supports optional weighting, normalization, and cover density ranking by switching between the underlying ts_rank and ts_rank_cd functions. The class ensures that input vectors and queries are properly resolved and cast to the appropriate database types for execution.
Attributes
| Attribute | Type | Description |
|---|---|---|
| function | string = ts_rank | The name of the database function used to calculate the search rank, which defaults to 'ts_rank' but changes to 'ts_rank_cd' if cover_density is enabled. |
| output_field | [FloatField](../../../forms/fields/floatfield.md?sid=django_forms_fields_floatfield) | The database field type used to represent the calculated rank value, which is a FloatField. |
Constructor
Signature
def SearchRank(
vector: SearchVector | Expression,
query: SearchQuery | Expression,
weights: list | Expression = None,
normalization: int | Expression = None,
cover_density: boolean = False
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| vector | `SearchVector | Expression` |
| query | `SearchQuery | Expression` |
| weights | `list | Expression` = None |
| normalization | `int | Expression` = None |
| cover_density | boolean = False | If True, uses the ts_rank_cd function which considers the proximity of matching lexemes. |
Signature
def SearchRank(
vector: SearchVector | str,
query: SearchQuery | str,
weights: list | Value | None = None,
normalization: int | Value | None = None,
cover_density: bool = False
)
Parameters
| Name | Type | Description |
|---|---|---|
| vector | `SearchVector | str` |
| query | `SearchQuery | str` |
| weights | `list | Value |
| normalization | `int | Value |
| cover_density | bool = False | When True, switches the underlying function to 'ts_rank_cd' which accounts for the proximity of matching lexemes. |