def METHOD_NAME(query_, definition):
    if isinstance(definition, MatchPropertyDefinition):
        match_type = definition.match_type
        if match_type == MatchPropertyDefinition.MATCH_HAS_NO_VALUE:
            query_ = query_.case_property_missing(definition.property_name)
        elif match_type == MatchPropertyDefinition.MATCH_HAS_VALUE:
            query_ = query_.NOT(case_property_missing(definition.property_name))
        elif match_type == MatchPropertyDefinition.MATCH_EQUAL:
            query_ = query_.case_property_query(
                definition.property_name,
                definition.property_value,
                queries.MUST,
            )
        elif match_type == MatchPropertyDefinition.MATCH_NOT_EQUAL:
            query_ = query_.case_property_query(
                definition.property_name,
                definition.property_value,
                queries.MUST_NOT,
            )
    elif isinstance(definition, LocationFilterDefinition):
        # Get all users owning cases at definition.location_id
        owners_ids = user_ids_at_locations([definition.location_id])
        # Add the definition.location_id for cases which belong to definition.location_id
        owners_ids.append(definition.location_id)
        query_ = query_.owner(owners_ids)
    return query_