-
Notifications
You must be signed in to change notification settings - Fork 76
terms_stats facet type support #254
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1262,6 +1262,52 @@ def test_facet_date_histogram(self): | |
for item in qs.facet_counts()['created1']] | ||
eq_(sorted(facet_counts), [2, 3]) | ||
|
||
def test_facet_terms_stats(self): | ||
"""Test terms stats facet""" | ||
# FacetTest.create_index() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is commented out. Probably better to remove it if it shouldn't be here. |
||
FacetTest.index_data([ | ||
{'id': 1, "term_id":1, 'value': 1}, | ||
{'id': 2, "term_id":1, 'value': 1}, | ||
{'id': 3, "term_id":1, 'value': 1}, | ||
{'id': 4, "term_id":1, 'value': 2}, | ||
{'id': 5, "term_id":2, 'value': 2}, | ||
{'id': 6, "term_id":2, 'value': 3}, | ||
{'id': 7, "term_id":2, 'value': 3}, | ||
{'id': 8, "term_id":2, 'value': 3}, | ||
{'id': 9, "term_id":2, 'value': 4}, | ||
]) | ||
FacetTest.refresh() | ||
qs = (self.get_s() | ||
.facet_raw(created1={ | ||
'terms_stats': { | ||
"key_field": "term_id", | ||
"value_field": "value" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: You're switching between ' and ". Best to use ' for consistency. |
||
} | ||
}) | ||
) | ||
|
||
data = qs.facet_counts() | ||
first_term = data["created1"]["terms"][0] | ||
second_term = data["created1"]["terms"][1] | ||
eq_(first_term,{ | ||
u"term": 2, | ||
u"count": 5, | ||
u"total_count": 5, | ||
u"min": 2, | ||
u"max": 4, | ||
u"total": 15, | ||
u"mean": 3.0, | ||
}) | ||
eq_(second_term,{ | ||
u"term": 1, | ||
u"count": 4, | ||
u"total_count": 4, | ||
u"min": 1, | ||
u"max": 2, | ||
u"total": 5, | ||
u"mean": 1.25, | ||
}) | ||
|
||
def test_facet_statistical(self): | ||
"""Test statistical facet""" | ||
FacetTest.index_data([ | ||
|
@@ -1354,22 +1400,53 @@ def test_query_facet(self): | |
|
||
def test_invalid_field_type(self): | ||
"""Invalid _type should raise InvalidFacetType.""" | ||
a= {'elasticutilsmappingtype': {'properties': {'pin': {'properties': {'location': {'type': 'geo_point'}}}}}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Fix this per pep-8. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, it's best not to use one-character variable names. Rename this to something more helpful. |
||
FacetTest.put_mapping(mapping=a) | ||
FacetTest.index_data([ | ||
{'id': 1, 'age': 30}, | ||
{'id': 2, 'age': 40} | ||
{"id":1, | ||
"pin" : { | ||
"location" : { | ||
"lat" : 40.12, | ||
"lon" : -71.34 | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: The indentation for this is kind of all over the place. |
||
]) | ||
FacetTest.refresh() | ||
|
||
# Note: This uses a terms_stats facet. If we implement handling | ||
# Note: This uses a geo_distance facet. If we implement handling | ||
# for that, then we need to pick another facet type to fail on | ||
# or do the right thing and mock the test. | ||
# Note: Previously this used histogram and statistical facets, | ||
# Note: Previously this used histogram, statistical and terms_stats facets, | ||
# but those were implemented. | ||
with self.assertRaises(InvalidFacetType): | ||
(self.get_s() | ||
.facet_raw(created1={'terms_stats': {'key_field': 'age', | ||
'value_field': 'age'}}) | ||
.facet_raw(created1={ | ||
"geo_distance": { | ||
"pin.location": { | ||
"lat": 40, | ||
"lon": -70 | ||
}, | ||
"ranges": [ | ||
{ | ||
"to": 10 | ||
}, | ||
{ | ||
"from": 10, | ||
"to": 20 | ||
}, | ||
{ | ||
"from": 20, | ||
"to": 100 | ||
}, | ||
{ | ||
"from": 100 | ||
} | ||
] | ||
} | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pretty sure we added geo_distance, so we're going to need to make this something else. :p There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re: geo I think we're out of facets that aren't implemented, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly. If so, just comment this test out. |
||
.facet_counts()) | ||
FacetTest.mapping = {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this line do? |
||
|
||
|
||
class HighlightTest(ESTestCase): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need
put_mapping
unless we're incrementally building the index. If you look at other tests, they just wipe the index and add a new mapping or they set the mapping in the class attributes. Either one is better since it exists already.