#NEWLINE# @ classmethod #NEWLINE# def search( cls , phrase , index = None , ranking = 'bm25' , ordering = None , **filters ) : #NEWLINE# #INDENT# query = Document . search ( phrase , index , ranking , ordering , ** filters ) #NEWLINE# query = query . select ( Document . _meta . primary_key . alias ( 'document_id' ) , Document . identifier , Attachment . id , Attachment . hash , Attachment . filename , Attachment . mimetype , Attachment . timestamp ) . switch ( Document ) . join ( Attachment , on = ( Document . _meta . primary_key == Attachment . document ) ) #NEWLINE# return Attachment . apply_rank_and_sort ( query , ranking , ( ordering or ( ) ) )