def search_pack_index(
    query, exclude=None, priority=None, case_sensitive=True, proxy_config=None
):
    """
    Search the pack index by query.
    Returns a list of matches for a query.
    """
    if not query:
        raise ValueError("Query must be specified.")

    if not exclude:
        exclude = EXCLUDE_FIELDS
    if not priority:
        priority = SEARCH_PRIORITY

    if not case_sensitive:
        query = str(query).lower()

    index, _ = fetch_pack_index(proxy_config=proxy_config)

    matches = [[] for i in range(len(priority) + 1)]
    for pack in six.itervalues(index):
        for key, value in six.iteritems(pack):
            if not hasattr(value, "__contains__"):
                value = str(value)

            if not case_sensitive:
                value = lowercase_value(value=value)

            if key not in exclude and query in value:
                if key in priority:
                    matches[priority.index(key)].append(pack)
                else:
                    matches[-1].append(pack)
                break

    return list(itertools.chain.from_iterable(matches))

    Search the pack index by query.
    Returns a list of matches for a query.
    
st2common/st2common/services/packs.py