#NEWLINE# def bm25_relevance( self , terms , matches , current_doc , total_docs , b = 0 , k = 1.2 ) : #NEWLINE# #INDENT# "\n        Given multiple inputs, performs a BM25 relevance calculation for a\n        given document.\n\n        ``terms`` should be a list of terms.\n\n        ``matches`` should be the first dictionary back from\n        ``collect_results``.\n\n        ``current_doc`` should be the second dictionary back from\n        ``collect_results``.\n\n        ``total_docs`` should be an integer of the total docs in the index.\n\n        Optionally accepts a ``b`` parameter, which is an integer specifying\n        the length of the document. Since it doesn't vastly affect the score,\n        the default is ``0``.\n\n        Optionally accepts a ``k`` parameter. It accepts a float & is used to\n        modify scores to fall into a given range. With the default of ``1.2``,\n        scores typically range from ``0.4`` to ``1.0``.\n        " #NEWLINE# score = b #NEWLINE# for term in terms : #NEWLINE# #INDENT# idf = ( math . log ( ( ( ( total_docs - matches [ term ] ) + 1.0 ) / matches [ term ] ) ) / math . log ( ( 1.0 + total_docs ) ) ) #NEWLINE# score = ( score + ( ( current_doc . get ( term , 0 ) * idf ) / ( current_doc . get ( term , 0 ) + k ) ) ) #NEWLINE# #UNINDENT# return ( 0.5 + ( score / ( 2 * len ( score ) ) ) )