<s> import os <EOL> class QueryResult ( object ) : <EOL> def __init__ ( self , hits = None , truncated = False ) : <EOL> if hits : <EOL> self . _filenames = [ x [ <NUM_LIT:0> ] for x in hits ] <EOL> self . _ranks = [ x [ <NUM_LIT:1> ] for x in hits ] <EOL> else : <EOL> self . _filenames = [ ] <EOL> self . _ranks = [ ] <EOL> self . truncated = truncated <EOL> self . debug_info = [ ] <EOL> def as_dict ( self ) : <EOL> return { "<STR_LIT>" : list ( self . hits ) , <EOL> "<STR_LIT>" : self . truncated , <EOL> "<STR_LIT>" : self . debug_info } <EOL> @ staticmethod <EOL> def from_dict ( d ) : <EOL> r = QueryResult ( ) <EOL> r . _filenames = [ x [ <NUM_LIT:0> ] for x in d [ "<STR_LIT>" ] ] <EOL> r . _ranks = [ x [ <NUM_LIT:1> ] for x in d [ "<STR_LIT>" ] ] <EOL> r . truncated = d [ "<STR_LIT>" ] <EOL> r . debug_info = d [ "<STR_LIT>" ] <EOL> return r <EOL> def is_empty ( self ) : <EOL> return len ( self . filenames ) == <NUM_LIT:0> <EOL> @ property <EOL> def filenames ( self ) : <EOL> return self . _filenames <EOL> @ property <EOL> def ranks ( self ) : <EOL> return self . _ranks <EOL> @ property <EOL> def hits ( self ) : <EOL> for i in range ( len ( self . filenames ) ) : <EOL> yield ( self . filenames [ i ] , self . ranks [ i ] ) <EOL> def get_copy_with_max_hits ( self , max_hits ) : <EOL> return QueryResult ( hits = list ( self . hits ) [ : max_hits ] , truncated = self . truncated ) <EOL> def rank_of ( self , filename ) : <EOL> for i in range ( len ( self . filenames ) ) : <EOL> if self . filenames [ i ] == filename : <EOL> return self . ranks [ i ] <EOL> raise Exception ( "<STR_LIT>" % filename ) </s>
