• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python pyeqs.QuerySet类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_post_query_actions

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)
开发者ID:Yipit,项目名称:pyeqs,代码行数:32,代码来源:test_queryset.py


示例2: test_create_queryset_with_filters

def test_create_queryset_with_filters():
    """
    Create QuerySet with Multiple Filters
    """
    # When create a query block
    t = QuerySet("foobar")

    # And I add a filter
    t.filter(Term("foo", "bar"))
    t.filter(Term("foobar", "foobar"))

    # Then I see the appropriate JSON
    results = {
        "query": {
            "filtered": {
                "query": {"match_all": {}},
                "filter": {
                    "and": [
                        {
                            "term": {
                                "foo": "bar"
                            }
                        },
                        {
                            "term": {
                                "foobar": "foobar"
                            }
                        }
                    ]
                }
            }
        }
    }

    homogeneous(t._query, results)
开发者ID:jpatel3,项目名称:pyeqs,代码行数:35,代码来源:test_queryset.py


示例3: test_search_multiple_scoring

def test_search_multiple_scoring(context):
    """
    Search with custom scoring and params
    """
    # When create a query block
    t = QuerySet("localhost", index="foo")

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

    # And I add scoring with params
    score = ScriptScore("s = custom_param + doc['bar'].value", params={"custom_param": 1})
    t.score(score)

    boost = {
        "boost_factor": "10",
        "filter": Exists("baz")
    }
    t.score(boost)
    results = t[0:10]

    # Then my results are scored correctly
    len(results).should.equal(2)
    results[0]["_source"]["baz"].should.equal(4)
    ("baz" in results[1]["_source"].keys()).should.be.false
开发者ID:Yipit,项目名称:pyeqs,代码行数:26,代码来源:test_score.py


示例4: test_create_queryset_with_multiple_sorting

def test_create_queryset_with_multiple_sorting():
    """
    Create QuerySet with Multiple Sorting
    """
    # When create a query block
    t = QuerySet("foobar")

    # And I add sorting
    s = Sort("_id", order="asc")
    t.order_by(s)

    ss = Sort("_id", order="desc")
    t.order_by(ss)

    # Then I see the appropriate JSON
    results = {
        "sort": [
            {
                "_id": {
                    "order": "asc"
                }
            },
            {
                "_id": {
                    "order": "desc"
                }
            }
        ],
        "query": {
            "match_all": {}
        }
    }

    homogeneous(t._query, results)
开发者ID:jpatel3,项目名称:pyeqs,代码行数:34,代码来源:test_queryset.py


示例5: test_wrappers

def test_wrappers(context):
    """
    Search with wrapped match_all query
    """
    # 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 do a search
    def wrapper_function(search_results):
        return map(lambda x: x["_source"]["bar"] + 1, search_results)

    t.wrappers(wrapper_function)
    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].should.equal(2)
    results[1].should.equal(3)
    results[2].should.equal(4)
开发者ID:sunchen009,项目名称:pyeqs,代码行数:25,代码来源:test_queryset.py


示例6: test_create_queryset_with_scoring

def test_create_queryset_with_scoring():
    """
    Create QuerySet with Scoring, Minimum Score and Track Scores
    """
    # When create a query block
    t = QuerySet("foobar")

    # And I add scoring
    s = ScriptScore("foo = 0.0")
    t.score(s, min_score=0, track_scores=True)

    # Then I see the appropriate JSON
    results = {
        "min_score": 0,
        "track_scores": True,
        "query": {
            "function_score": {
                "functions": [
                    {
                        "script_score": {
                            "script": "foo = 0.0"
                        }
                    }
                ],
                "query": {"match_all": {}},
                "boost_mode": "replace",
                "score_mode": "multiply"
            }
        }
    }

    homogeneous(t._query, results)
开发者ID:jpatel3,项目名称:pyeqs,代码行数:32,代码来源:test_queryset.py


示例7: test_search_global_aggregations

def test_search_global_aggregations(context):
    """
    Search with global aggregations
    """
    # With a specific query
    # q = QueryBuilder(query_string=QueryString(query={"match": {"foo_attr": "yes"}}))

    # When create a query block
    t = QuerySet("localhost", index="foo")

    # And there are records
    add_document("foo", {"bar": "baz", "foo_attr": "yes"})
    add_document("foo", {"bar": "bazbaz", "foo_attr": "no"})
    add_document("foo", {"bar": "bazbaz"})

    # And I do a global
    t.aggregate(aggregation=Aggregations("foo_attrs", "bar", "terms", global_name="all_bar"))
    t[0:10]

    # I get the expected results
    t.aggregations().should.have.key("all_bar").being.equal({
        u'foo_attrs': {u'buckets': [
            {u'key': u'bazbaz', u'doc_count': 2},
            {u'key': u'baz', u'doc_count': 1}
        ]},
        u'doc_count': 3})
