Find single keywords in the fulltext.

    :param skw_db: list of KeywordToken objects
    :param fulltext: string, which will be searched

    :return : dictionary of matches in a format {
        <keyword object>, [[position, position...], ],
        ..
    }

def get_single_keywords(skw_db, fulltext):
    """Find single keywords in the fulltext.

    :param skw_db: list of KeywordToken objects
    :param fulltext: string, which will be searched

    :return : dictionary of matches in a format {
        <keyword object>, [[position, position...], ],
        ..
    }
    """
    timer_start = time.clock()

    # single keyword -> [spans]
    records = []

    for single_keyword in skw_db.values():
        for regex in single_keyword.regex:
            for match in regex.finditer(fulltext):
                # Modify the right index to put it on the last letter
                # of the word.
                span = (match.span()[0], match.span()[1] - 1)

                # FIXME: expensive!!!
                # Remove the previous records contained by this span
                records = [record for record in records
                           if not _contains_span(span, record[0])]

                add = True
                for previous_record in records:
                    if ((span, single_keyword) == previous_record or
                            _contains_span(previous_record[0], span)):
                        # Match is contained by a previous match.
                        add = False
                        break

                if add:
                    records.append((span, single_keyword))

    # TODO - change to the requested format (I will return to it later)

    # List of single_keywords: {spans: single keyword}
    single_keywords = {}
    for span, single_keyword in records:
        single_keywords.setdefault(single_keyword, [[]])
        single_keywords[single_keyword][0].append(span)

    current_app.logger.info(
        "Matching single keywords... %d keywords found "
        "in %.1f sec." % (len(single_keywords), time.clock() - timer_start),
    )
    return single_keywords