本文整理汇总了Python中addons.models.Addon.search方法的典型用法代码示例。如果您正苦于以下问题:Python Addon.search方法的具体用法?Python Addon.search怎么用?Python Addon.search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类addons.models.Addon
的用法示例。
在下文中一共展示了Addon.search方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_filter_or
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import search [as 别名]
def test_filter_or(self):
qs = Addon.search().filter(type=1).filter(or_=dict(status=1, app=2))
filters = qs._build_query()['query']['filtered']['filter']
# Filters:
# {'and': [
# {'term': {'type': 1}},
# {'or': [{'term': {'status': 1}}, {'term': {'app': 2}}]},
# ]}
eq_(filters.keys(), ['and'])
ok_({'term': {'type': 1}} in filters['and'])
or_clause = sorted(filters['and'])[0]
eq_(or_clause.keys(), ['or'])
ok_({'term': {'status': 1}} in or_clause['or'])
ok_({'term': {'app': 2}} in or_clause['or'])
qs = Addon.search().filter(type=1, or_=dict(status=1, app=2))
filters = qs._build_query()['query']['filtered']['filter']
# Filters:
# {'and': [
# {'term': {'type': 1}},
# {'or': [{'term': {'status': 1}}, {'term': {'app': 2}}]},
# ]}
eq_(filters.keys(), ['and'])
ok_({'term': {'type': 1}} in filters['and'])
or_clause = sorted(filters['and'])[0]
eq_(or_clause.keys(), ['or'])
ok_({'term': {'status': 1}} in or_clause['or'])
ok_({'term': {'app': 2}} in or_clause['or'])
示例2: test_extra_order_by
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import search [as 别名]
def test_extra_order_by(self):
qs = Addon.search().extra(order_by=['-rating'])
eq_(qs._build_query(), {'fields': ['id'],
'sort': [{'rating': 'desc'}]})
qs = Addon.search().order_by('-id').extra(order_by=['-rating'])
eq_(qs._build_query(), {'fields': ['id'],
'sort': [{'id': 'desc'},
{'rating': 'desc'}]})
示例3: test_extra_query
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import search [as 别名]
def test_extra_query(self):
qs = Addon.search().extra(query={'type': 1})
eq_(qs._build_query()['query']['function_score']['query'],
{'term': {'type': 1}})
qs = Addon.search().filter(status=1).extra(query={'type': 1})
filtered = qs._build_query()['query']['filtered']
eq_(filtered['query']['function_score']['query'], {'term': {'type': 1}})
eq_(filtered['filter'], [{'term': {'status': 1}}])
示例4: test_extra_filter
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import search [as 别名]
def test_extra_filter(self):
qs = Addon.search().extra(filter={"category__in": [1, 2]})
eq_(qs._build_query(), {"fields": ["id"], "filter": {"in": {"category": [1, 2]}}})
qs = Addon.search().filter(type=1).extra(filter={"category__in": [1, 2]})
eq_(
qs._build_query(),
{"fields": ["id"], "filter": {"and": [{"term": {"type": 1}}, {"in": {"category": [1, 2]}}]}},
)
示例5: test_extra_filter
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import search [as 别名]
def test_extra_filter(self):
qs = Addon.search().extra(filter={'category__in': [1, 2]})
eq_(qs._build_query()['query']['filtered']['filter'],
[{'in': {'category': [1, 2]}}])
qs = (Addon.search().filter(type=1)
.extra(filter={'category__in': [1, 2]}))
eq_(qs._build_query()['query']['filtered']['filter'],
{'and': [{'term': {'type': 1}}, {'in': {'category': [1, 2]}}, ]})
示例6: test_extra_query
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import search [as 别名]
def test_extra_query(self):
qs = Addon.search().extra(query={'type': 1})
eq_(qs._build_query(), {'fields': ['id'],
'query': {'term': {'type': 1}}})
qs = Addon.search().filter(status=1).extra(query={'type': 1})
eq_(qs._build_query(), {'fields': ['id'],
'query': {'term': {'type': 1}},
'filter': {'term': {'status': 1}}})
示例7: test_extra_filter_or
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import search [as 别名]
def test_extra_filter_or(self):
qs = Addon.search().extra(filter={'or_': {'status': 1, 'app': 2}})
eq_(qs._build_query()['query']['filtered']['filter'],
[{'or': [{'term': {'status': 1}}, {'term': {'app': 2}}]}])
qs = (Addon.search().filter(type=1)
.extra(filter={'or_': {'status': 1, 'app': 2}}))
eq_(qs._build_query()['query']['filtered']['filter'],
{'and': [{'term': {'type': 1}},
{'or': [{'term': {'status': 1}}, {'term': {'app': 2}}]}]})
示例8: test_extra_filter_or
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import search [as 别名]
def test_extra_filter_or(self):
qs = Addon.search().extra(filter={"or_": {"status": 1, "app": 2}})
eq_(qs._build_query(), {"fields": ["id"], "filter": {"or": [{"term": {"status": 1}}, {"term": {"app": 2}}]}})
qs = Addon.search().filter(type=1).extra(filter={"or_": {"status": 1, "app": 2}})
eq_(
qs._build_query(),
{
"fields": ["id"],
"filter": {"and": [{"term": {"type": 1}}, {"or": [{"term": {"status": 1}}, {"term": {"app": 2}}]}]},
},
)
示例9: test_extra_filter
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import search [as 别名]
def test_extra_filter(self):
qs = Addon.search().extra(filter={'category__in': [1, 2]})
eq_(qs._build_query(), {'fields': ['id'],
'filter': {'in': {'category': [1, 2]}}})
qs = (Addon.search().filter(type=1)
.extra(filter={'category__in': [1, 2]}))
eq_(qs._build_query(), {'fields': ['id'],
'filter': {'and': [
{'term': {'type': 1}},
{'in': {'category': [1, 2]}},
]}})
示例10: test_extra_filter
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import search [as 别名]
def test_extra_filter(self):
qs = Addon.search().extra(filter={'category__in': [1, 2]})
eq_(qs._build_query()['query']['filtered']['filter'],
[{'in': {'category': [1, 2]}}])
qs = (Addon.search().filter(type=1)
.extra(filter={'category__in': [1, 2]}))
filters = qs._build_query()['query']['filtered']['filter']
# Filters:
# {'and': [{'term': {'type': 1}}, {'in': {'category': [1, 2]}}, ]}
eq_(filters.keys(), ['and'])
ok_({'term': {'type': 1}} in filters['and'])
ok_({'in': {'category': [1, 2]}} in filters['and'])
示例11: test_filter_or
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import search [as 别名]
def test_filter_or(self):
qs = Addon.search().filter(type=1).filter(or_=dict(status=1, app=2))
eq_(qs._build_query()['query']['filtered']['filter'],
{'and': [
{'term': {'type': 1}},
{'or': [{'term': {'status': 1}}, {'term': {'app': 2}}]},
]})
qs = Addon.search().filter(type=1, or_=dict(status=1, app=2))
eq_(qs._build_query()['query']['filtered']['filter'],
{'and': [
{'term': {'type': 1}},
{'or': [{'term': {'status': 1}}, {'term': {'app': 2}}]},
]})
示例12: test_extra_filter_or
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import search [as 别名]
def test_extra_filter_or(self):
qs = Addon.search().extra(filter={'or_': {'status': 1, 'app': 2}})
eq_(qs._build_query(), {'fields': ['id'],
'filter': {'or': [
{'term': {'status': 1}},
{'term': {'app': 2}}]}})
qs = (Addon.search().filter(type=1)
.extra(filter={'or_': {'status': 1, 'app': 2}}))
eq_(qs._build_query(), {'fields': ['id'],
'filter': {'and': [
{'term': {'type': 1}},
{'or': [{'term': {'status': 1}},
{'term': {'app': 2}}]},
]}})
示例13: test_gt
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import search [as 别名]
def test_gt(self):
qs = Addon.search().filter(type__in=[1, 2], status__gt=4)
eq_(qs._build_query(), {'fields': ['id'],
'filter': {'and': [
{'in': {'type': [1, 2]}},
{'range': {'status': {'gt': 4}}},
]}})
示例14: es_extensions
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import search [as 别名]
def es_extensions(request, category=None, template=None):
TYPE = amo.ADDON_EXTENSION
if category is not None:
q = Category.objects.filter(application=request.APP.id, type=TYPE)
category = get_object_or_404(q, slug=category)
if ('sort' not in request.GET and not request.MOBILE
and category and category.count > 4):
return category_landing(request, category)
qs = (Addon.search().filter(type=TYPE, app=request.APP.id,
is_disabled=False,
status__in=amo.REVIEWED_STATUSES))
filter = ESAddonFilter(request, qs, key='sort', default='popular')
qs, sorting = filter.qs, filter.field
src = 'cb-btn-%s' % sorting
dl_src = 'cb-dl-%s' % sorting
if category:
qs = qs.filter(category=category.id)
addons = amo.utils.paginate(request, qs)
return render(request, template,
{'section': 'extensions', 'addon_type': TYPE,
'category': category, 'addons': addons,
'filter': filter, 'sorting': sorting,
'sort_opts': filter.opts, 'src': src,
'dl_src': dl_src, 'search_cat': '%s,0' % TYPE})
示例15: test_query_or
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import search [as 别名]
def test_query_or(self):
qs = Addon.search().query(or_=dict(type=1, status__gte=2))
eq_(qs._build_query(), {'fields': ['id'],
'query': {'bool': {'should': [
{'term': {'type': 1}},
{'range': {'status': {'gte': 2}}},
]}}})