当前位置: 首页>>代码示例>>Python>>正文


Python Addon.search方法代码示例

本文整理汇总了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'])
开发者ID:abdellah-bn,项目名称:olympia,代码行数:30,代码来源:test_search.py

示例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'}]})
开发者ID:Sancus,项目名称:zamboni,代码行数:11,代码来源:test_search.py

示例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}}])
开发者ID:callahad,项目名称:olympia,代码行数:11,代码来源:test_search.py

示例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]}}]}},
        )
开发者ID:rtilder,项目名称:zamboni,代码行数:11,代码来源:test_search.py

示例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]}}, ]})
开发者ID:srachit,项目名称:olympia,代码行数:11,代码来源:test_search.py

示例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}}})
开发者ID:Sancus,项目名称:zamboni,代码行数:11,代码来源:test_search.py

示例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}}]}]})
开发者ID:srachit,项目名称:olympia,代码行数:12,代码来源:test_search.py

示例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}}]}]},
            },
        )
开发者ID:rtilder,项目名称:zamboni,代码行数:14,代码来源:test_search.py

示例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]}},
                                ]}})
开发者ID:Sancus,项目名称:zamboni,代码行数:14,代码来源:test_search.py

示例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'])
开发者ID:abdellah-bn,项目名称:olympia,代码行数:15,代码来源:test_search.py

示例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}}]},
            ]})
开发者ID:srachit,项目名称:olympia,代码行数:16,代码来源:test_search.py

示例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}}]},
                                ]}})
开发者ID:Sancus,项目名称:zamboni,代码行数:17,代码来源:test_search.py

示例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}}},
                             ]}})
开发者ID:Sancus,项目名称:zamboni,代码行数:9,代码来源:test_search.py

示例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})
开发者ID:srachit,项目名称:olympia,代码行数:31,代码来源:views.py

示例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}}},
                             ]}}})
开发者ID:Sancus,项目名称:zamboni,代码行数:9,代码来源:test_search.py


注:本文中的addons.models.Addon.search方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。