Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - add query match_all and match_none query clauses #106

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pandagg/node/aggs/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def __init__(


class MatchAll(Filter):
KEY = "match_all"

def __init__(self, **body: Any):
super(MatchAll, self).__init__(filter={"match_all": {}}, **body)

Expand Down
1 change: 1 addition & 0 deletions pandagg/node/query/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .full_text import *
from .geo import *
from .joining import *
from .match_all import *
from .shape import *
from .span import *
from .specialized import *
Expand Down
18 changes: 18 additions & 0 deletions pandagg/node/query/match_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from typing import Any

from pandagg.node.query import LeafQueryClause


class MatchAll(LeafQueryClause):

KEY = "match_all"

def __init__(self, **body: Any) -> None:
super(MatchAll, self).__init__(**body)


class MatchNone(LeafQueryClause):
KEY = "match_none"

def __init__(self, **body: Any) -> None:
super(MatchNone, self).__init__(**body)
4 changes: 4 additions & 0 deletions pandagg/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
DisMax,
)
from pandagg.node.query.joining import Nested, HasChild, HasParent, ParentId
from pandagg.node.query.match_all import MatchNone, MatchAll
from pandagg.node.query.geo import GeoShape, GeoPolygone, GeoDistance, GeoBoundingBox
from pandagg.node.query.specialized import (
DistanceFeature,
Expand Down Expand Up @@ -78,6 +79,9 @@
"HasParent",
"HasChild",
"ParentId",
# match_all
"MatchAll",
"MatchNone",
# shape
"Shape",
# geo
Expand Down
20 changes: 20 additions & 0 deletions tests/node/query/test_match_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from pandagg.node.query import MatchAll, MatchNone


def test_match_all_clause():
q = MatchAll()
assert q.body == {}
assert q.to_dict() == {"match_all": {}}
assert q.line_repr(depth=None) == ("match_all", "")

q = MatchAll(boost=0.5)
assert q.body == {"boost": 0.5}
assert q.to_dict() == {"match_all": {"boost": 0.5}}
assert q.line_repr(depth=None) == ("match_all", "boost=0.5")


def test_match_none_clause():
q = MatchNone()
assert q.body == {}
assert q.to_dict() == {"match_none": {}}
assert q.line_repr(depth=None) == ("match_none", "")