#NEWLINE# def FillFacetResponse( self , results , response ) : #NEWLINE# #INDENT# 'Extract facet results and add them to the response.\n\n    This method goes through all facets and add aggregated facet information to\n    the search response according to facet request parameters.\n\n    Args:\n      results: Search Query result set.\n      response: Search Query response protocol buffer objects. Facet results\n        will be added to this response.\n    Raises:\n      ValueError: if a facet type is invalid or facet request has invalid\n        values.\n    ' #NEWLINE# if ( ( not self . _params . include_facet_list ( ) ) and ( not self . _params . auto_discover_facet_count ( ) ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# self . _PreprocessManualFacets ( ) #NEWLINE# self . _discovered_facets = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for result in results [ : self . _params . facet_depth ( ) ] : #NEWLINE# #INDENT# for facet in result . document . facet_list ( ) : #NEWLINE# #INDENT# if ( facet . value ( ) . type ( ) == document_pb . FacetValue . ATOM ) : #NEWLINE# #INDENT# self . _ProcessAtomFacet ( facet ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( facet . value ( ) . type ( ) == document_pb . FacetValue . NUMBER ) : #NEWLINE# #INDENT# self . _ProcessNumberFacet ( facet ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( ( 'Facet type %d is not supported' % facet . value ( ) . type ( ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# for facet in self . _manual_facets . values ( ) : #NEWLINE# #INDENT# self . _FillResponseForSingleFacet ( facet , response . add_facet_result ( ) ) #NEWLINE# #UNINDENT# for facet in _GetTopN ( self . _discovered_facets . values ( ) , self . _params . auto_discover_facet_count ( ) ) : #NEWLINE# #INDENT# self . _FillResponseForSingleFacet ( facet , response . add_facet_result ( ) )