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


Python QuerySet.count方法代码示例

本文整理汇总了Python中pyeqs.QuerySet.count方法的典型用法代码示例。如果您正苦于以下问题:Python QuerySet.count方法的具体用法?Python QuerySet.count怎么用?Python QuerySet.count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyeqs.QuerySet的用法示例。


在下文中一共展示了QuerySet.count方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_queryset_iteration_with_no_results

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import count [as 别名]
def test_queryset_iteration_with_no_results():
    """
    Fetch results with QuerySet via __iter__ with no results
    """

    # When I create a query block
    t = QuerySet("foobar", index="bar")
    wrapper = lambda y: list(map(lambda x: x['_id'], y))
    t.wrappers(wrapper)

    # And I have no records
    response = {
       "took": 12,
       "hits": {
          "total": 0,
          "max_score": 0,
          "hits": []
       }
    }
    httpretty.register_uri(httpretty.GET, "http://foobar:9200/bar/_search",
                       body=json.dumps(response),
                       content_type="application/json")

    results = []
    for result in t:
        results.append(result)
    len(results).should.equal(0)
    t.count().should.equal(0)
开发者ID:jpatel3,项目名称:pyeqs,代码行数:30,代码来源:test_queryset.py

示例2: test_search_with_iterator

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import count [as 别名]
def test_search_with_iterator(context):
    """
    Search using an iterator
    """
    # When create a queryset
    t = QuerySet("localhost", index="foo")

    # And set iterator fetching to a small size
    t._per_request = 2

    # And there are records
    add_document("foo", {"bar": 0})
    add_document("foo", {"bar": 1})
    add_document("foo", {"bar": 2})
    add_document("foo", {"bar": 3})
    add_document("foo", {"bar": 4})

    # And I do a filter on my new object

    # And a different filter on my old object
    t.order_by(Sort("bar", order="asc"))

    # Then I get the expected results
    for (counter, result) in enumerate(t):
        result['_source'].should.equal({"bar": counter})

    len(t).should.equal(5)
    t.count().should.equal(5)
开发者ID:jpatel3,项目名称:pyeqs,代码行数:30,代码来源:test_queryset.py

示例3: test_queryset_count

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import count [as 别名]
def test_queryset_count():
    """
    Get QuerySet Count
    """
    # When I create a query block
    t = QuerySet("foobar")

    # Then I get an appropriate Count
    t.count().should.equal(None)
开发者ID:jpatel3,项目名称:pyeqs,代码行数:11,代码来源:test_queryset.py

示例4: test_queryset_getitem_with_post_query_action

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import count [as 别名]
def test_queryset_getitem_with_post_query_action():
    """
    Fetch from QuerySet with __getitem__ and post query action
    """
    # When I create a query block
    t = QuerySet("localhost", index="bar")

    # And I have a post query action
    global my_global_var
    my_global_var = 1

    def action(self, results, start, stop):
        global my_global_var
        my_global_var += 1

    t.post_query_actions(action)

    # And I have records
    response = {
        "took": 12,
        "timed_out": False,
        "_shards": {
            "total": 5,
            "successful": 5,
            "failed": 0
        },
        "hits": {
            "total": 1,
            "max_score": 10,
            "hits": [
                {
                    "_index": "bar",
                    "_type": "baz",
                    "_id": "1",
                    "_score": 10,
                    "_source": {
                        "foo": "bar"
                    },
                    "sort": [
                        1395687078000
                    ]
                }
            ]
        }
    }
    httpretty.register_uri(httpretty.GET, "http://localhost:9200/bar/_search",
                       body=json.dumps(response),
                       content_type="application/json")

    results = t[0:1]
    len(results).should.equal(1)
    t.count().should.equal(1)

    # Then I see the correct results
    results[0]['_id'].should.equal('1')
    my_global_var.should.equal(2)
开发者ID:Yipit,项目名称:pyeqs,代码行数:58,代码来源:test_queryset.py

