Skip to main content

SearchConfig

This class represents a configuration for full-text search, specifically used to cast an expression to the PostgreSQL regconfig type. It provides methods to initialize the configuration from a value or parameter and integrates with the SQL compilation process to ensure the correct database type casting. The class manages its underlying configuration as a source expression within the database abstraction layer.

Attributes

AttributeTypeDescription
config[Expression](../../../db/models/expressions/expression.md?sid=django_db_models_expressions_expression)The configuration value or expression used to specify the text search configuration for PostgreSQL full-text search.

Constructor

Signature

def SearchConfig(
config: Any
) - > null

Parameters

NameTypeDescription
configAnyThe configuration value or expression to be used for the search configuration.

Signature

def SearchConfig(
config: string|Expression
) - > null

Parameters

NameTypeDescription
config`stringExpression`

Methods


from_parameter()

@classmethod
def from_parameter(
config: any
) - > SearchConfig|null

Creates a SearchConfig instance from a parameter if it is not already one or null.

Parameters

NameTypeDescription
configanyThe input parameter to be converted into a SearchConfig instance.

Returns

TypeDescription
`SearchConfignull`

get_source_expressions()

@classmethod
def get_source_expressions() - > list

Fetches the underlying configuration expressions associated with this instance.

Returns

TypeDescription
listA list containing the single configuration expression used by this object.

set_source_expressions()

@classmethod
def set_source_expressions(
exprs: list
) - > null

Updates the internal configuration expression with a new set of source expressions.

Parameters

NameTypeDescription
exprslistA list containing exactly one expression to be assigned as the new configuration.

Returns

TypeDescription
nullNone

as_sql()

@classmethod
def as_sql(
compiler: [SQLCompiler](../../../db/models/sql/compiler/sqlcompiler.md?sid=django_db_models_sql_compiler_sqlcompiler),
connection: DatabaseConnection
) - > tuple

Generates the SQL representation of the search configuration, casting the value to the PostgreSQL regconfig type.

Parameters

NameTypeDescription
compiler[SQLCompiler](../../../db/models/sql/compiler/sqlcompiler.md?sid=django_db_models_sql_compiler_sqlcompiler)The query compiler used to transform the expression into SQL.
connectionDatabaseConnectionThe current database connection used for vendor-specific SQL generation.

Returns

TypeDescription
tupleA tuple containing the SQL string with the regconfig cast and the list of parameters for the query.