support multiple queries and range queries

This commit is contained in:
Jeff Balogh 2011-06-27 17:19:00 -07:00
Родитель ff91fda65e
Коммит 8f6d83bb6c
2 изменённых файлов: 11 добавлений и 1 удалений

Просмотреть файл

@ -119,7 +119,7 @@ class ES(object):
qs['filter'] = filters[0]
if len(queries) > 1:
raise NotImplementedError()
qs['query'] = {'bool': {'must': queries}}
elif queries:
qs['query'] = queries[0]
@ -163,6 +163,8 @@ class ES(object):
rv.append({'term': {key: val}})
elif field_action == 'startswith':
rv.append({'prefix': {key: val}})
elif field_action in ('gt', 'gte', 'lt', 'lte'):
rv.append({'range': {key: {field_action: val}}})
return rv
def _do_search(self):

Просмотреть файл

@ -45,6 +45,14 @@ class TestES(amo.tests.ESTestCase):
eq_(qs._build_query(), {'fields': ['id'],
'query': {'term': {'type': 1}}})
def test_query_multiple_and_range(self):
qs = Addon.search().query(type=1, status__gte=1)
eq_(qs._build_query(), {'fields': ['id'],
'query': {'bool': {'must': [
{'term': {'type': 1}},
{'range': {'status': {'gte': 1}}},
]}}})
def test_order_by_desc(self):
qs = Addon.search().order_by('-rating')
eq_(qs._build_query(), {'fields': ['id'],