示例5: test_queryset_iteration

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import count [as 别名]
def test_queryset_iteration():
    """
    Fetch results with QuerySet via __iter__
    """

    # When I create a query block
    t = QuerySet("foobar", index="bar")
    wrapper = lambda y: list(map(lambda x: x['_id'], y))
    t.wrappers(wrapper)

    # And I have a record
    response = {
       "took": 12,
       "hits": {
          "total": 1,
          "max_score": 10,
          "hits": [
             {
                "_index": "bar",
                "_type": "baz",
                "_id": "1",
                "_score": 10,
                "_source": {
                   "foo": "bar"
                },
                "sort": [
                   1395687078000
                ]
             }
          ]
       }
    }
    httpretty.register_uri(httpretty.GET, "http://foobar:9200/bar/_search",
                       body=json.dumps(response),
                       content_type="application/json")

    results = []
    for result in t:
        results.append(result)
    len(results).should.equal(1)
    len(t).should.equal(1)
    t.count().should.equal(1)
开发者ID:jpatel3,项目名称:pyeqs,代码行数:44,代码来源:test_queryset.py

示例6: test_queryset_getitem_multiple

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import count [as 别名]
def test_queryset_getitem_multiple():
    """
    Fetch from QuerySet with __getitem__ multiple times
    """
    # When I create a query block
    t = QuerySet("localhost", index="bar")
    wrapper = lambda y: list(map(lambda x: x['_id'], y))
    t.wrappers(wrapper)
    # And I have a record
    response = {
       "took": 12,
       "hits": {
          "total": 1,
          "max_score": 10,
          "hits": [
             {
                "_index": "bar",
                "_type": "baz",
                "_id": "1",
                "_score": 10,
                "_source": {
                   "foo": "bar"
                },
                "sort": [
                   1395687078000
                ]
             }
          ]
       }
    }
    httpretty.register_uri(httpretty.GET, "http://localhost:9200/bar/_search",
                       body=json.dumps(response),
                       content_type="application/json")

    results = t[0:1]
    len(results).should.equal(1)
    t.count().should.equal(1)

    results = t[0:1]
    len(results).should.equal(1)
    t.count().should.equal(1)
开发者ID:jpatel3,项目名称:pyeqs,代码行数:43,代码来源:test_queryset.py

示例7: test_queryset_iteration_with_multiple_cache_fetches

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import count [as 别名]
def test_queryset_iteration_with_multiple_cache_fetches():
    """
    Fetch results with QuerySet via __iter__ with multiple cache fetches
    """

    # When I create a query block
    t = QuerySet("foobar", index="bar")
    wrapper = lambda y: list(map(lambda x: x['_id'], y))
    t.wrappers(wrapper)

    # And we lower the per request to force multiple fetches
    t._per_request = 2

    # And I have records
    first_response = {
       "took": 12,
       "hits": {
          "total": 3,
          "max_score": 10,
          "hits": [
             {
                "_index": "bar",
                "_type": "baz",
                "_id": "1",
                "_score": 10,
                "_source": {
                   "foo": "bar"
                },
                "sort": [
                   1395687078000
                ]
             },
             {
                "_index": "bar",
                "_type": "baz",
                "_id": "2",
                "_score": 10,
                "_source": {
                   "foo": "barbar"
                },
                "sort": [
                   1395687078000
                ]
             }
          ]
       }
    }

    second_response = {
       "took": 12,
       "hits": {
          "total": 3,
          "max_score": 10,
          "hits": [
             {
                "_index": "bar",
                "_type": "baz",
                "_id": "3",
                "_score": 10,
                "_source": {
                   "foo": "barbarbar"
                },
                "sort": [
                   1395687078000
                ]
             }
          ]
       }
    }
    httpretty.register_uri(httpretty.GET, "http://foobar:9200/bar/_search",
                        responses=[
                           httpretty.Response(body=json.dumps(first_response), content_type="application/json"),
                           httpretty.Response(body=json.dumps(second_response), content_type="application/json"),
                        ])

    # Then I should eventually get all records
    results = []
    for result in t:
        results.append(result)
    len(results).should.equal(3)
    t.count().should.equal(3)
    results[0].should.equal("1")
    results[1].should.equal("2")
    results[2].should.equal("3")
开发者ID:jpatel3,项目名称:pyeqs,代码行数:86,代码来源:test_queryset.py


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