本文整理汇总了Python中pyeqs.QuerySet.post_query_actions方法的典型用法代码示例。如果您正苦于以下问题:Python QuerySet.post_query_actions方法的具体用法?Python QuerySet.post_query_actions怎么用?Python QuerySet.post_query_actions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyeqs.QuerySet
的用法示例。
在下文中一共展示了QuerySet.post_query_actions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_post_query_actions
# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import post_query_actions [as 别名]
def test_post_query_actions(context):
"""
Search with match_all query with post query actions
"""
# When create a queryset
t = QuerySet("localhost", index="foo")
# And there are records
add_document("foo", {"bar": 1})
add_document("foo", {"bar": 2})
add_document("foo", {"bar": 3})
# 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 do a search
t.order_by(Sort("bar", order="asc"))
results = t[0:10]
# Then I get a the expected results
len(results).should.equal(3)
results[0]["_source"]["bar"].should.equal(1)
results[1]["_source"]["bar"].should.equal(2)
results[2]["_source"]["bar"].should.equal(3)
my_global_var.should.equal(2)
示例2: test_queryset_getitem_with_post_query_action
# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import post_query_actions [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)