#NEWLINE# @ scenario ( prepare_data , cleanup_data ) #NEWLINE# def test_search_with_filter_and_scoring( context ) : #NEWLINE# #INDENT# '\n    Search with match_all query, filter and scoring\n    ' #NEWLINE# t = QuerySet ( 'localhost' , index = 'foo' ) #NEWLINE# add_document ( 'foo' , { #NEWLINE# #INDENT# 'bar' : 'baz' , #NEWLINE# 'scoring_field' : 1 , #NEWLINE# #UNINDENT# } ) #NEWLINE# add_document ( 'foo' , { #NEWLINE# #INDENT# 'bar' : 'baz' , #NEWLINE# 'scoring_field' : 2 , #NEWLINE# #UNINDENT# } ) #NEWLINE# add_document ( 'foo' , { #NEWLINE# #INDENT# 'bar' : 'bazbaz' , #NEWLINE# 'scoring_field' : 3 , #NEWLINE# #UNINDENT# } ) #NEWLINE# t . filter ( Term ( 'bar' , 'baz' ) ) #NEWLINE# score = ScriptScore ( "final_score = 0 + doc['scoring_field'].value;" ) #NEWLINE# t . score ( score ) #NEWLINE# results = score [ 0 : 10 ] #NEWLINE# len ( results ) . should . equal ( 2 ) #NEWLINE# results [ 0 ] [ '_source' ] . should . equal ( { #NEWLINE# #INDENT# 'bar' : 'baz' , #NEWLINE# 'scoring_field' : 2 , #NEWLINE# #UNINDENT# } ) #NEWLINE# results [ 1 ] [ '_source' ] . should . equal ( { #NEWLINE# #INDENT# 'bar' : 'baz' , #NEWLINE# 'scoring_field' : 1 , #NEWLINE# #UNINDENT# } )