def METHOD_NAME(self, text, length=240):
    """Extract the context for the search query from the document's
    full `text`.
    :param text: the full text of the document to create the context for
    :param length: the length of the context snippet to return.
    """
    res = self.context_re.search(text)
    if res is None:
        return ''
    context_start = max(res.start() - int(length/2), 0)
    context_end = context_start + length
    context = ''.join([context_start > 0 and '...' or '',
                       text[context_start:context_end],
                       context_end < len(text) and '...' or ''])
    try:
        return text_type(context, errors='ignore')
    except TypeError:
        return context