Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The If Wrapper stage can in SearchAPI allows you to execute a list of stages depending based on the result of a comparison. The stage will check inside intermediate for the field defined in check_field, and see if its value matches the one given in check_value, if this is true the stages stored in stages, otherwise if the list else_stages was provided, will executeThis stage checks a specific field inside the intermediate data and compares its value with the one provided in the check_value parameter. If the comparison is true, the stages specified in the stages parameter will be executed. Alternatively, if the else_stages parameter is provided, those stages will be executed.

Note

This applies for all the stage functions process, post_process and get_ui_config

Info

If Wrapper doesn't return value to the pipeline

PropertyDescriptionDefaultTypeRequired
typeStage class name-stringYes
enableEnable stage for executiontruebooleanNo
nameName for this specific stage"if"stringNo
save_to_intermediateIf true, the result of the stage will be stored in the intermediate instead of the final sectionfalsebooleanNo
ui_onlySection specific for UI configuration that affects the process of the stageobjectNo
halt_on_exceptionIndicates if the pipeline should be interrupted in case of an exceptionfalsebooleanNo
stagesList of stages to be executed if the condition is true-array of BaseStageYes (minItems: 1)
else_stagesList of stages to be executed if the condition is false[]array of BaseStageNo (minItems: 1)
check_fieldKey used in the JSON payload to validate whether the stage should be enabled or notstringYes
check_valueField value used to compare with the value in the "check_field" to determine if the stage should be enabled-No

Example Configuration

Code Block
languagepy
themeDJango
_if = IfWrapperStage(
    name='if',
    check_field='flag',
    check_value=True,
    stages=[_search1],
    else_stages=[_search2]
)