def do_query(archives, config_file=None, logger=None, context=None):
    '\n    Gets concordance for keywords and groups by word.\n\n    config_file must be the path to a configuration file with a list\n    of the keywords to search for, one per line.\n\n    Both keywords and words in documents are normalized, by removing\n    all non-\'a-z|A-Z\' characters.\n\n    Returns result of form:\n\n        {\n            <WORD>:\n                [\n                    {\n                        "title": <TITLE>,\n                        "place": <PLACE>,\n                        "publisher": <PUBLISHER>,\n                        "page_number": <PAGE_NUMBER>,\n                        "content": <PAGE_CONTENT>,\n                        "year": <YEAR>,\n                        "document_id": <DOCUMENT_ID>,\n                        "filename": <FILENAME>\n                    },\n                    ...\n                ],\n            <WORD>:\n                ...\n        }\n\n    :param archives: RDD of defoe.alto.archive.Archive\n    :type archives: pyspark.rdd.PipelinedRDD\n    :param config_file: query configuration file\n    :type config_file: str or unicode\n    :param logger: logger (unused)\n    :type logger: py4j.java_gateway.JavaObject\n    :return: information on documents in which keywords occur grouped\n    by word\n    :rtype: dict\n    '
    keywords = query_utils.get_normalized_keywords(config_file)
    documents = archives.flatMap((lambda archive: [document for document in list(archive)]))
    filtered_words = documents.flatMap((lambda document: get_page_matches(document, keywords)))
    matching_docs = filtered_words.map((lambda year_document_page_word: (year_document_page_word[3], {'title': year_document_page_word[1].title, 'place': year_document_page_word[1].place, 'publisher': year_document_page_word[1].publisher, 'page_number': year_document_page_word[2].code, 'content': year_document_page_word[2].content, 'year': year_document_page_word[0], 'document_id': year_document_page_word[1].code, 'filename': year_document_page_word[1].archive.filename})))
    result = matching_docs.groupByKey().map((lambda year_context: (year_context[0], list(year_context[1])))).collect()
    return result
Gets concordance for keywords and groups by word.

config_file must be the path to a configuration file with a list
of the keywords to search for, one per line.

Both keywords and words in documents are normalized, by removing
all non-'a-z|A-Z' characters.

Returns result of form:

    {
        <WORD>:
            [
                {
                    "title": <TITLE>,
                    "place": <PLACE>,
                    "publisher": <PUBLISHER>,
                    "page_number": <PAGE_NUMBER>,
                    "content": <PAGE_CONTENT>,
                    "year": <YEAR>,
                    "document_id": <DOCUMENT_ID>,
                    "filename": <FILENAME>
                },
                ...
            ],
        <WORD>:
            ...
    }

:param archives: RDD of defoe.alto.archive.Archive
:type archives: pyspark.rdd.PipelinedRDD
:param config_file: query configuration file
:type config_file: str or unicode
:param logger: logger (unused)
:type logger: py4j.java_gateway.JavaObject
:return: information on documents in which keywords occur grouped
by word
:rtype: dict
def do_query(archives, config_file=None, logger=None, context=None):
    '\n    Gets concordance for keywords and groups by word.\n\n    config_file must be the path to a configuration file with a list\n    of the keywords to search for, one per line.\n\n    Both keywords and words in documents are normalized, by removing\n    all non-\'a-z|A-Z\' characters.\n\n    Returns result of form:\n\n        {\n            <WORD>:\n                [\n                    {\n                        "title": <TITLE>,\n                        "place": <PLACE>,\n                        "publisher": <PUBLISHER>,\n                        "page_number": <PAGE_NUMBER>,\n                        "content": <PAGE_CONTENT>,\n                        "year": <YEAR>,\n                        "document_id": <DOCUMENT_ID>,\n                        "filename": <FILENAME>\n                    },\n                    ...\n                ],\n            <WORD>:\n                ...\n        }\n\n    :param archives: RDD of defoe.alto.archive.Archive\n    :type archives: pyspark.rdd.PipelinedRDD\n    :param config_file: query configuration file\n    :type config_file: str or unicode\n    :param logger: logger (unused)\n    :type logger: py4j.java_gateway.JavaObject\n    :return: information on documents in which keywords occur grouped\n    by word\n    :rtype: dict\n    '
    keywords = query_utils.get_normalized_keywords(config_file)
    documents = archives.flatMap((lambda archive: [document for document in list(archive)]))
    filtered_words = documents.flatMap((lambda document: get_page_matches(document, keywords)))
    matching_docs = filtered_words.map((lambda year_document_page_word: (year_document_page_word[3], {'title': year_document_page_word[1].title, 'place': year_document_page_word[1].place, 'publisher': year_document_page_word[1].publisher, 'page_number': year_document_page_word[2].code, 'content': year_document_page_word[2].content, 'year': year_document_page_word[0], 'document_id': year_document_page_word[1].code, 'filename': year_document_page_word[1].archive.filename})))
    result = matching_docs.groupByKey().map((lambda year_context: (year_context[0], list(year_context[1])))).collect()
    return result