@@ -8,7 +8,7 @@ class Result(object):
88 Represents the result of a search query, and has an array of Document objects
99 """
1010
11- def __init__ (self , res , hascontent , duration = 0 , has_payload = False ):
11+ def __init__ (self , res , hascontent , duration = 0 , has_payload = False , with_scores = False ):
1212 """
1313 - **snippets**: An optional dictionary of the form {field: snippet_size} for snippet formatting
1414 """
@@ -19,15 +19,20 @@ def __init__(self, res, hascontent, duration=0, has_payload = False):
1919
2020 step = 1
2121 if hascontent :
22- step = 3 if has_payload else 2
23- else :
24- # we can't have nocontent and payloads in the same response
25- has_payload = False
22+ step = step + 1
23+ if has_payload :
24+ step = step + 1
25+ if with_scores :
26+ step = step + 1
27+
28+ offset = 2 if with_scores else 1
2629
2730 for i in xrange (1 , len (res ), step ):
2831 id = to_string (res [i ])
29- payload = to_string (res [i + 1 ]) if has_payload else None
30- fields_offset = 2 if has_payload else 1
32+ payload = to_string (res [i + offset ]) if has_payload else None
33+ #fields_offset = 2 if has_payload else 1
34+ fields_offset = offset + 1 if has_payload else offset
35+ score = float (res [i + 1 ]) if with_scores else None
3136
3237 fields = {}
3338 if hascontent :
@@ -40,7 +45,7 @@ def __init__(self, res, hascontent, duration=0, has_payload = False):
4045 except KeyError :
4146 pass
4247
43- doc = Document (id , payload = payload , ** fields )
48+ doc = Document (id , score = score , payload = payload , ** fields ) if with_scores else Document ( id , payload = payload , ** fields )
4449 self .docs .append (doc )
4550
4651 def __repr__ (self ):
0 commit comments