开发者ID:Yipit,项目名称:pyeqs,代码行数:26,代码来源:test_aggregations.py


示例8: test_search_nested_terms_aggregations_with_size

def test_search_nested_terms_aggregations_with_size(context):
    """
    Search with nested terms aggregation and a specified size
    """
    # When create a query block
    t = QuerySet("localhost", index="foo")

    # And there are nested records
    add_document("foo", {"child": [{"stuff": "yep", "bazbaz": "type0"}], "foo": "foo"})
    add_document("foo", {"child": [{"stuff": "yep", "bazbaz": "type0"}], "foo": "foo"})
    add_document("foo", {"child": [{"stuff": "nope", "bazbaz": "type1"}], "foo": "foofoo"})
    add_document("foo", {"child": [{"stuff": "nope", "bazbaz": "type2"}], "foo": "foofoo"})

    # And I do a nested
    t.aggregate(aggregation=Aggregations("baz_types", "bazbaz", "terms",
                                         nested_path="child", size=1))
    t[0:10]

    # The I get the expected results
    t.aggregations().should.have.key("child").being.equal({
        u'baz_types': {
            u'buckets': [{u'doc_count': 2, u'key': u'type0'}]
        },
        u'doc_count': 4
    })
开发者ID:Yipit,项目名称:pyeqs,代码行数:25,代码来源:test_aggregations.py


示例9: test_queryset_iteration_with_no_results

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,代码行数:28,代码来源:test_queryset.py


示例10: test_create_queryset_with_multiple_scoring

def test_create_queryset_with_multiple_scoring():
    """
    Create QuerySet with Multiple Scoring
    """
    # When create a query block
    t = QuerySet("foobar")

    # And I add scoring
    s = ScriptScore("foo = 0.0")
    t.score(s)

    # And I add more scoring
    ss = ScriptScore("foo = 1.0")
    t.score(ss)

    # Then I see the appropriate JSON
    results = {
        "query": {
            "function_score": {
                "query": {"match_all": {}},
                "script_score": {
                    "script": "foo = 1.0"
                },
                "boost_mode": "replace"
            }
        }
    }

    homogeneous(t._query, results)
开发者ID:mengjues,项目名称:pyeqs,代码行数:29,代码来源:test_queryset.py


示例11: test_queryset_count

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,代码行数:9,代码来源:test_queryset.py


示例12: test_queryset_max_score

def test_queryset_max_score():
    """
    Get QuerySet Max Score
    """
    # When I create a query block
    t = QuerySet("foobar")

    # Then I get an appropriate max score
    t.max_score().should.equal(None)
开发者ID:Yipit,项目名称:pyeqs,代码行数:9,代码来源:test_queryset.py


示例13: test_queryset_getitem_with_post_query_action

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,代码行数:56,代码来源:test_queryset.py


示例14: test_search_with_filter_and_scoring_and_sorting_and_fields

def test_search_with_filter_and_scoring_and_sorting_and_fields(context):
    """
    Search with match_all query, filter, scoring, sorting, and fields
    """
    # When create a queryset
    t = QuerySet("localhost", index="foo")

    # And there are records
    add_document("foo", {"bar": "baz", "scoring_field": 0, "sorting_field": 30})
    add_document("foo", {"bar": "baz", "scoring_field": 1, "sorting_field": 20})
    add_document("foo", {"bar": "baz", "scoring_field": 2, "sorting_field": 10})
    add_document("foo", {"bar": "bazbaz", "scoring_field": 3, "sorting_field": 0})

    # And I do a search
    t.filter(Term("bar", "baz"))
    score = ScriptScore("final_score = 0 + doc['scoring_field'].value;")
    t.score(score)
    sorting = Sort("sorting_field", order="desc")
    t.order_by(sorting)
    t.only(["bar"])
    results = t[0:10]

    # Then I get a the expected results
    len(results).should.equal(3)
    results[0]['fields'].should.equal({"bar": ["baz"]})
    results[1]['fields'].should.equal({"bar": ["baz"]})
    results[2]['fields'].should.equal({"bar": ["baz"]})
开发者ID:jpatel3,项目名称:pyeqs,代码行数:27,代码来源:test_queryset.py


示例15: test_search_filtered_aggregations

