from operator import or_


def get_filter_clauses_for_partial_field_match(field, partial_strings_array):
    """
    Create filter clauses for partially matching the field to any of the
    strings in an array using LIKE
    """
    clauses = []
    for partial_string in partial_strings_array:
        stripped_partial_string = partial_string.strip()
        if stripped_partial_string:
            clauses.append(field.like('%' + stripped_partial_string + '%'))
    if len(clauses) == 0:
        return None
    elif len(clauses) == 1:
        return clauses[0]

    return or_(*clauses)