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


Python QuerySet.order_by方法代码示例

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


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

示例1: test_create_queryset_with_multiple_sorting

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import order_by [as 别名]
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,代码行数:36,代码来源:test_queryset.py

示例2: test_search_with_filter_and_scoring_and_sorting_and_fields

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import order_by [as 别名]
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,代码行数:29,代码来源:test_queryset.py

示例3: test_search_with_iterator

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import order_by [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

示例4: test_post_query_actions

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import order_by [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)
开发者ID:Yipit,项目名称:pyeqs,代码行数:34,代码来源:test_queryset.py

示例5: test_wrappers

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import order_by [as 别名]
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,代码行数:27,代码来源:test_queryset.py

示例6: test_search_with_mode_sorting

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import order_by [as 别名]
def test_search_with_mode_sorting(context):
    """
    Search with descending sorting and mode
    """
    # When create a query block
    t = QuerySet("localhost", index="foo")

    # And there are records
    add_document("foo", {"bar": [1, 10]})
    add_document("foo", {"bar": [2, 10]})
    add_document("foo", {"bar": [3, 10]})

    # And I add sorting
    s = Sort("bar", order="desc", mode="min")
    t.order_by(s)
    results = t[0:10]

    # Then my results have the proper sorting
    results[0]["_source"]["bar"].should.equal([3, 10])
    results[1]["_source"]["bar"].should.equal([2, 10])
    results[2]["_source"]["bar"].should.equal([1, 10])
开发者ID:mengjues,项目名称:pyeqs,代码行数:23,代码来源:test_sorting.py

示例7: test_search_with_desc_sorting

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import order_by [as 别名]
def test_search_with_desc_sorting(context):
    """
    Search with descending sorting
    """
    # When create a query block
    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 add sorting
    s = Sort("bar", order="desc")
    t.order_by(s)
    results = t[0:10]

    # Then my results have the proper sorting
    results[0]["_source"]["bar"].should.equal(3)
    results[1]["_source"]["bar"].should.equal(2)
    results[2]["_source"]["bar"].should.equal(1)
开发者ID:mengjues,项目名称:pyeqs,代码行数:23,代码来源:test_sorting.py

示例8: test_search_with_multiple_sorts

# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import order_by [as 别名]
def test_search_with_multiple_sorts(context):
    """
    Search with multiple sorts
    """
    # When create a query block
    t = QuerySet("localhost", index="foo")

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

    # And I add sorting
    first_sort = Sort("bar", order="asc")
    second_sort = Sort("baz", order="asc")
    t.order_by(first_sort)
    t.order_by(second_sort)
    results = t[0:10]

    # Then my results have the proper sorting
    results[0]["_source"]["baz"].should.equal(1)
    results[1]["_source"]["baz"].should.equal(2)
    results[2]["_source"]["baz"].should.equal(3)
开发者ID:mengjues,项目名称:pyeqs,代码行数:25,代码来源:test_sorting.py


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