Skip to content

Commit

Permalink
fixed simple relevant data for range queries
Browse files Browse the repository at this point in the history
  • Loading branch information
brunovianarezende committed Jan 19, 2012
1 parent 6173c25 commit 874aa8c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
5 changes: 4 additions & 1 deletion xappy/searchresults.py
Expand Up @@ -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
Expand Down
30 changes: 27 additions & 3 deletions xappy/unittests/field_groups.py
Expand Up @@ -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'),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -145,6 +146,7 @@ def test_field_groups(self):
'b': ['Notinteresting'],
'd': ['Australia'],
'f': ['Ave'],
'h': ['0.5'],
},
[{
'b': ['Andes America'],
Expand Down Expand Up @@ -174,6 +176,7 @@ def test_field_groups(self):
'b': ['Notinteresting'],
'd': ['Australia'],
'f': ['Ave'],
'h': ['0.5'],
},
0: {
'b': ['Andes America'],
Expand Down Expand Up @@ -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.