本文整理汇总了Python中pyeqs.QuerySet.filter方法的典型用法代码示例。如果您正苦于以下问题:Python QuerySet.filter方法的具体用法?Python QuerySet.filter怎么用?Python QuerySet.filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyeqs.QuerySet
的用法示例。
在下文中一共展示了QuerySet.filter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_queryset_with_filters
# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import filter [as 别名]
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)
示例2: test_search_with_filter_and_scoring_and_sorting_and_fields
# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import filter [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"]})
示例3: test_create_queryset_with_filters_and_scoring
# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import filter [as 别名]
def test_create_queryset_with_filters_and_scoring():
"""
Create QuerySet with Scoring and Multiple Filters
"""
# When create a query block
t = QuerySet("foobar")
# And I add filtering
t.filter(Term("foo", "bar"))
# And I add scoring
s = ScriptScore("foo = 0.0")
t.score(s)
# And I add a second filter
t.filter(Term("foobar", "foobar"))
# Then I see the appropriate JSON
results = {
"query": {
"function_score": {
"query": {
"filtered": {
"query": {"match_all": {}},
"filter": {
"and": [
{
"term": {
"foo": "bar"
}
},
{
"term": {
"foobar": "foobar"
}
}
]
}
}
},
"functions": [
{
"script_score": {
"script": "foo = 0.0"
}
}
],
"boost_mode": "replace",
"score_mode": "multiply"
}
}
}
homogeneous(t._query, results)
示例4: test_geo_distance_search_array
# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import filter [as 别名]
def test_geo_distance_search_array(context):
"""
Search with geo distance filter with array
"""
# When create a queryset
t = QuerySet("localhost", index="foo")
# And there are records
add_document("foo", {"location": {"lat": 1.1, "lon": 2.1}})
add_document("foo", {"location": {"lat": 40.1, "lon": 80.1}})
# And I filter for terms
t.filter(GeoDistance([2.0, 1.0], "20mi"))
results = t[0:10]
# Then I get a the expected results
len(results).should.equal(1)
示例5: test_geo_distance_search_with_field_name
# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import filter [as 别名]
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)
示例6: test_simple_search_with_filter
# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import filter [as 别名]
def test_simple_search_with_filter(context):
"""
Search with filter
"""
# When create a queryset
t = QuerySet("localhost", index="foo")
# And there are records
add_document("foo", {"bar": "baz"})
add_document("foo", {"bar": "bazbaz"})
# And I do a filtered search
t.filter(Term("bar", "baz"))
results = t[0:10]
# Then I get a the expected results
len(results).should.equal(1)
results[0]['_source'].should.equal({"bar": "baz"})
示例7: test_search_with_missing_existence_null_value
# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import filter [as 别名]
def test_search_with_missing_existence_null_value(context):
"""
Search with missing via non-existence or a null value
"""
# When create a query block
t = QuerySet("localhost", index="foo")
# And there are records
add_document("foo", {"bar": 1})
add_document("foo", {"baz": 2})
add_document("foo", {"baz": 3, "bar": None})
# And I add filters
t.filter(Missing("bar", existence=True, null_value=True))
results = t[0:10]
# Then my results are filtered correctly
len(results).should.equal(2)
示例8: test_terms_search_with_execution
# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import filter [as 别名]
def test_terms_search_with_execution(context):
"""
Search with terms filter with execution
"""
# When create a queryset
t = QuerySet("localhost", index="foo")
# And there are records
add_document("foo", {"foo": ["foo", "bar"]})
add_document("foo", {"foo": ["foo", "baz"]})
# And I filter for terms
t.filter(Terms("foo", ["foo", "bar"], execution="and"))
results = t[0:10]
# Then I get a the expected results
len(results).should.equal(1)
results[0]["_source"]["foo"].should.equal(["foo", "bar"])
示例9: test_match_all_search
# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import filter [as 别名]
def test_match_all_search(context):
"""
Search with match all filter
"""
# When create a queryset
t = QuerySet("localhost", index="foo")
# And there are records
add_document("foo", {"bar": "baz", "foo": "foo"})
add_document("foo", {"bar": "bazbaz", "foo": "foo"})
add_document("foo", {"bar": "baz", "foo": "foofoo"})
add_document("foo", {"bar": "baz", "foo": "foofoofoo"})
# And I filter match_all
t.filter(MatchAll())
results = t[0:10]
# Then I get a the expected results
len(results).should.equal(4)
示例10: test_terms_search
# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import filter [as 别名]
def test_terms_search(context):
"""
Search with terms filter
"""
# When create a queryset
t = QuerySet("localhost", index="foo")
# And there are records
add_document("foo", {"bar": "baz", "foo": "foo"})
add_document("foo", {"bar": "bazbaz", "foo": "foo"})
add_document("foo", {"bar": "baz", "foo": "foofoo"})
add_document("foo", {"bar": "baz", "foo": "foofoofoo"})
# And I filter for terms
t.filter(Terms("foo", ["foo", "foofoo"]))
results = t[0:10]
# Then I get a the expected results
len(results).should.equal(3)
示例11: test_search_with_missing
# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import filter [as 别名]
def test_search_with_missing(context):
"""
Search with missing
"""
# When create a query block
t = QuerySet("localhost", index="foo")
# And there are records
add_document("foo", {"bar": 1})
add_document("foo", {"baz": 2})
add_document("foo", {"bar": 3})
# And I add filters
t.filter(Missing("bar"))
results = t[0:10]
# Then my results are filtered correctly
len(results).should.equal(1)
results[0]["_source"]["baz"].should.equal(2)
示例12: test_search_with_exists
# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import filter [as 别名]
def test_search_with_exists(context):
"""
Search with exists filter
"""
# When create a query block
t = QuerySet("localhost", index="foo")
# And there are records
add_document("foo", {"bar": 1})
add_document("foo", {"baz": 1})
# And I add an exists filter
exists = Exists("baz")
t.filter(exists)
results = t[0:10]
# Then my results only have that field
len(results).should.equal(1)
results[0]["_source"]["baz"].should.equal(1)
示例13: test_search_with_filter_block
# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import filter [as 别名]
def test_search_with_filter_block(context):
"""
Search with Filter Block
"""
# When create a query block
t = QuerySet("localhost", index="foo")
# And there are records
add_document("foo", {"bar": "baz", "foo": "foo"})
add_document("foo", {"bar": "bazbaz", "foo": "foo"})
add_document("foo", {"bar": "bazbaz", "foo": "foofoo"})
# And I do a filtered search
f = Filter("or").filter(Term("bar", "baz")).filter(Term("foo", "foo"))
t.filter(f)
results = t[0:10]
# Then I get the appropriate response
len(results).should.equal(2)
示例14: test_create_queryset_with_scoring_and_filtering_from_object
# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import filter [as 别名]
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"
}
}
]
}
}
},
"script_score": {
"script": "foo = 0.0"
},
"boost_mode": "replace"
}
}
}
homogeneous(t._query, results)
示例15: test_search_with_multiple_filters
# 需要导入模块: from pyeqs import QuerySet [as 别名]
# 或者: from pyeqs.QuerySet import filter [as 别名]
def test_search_with_multiple_filters(context):
"""
Search with multiple filters
"""
# When create a query block
t = QuerySet("localhost", index="foo")
# And there are records
add_document("foo", {"bar": "baz", "foo": "foo"})
add_document("foo", {"bar": "bazbaz", "foo": "foo"})
add_document("foo", {"bar": "bazbaz", "foo": "foofoo"})
# And I do a filtered search
t.filter(Term("bar", "bazbaz"))
t.filter(Term("foo", "foo"))
results = t[0:10]
# Then I get the appropriate response
len(results).should.equal(1)
results[0]['_source'].should.equal({"bar": "bazbaz", "foo": "foo"})