Changeset View
Changeset View
Standalone View
Standalone View
swh/search/tests/test_translator.py
Show All 36 Lines | expected = { | ||||
}, | }, | ||||
] | ] | ||||
} | } | ||||
} | } | ||||
} | } | ||||
_test_results(query, expected) | _test_results(query, expected) | ||||
def test_visited(): | |||||
query = "visited = true" | |||||
expected = { | |||||
"filters": {"term": {"has_visits": True}}, | |||||
} | |||||
_test_results(query, expected) | |||||
query = "visited = false" | |||||
expected = { | |||||
"filters": { | |||||
"bool": { | |||||
"should": [ | |||||
{"term": {"has_visits": False}}, | |||||
{"bool": {"must_not": {"exists": {"field": "has_visits"}}}}, | |||||
] | |||||
} | |||||
} | |||||
} | |||||
_test_results(query, expected) | |||||
def test_conjunction_op_precedence_override(): | def test_conjunction_op_precedence_override(): | ||||
query = "(visited = false or visits > 2) and visits < 5" | query = "(visited = true or visits > 2) and visits < 5" | ||||
expected = { | expected = { | ||||
"filters": { | "filters": { | ||||
"bool": { | "bool": { | ||||
"must": [ | "must": [ | ||||
{ | { | ||||
"bool": { | "bool": { | ||||
"should": [ | "should": [ | ||||
{"term": {"has_visits": False}}, | {"term": {"has_visits": True}}, | ||||
{"range": {"nb_visits": {"gt": 2}}}, | {"range": {"nb_visits": {"gt": 2}}}, | ||||
] | ] | ||||
} | } | ||||
}, | }, | ||||
{"range": {"nb_visits": {"lt": 5}}}, | {"range": {"nb_visits": {"lt": 5}}}, | ||||
] | ] | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 343 Lines • Show Last 20 Lines |