#NEWLINE# def search( self , query , html = False ) : #NEWLINE# #INDENT# 'Search the index using a text query.\n        ' #NEWLINE# if html : #NEWLINE# #INDENT# query_terms = self . _prepare_html ( query ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# query_terms = self . _prepare_text ( query ) #NEWLINE# #UNINDENT# idfs = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# num_docs = self . document_index . objects . count ( ) #NEWLINE# for term in query_terms : #NEWLINE# #INDENT# term_docs = self . document_index . objects ( terms__term = term ) . count ( ) #NEWLINE# idfs [ term ] = log ( ( ( ( num_docs - term_docs ) + 0.5 ) / ( term_docs + 0.5 ) ) ) #NEWLINE# #UNINDENT# avg_doc_length = self . document_index . objects . average ( 'length' ) #NEWLINE# query = self . document_index . objects ( terms__term__in = query_terms ) #NEWLINE# options = { #NEWLINE# #INDENT# 'idfs' : idfs , #NEWLINE# 'avgDocLength' : avg_doc_length , #NEWLINE# 'queryTerms' : query_terms , #NEWLINE# 'k' : 2.0 , #NEWLINE# 'b' : 0.75 , #NEWLINE# #UNINDENT# } #NEWLINE# results = query . exec_js ( self . SEARCH_JS , 'doc_id' , 'terms' , ** options ) #NEWLINE# return results