#NEWLINE# def _MatchSingleFacetRefinement( self , doc_facet , refinement ) : #NEWLINE# #INDENT# 'Matches a single document facet with a single refinement.' #NEWLINE# if refinement . has_value ( ) : #NEWLINE# #INDENT# if refinement . has_range ( ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Refinement request for facet %s should either specify range or value constraint, not both.' % refinement . name ( ) ) ) #NEWLINE# #UNINDENT# facet_value = doc_facet . value ( ) . string_value ( ) #NEWLINE# if ( doc_facet . value ( ) . type ( ) == document_pb . FacetValue . NUMBER ) : #NEWLINE# #INDENT# return ( float ( facet_value ) == float ( refinement . value ( ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( facet_value == refinement . value ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not refinement . has_range ( ) ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Refinement request for facet %s should specify range or value constraint.' % refinement . name ( ) ) ) #NEWLINE# #UNINDENT# if ( doc_facet . value ( ) . type ( ) != document_pb . FacetValue . NUMBER ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# facet_value = float ( doc_facet . value ( ) . string_value ( ) ) #NEWLINE# ref_range = refinement . range ( ) #NEWLINE# start = ( float ( ref_range . start ( ) ) if ref_range . has_start ( ) else None ) #NEWLINE# end = ( float ( ref_range . end ( ) ) if ref_range . has_end ( ) else None ) #NEWLINE# return ( ( ( start is None ) or ( facet_value >= start ) ) and ( ( end is None ) or ( facet_value < end ) ) )