Skip to content
Browse files

fixed simple relevant data for range queries

  • Loading branch information...
1 parent 6173c25 commit 874aa8c629807e42b12077f9ad7726a7d1592194 @brunovianarezende brunovianarezende committed Jan 19, 2012
Showing with 31 additions and 4 deletions.
  1. +4 −1 xappy/searchresults.py
  2. +27 −3 xappy/unittests/field_groups.py
View
5 xappy/searchresults.py
@@ -282,7 +282,10 @@ def _relevant_data_simple(self, allow, query, groupnumbers):
elif value <= end:
in_range = True
if in_range:
- relevant_items.setdefault(field, []).append((-1, 0))
+ # if we have multiple values for a field, xappy will always
+ # index the last value
+ offset = len(self.data[field]) - 1
+ relevant_items.setdefault(field, []).append((-1, offset))
field_scores[field] = field_scores.get(field, 0) + 1
# Build a list of the fields which match the query, counting the number
View
30 xappy/unittests/field_groups.py
@@ -43,6 +43,7 @@ def pre_test(self):
doc.extend((
('a', 'Africa America'),
('a', 'Uninteresting'),
+ ('h', '0.5'),
xappy.FieldGroup([('b', 'Andes America'), ('c', 'Arctic America')]),
('b', 'Notinteresting'),
('d', 'Australia'),
@@ -94,14 +95,14 @@ def post_test(self):
self.sconn.close()
def test_field_groups(self):
- """Test field groups for freetext fields.
+ """Test field groups.
"""
# Test internal representation of groups
id = list(self.sconn.iterids())[0]
doc = self.sconn.get_document(id)
self.assertEqual(doc._get_groups(),
- [(('b', 0), ('c', 0)), (('e', 0),), (('g', 0), ('h', 0)), (('j', 0), ('k', 0)), (('j', 0), ('k', 0))])
+ [(('b', 0), ('c', 0)), (('e', 0),), (('g', 0), ('h', 1)), (('j', 0), ('k', 0)), (('j', 0), ('k', 0))])
id = list(self.sconn.iterids())[1]
doc = self.sconn.get_document(id)
@@ -136,7 +137,7 @@ def test_field_groups(self):
'd': ['Australia'],
'g': ['Atlantic'],
'f': ['Ave'],
- 'h': ['1.0'],
+ 'h': ['0.5', '1.0'],
'j': ['Same value'],
'k': ['Same value 2']})
self.assertEqual(results[0].grouped_data,
@@ -145,6 +146,7 @@ def test_field_groups(self):
'b': ['Notinteresting'],
'd': ['Australia'],
'f': ['Ave'],
+ 'h': ['0.5'],
},
[{
'b': ['Andes America'],
@@ -174,6 +176,7 @@ def test_field_groups(self):
'b': ['Notinteresting'],
'd': ['Australia'],
'f': ['Ave'],
+ 'h': ['0.5'],
},
0: {
'b': ['Andes America'],
@@ -258,5 +261,26 @@ def test_field_groups(self):
('a', (('Africa America', None),)),
))
+ # test relevant_data for range queries
+ q = self.sconn.query_facet('h', ('0.9', '1.1'))
+ results = q.search(0, 10)
+
+ self.assertEqual(results[0].relevant_data(simple=False),
+ (('h', ('1.0',)),
+ ))
+
+ self.assertEqual(results[0].relevant_data(simple=False,
+ groupnumbers=True),
+ (('h', (('1.0', 2),)),
+ ))
+
+ self.assertEqual(results[0].relevant_data(),
+ (('h', ('1.0',)),
+ ))
+
+ self.assertEqual(results[0].relevant_data(groupnumbers=True),
+ (('h', (('1.0', 2),)),
+ ))
+
if __name__ == '__main__':
main()

0 comments on commit 874aa8c

Please sign in to comment.
Something went wrong with that request. Please try again.