#NEWLINE# def _search( self , query , search_term ) : #NEWLINE# #INDENT# values = search_term . split ( ' ' ) #NEWLINE# queries = [ ] #NEWLINE# for value in values : #NEWLINE# #INDENT# if ( not value ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# regex = parse_like_term ( value ) #NEWLINE# stmt = [ ] #NEWLINE# for field in self . _search_fields : #NEWLINE# #INDENT# stmt . append ( { #NEWLINE# #INDENT# field : { #NEWLINE# #INDENT# '$regex' : regex , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# if stmt : #NEWLINE# #INDENT# if ( len ( stmt ) == 1 ) : #NEWLINE# #INDENT# queries . append ( stmt [ 0 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# queries . append ( { #NEWLINE# #INDENT# '$or' : stmt , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if queries : #NEWLINE# #INDENT# if ( len ( queries ) == 1 ) : #NEWLINE# #INDENT# final = queries [ 0 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# final = { #NEWLINE# #INDENT# '$and' : queries , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# if query : #NEWLINE# #INDENT# query = { #NEWLINE# #INDENT# '$and' : [ query , final ] , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# query = final #NEWLINE# #UNINDENT# #UNINDENT# return query