def _near_words(first, second, distance, exact=False):
    """
    Returns a query item matching messages that two words within a certain
    distance of each other.

    Args:
        first (str): The first word to search for.
        second (str): The second word to search for.
        distance (int): How many words apart first and second can be.
        exact (bool): Whether first must come before second [default False].

    Returns:
        The query string.

    """
    query = f'{first} AROUND {distance} {second}'
    if exact:
        query = '"' + query + '"'
    return query
