#NEWLINE# @ target_required #NEWLINE# def SearchByRegexName( self , regex_name , stats = False , target_id = None ) : #NEWLINE# #INDENT# '\n        Allows searching of the grep_outputs table using a regex name\n        What this function returns :\n        + regex_name\n        + grep_outputs - list of unique matches\n        + transaction_ids - list of one transaction id per unique match\n        + match_percent\n        ' #NEWLINE# grep_outputs = self . db . session . query ( models . GrepOutput . output ) . filter_by ( name = regex_name , target_id = target_id ) . group_by ( models . GrepOutput . output ) . all ( ) #NEWLINE# grep_outputs = [ i [ 0 ] for i in self ] #NEWLINE# transaction_ids = [ ] #NEWLINE# for grep_output in grep_outputs : #NEWLINE# #INDENT# transaction_ids . append ( self . db . session . query ( models . Transaction . id ) . join ( models . Transaction . grep_outputs ) . filter ( ( models . GrepOutput . output == grep_output ) , ( models . GrepOutput . target_id == target_id ) ) . limit ( 1 ) . all ( ) [ 0 ] [ 0 ] ) #NEWLINE# #UNINDENT# if stats : #NEWLINE# #INDENT# num_matched_transactions = self . db . session . query ( models . Transaction ) . join ( models . Transaction . grep_outputs ) . filter ( ( models . GrepOutput . name == regex_name ) , ( models . GrepOutput . target_id == target_id ) ) . group_by ( models . Transaction ) . count ( ) #NEWLINE# num_transactions_in_scope = self . db . session . query ( models . Transaction ) . filter_by ( scope = True , target_id = target_id ) . count ( ) #NEWLINE# if int ( num_transactions_in_scope ) : #NEWLINE# #INDENT# match_percent = int ( ( ( num_matched_transactions / float ( num_transactions_in_scope ) ) * 100 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# match_percent = 0 #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# match_percent = None #NEWLINE# #UNINDENT# return [ regex_name , [ json . loads ( i ) for i in grep_outputs ] , transaction_ids , match_percent ]