def test_search_filtered_aggregations(context):
    """
    Search with filtered aggregations
    """
    # When create a query block
    t = QuerySet("localhost", index="foo")

    # And there are records
    add_document("foo", {"bar": 0, "foo": "baz"})
    add_document("foo", {"bar": 0, "foo": "baz"})
    add_document("foo", {"bar": 2})
    add_document("foo", {"bar": 3, "foo": "bazbaz"})
    add_document("foo", {"bar": 5, "foo": "foobar"})
    add_document("foo", {"bar": 5})
    add_document("foo", {"bar": 5, "foo": "foobaz"})
    add_document("foo", {"bar": 9})

    # And I do a filtered
    f = Filter().filter(Range("bar", gte=5))
    t.aggregate(aggregation=Aggregations("missing_foo", "foo", "missing",
                                         filter_val=f, filter_name="high_bar"))
    t[0:10]

    # Then I get the expected results
    t.aggregations().should.have.key("high_bar")
    t.aggregations()["high_bar"].should.have.key("missing_foo").being.equal(
        {u'doc_count': 2})
    t.aggregations()["high_bar"]["doc_count"].should.equal(4)
开发者ID:Yipit,项目名称:pyeqs,代码行数:28,代码来源:test_aggregations.py


示例16: test_search_with_iterator

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)
    t.max_score().should_not.be(None)
开发者ID:Yipit,项目名称:pyeqs,代码行数:29,代码来源:test_queryset.py


示例17: test_create_queryset_with_scoring_and_filtering_from_object

def test_create_queryset_with_scoring_and_filtering_from_object():
    """
    Create QuerySet with Scoring and Filter Object
    """
    # When create a query block
    t = QuerySet("foobar")

    # And I add scoring
    s = ScriptScore("foo = 0.0")
    t.score(s)

    # And I add filtering
    f = Filter("and").filter(Term("foo", "bar"))
    t.filter(f)

    # Then I see the appropriate JSON
    results = {
        "query": {
            "function_score": {
                "query": {
                    "filtered": {
                        "query": {"match_all": {}},
                        "filter": {
                            "and": [
                                {
                                    "term": {
                                        "foo": "bar"
                                    }
                                }
                            ]
                        }
                    }
                },
                "functions": [
                    {
                        "script_score": {
                            "script": "foo = 0.0"
                        }
                    }
                ],
                "boost_mode": "replace",
                "score_mode": "multiply"
            }
        }
    }

    homogeneous(t._query, results)
开发者ID:jpatel3,项目名称:pyeqs,代码行数:47,代码来源:test_queryset.py


示例18: test_search_nested_aggregations

def test_search_nested_aggregations(context):
    """
    Search with nested aggregations
    """
    # When create a query block
    t = QuerySet("localhost", index="foo")

    # And there are nested records
    add_document("foo", {"child": [{"stuff": "yep", "bazbaz": 10}], "foo": "foo"})
    add_document("foo", {"child": [{"stuff": "nope", "bazbaz": 1}], "foo": "foofoo"})

    # And I do a nested
    t.aggregate(aggregation=Aggregations("best_bazbaz", "bazbaz", "max", nested_path="child"))
    t[0:10]

    # The I get the expected results
    t.aggregations().should.have.key("child").being.equal({'best_bazbaz': {'value': 10.0}, 'doc_count': 2})
开发者ID:Yipit,项目名称:pyeqs,代码行数:17,代码来源:test_aggregations.py


示例19: test_geo_distance_search_with_field_name

def test_geo_distance_search_with_field_name(context):
    """
    Search with geo distance filter with field_name
    """
    # When create a queryset
    t = QuerySet("localhost", index="foo")

    # And there are records
    add_document("foo", {"foo_loc": {"lat": 1.1, "lon": 2.1}})
    add_document("foo", {"foo_loc": {"lat": 40.1, "lon": 80.1}})

    # And I filter for distance
    t.filter(GeoDistance({"lat": 1.0, "lon": 2.0}, "20mi", field_name="foo_loc"))
    results = t[0:10]

    # Then I get a the expected results
    len(results).should.equal(1)
开发者ID:Yipit,项目名称:pyeqs,代码行数:17,代码来源:test_geo_distance.py


示例20: test_create_queryset_with_only_block

def test_create_queryset_with_only_block():
    """
    Create QuerySet with Only block
    """
    # When create a query block
    t = QuerySet("foobar")

    # And I add an 'only' block
    t.only("_id")

    # Then I see the appropriate JSON
    results = {
        "query": {"match_all": {}},
        "fields": ["_id"]
    }

    homogeneous(t._query, results)
开发者ID:jpatel3,项目名称:pyeqs,代码行数:17,代码来源:test_queryset.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pyes.ES类代码示例发布时间:2022-05-25
下一篇:
Python pyeq3.dataConvertorService函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap