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

Add a headers_jsons grep argument #1326

Open
abompard opened this issue Jun 13, 2024 · 0 comments
Open

Add a headers_jsons grep argument #1326

abompard opened this issue Jun 13, 2024 · 0 comments

Comments

@abompard
Copy link
Member

Now that there is a JSONB index on the headers column, we could add a grep argument that would make use of it. It could look something like:

--- a/datanommer.models/datanommer/models/__init__.py
+++ b/datanommer.models/datanommer/models/__init__.py
@@ -395,6 +395,8 @@ class Message(DeclarativeBase):
         not_topics=None,
         agents=None,
         not_agents=None,
+        headers_jsons=None,
+        headers_jsons_and=None,
         contains=None,
     ):
         """Flexible query interface for messages.
@@ -436,6 +438,8 @@ class Message(DeclarativeBase):
         not_topics = not_topics or []
         agents = agents or []
         not_agents = not_agents or []
+        headers_jsons = headers_jsons or []
+        headers_jsons_and = headers_jsons_and or []
         contains = contains or []
 
         Message = cls
@@ -470,6 +474,11 @@ class Message(DeclarativeBase):
         if agents:
             query = query.where(or_(*(Message.agent_name == agent for agent in agents)))
 
+        if headers_jsons:
+            query = query.where(or_(*(Message.headers.path_match(path) for path in headers_jsons)))
+        if headers_jsons_and:
+            query = query.where(and_(*(Message.headers.path_match(path) for path in headers_jsons_and)))
+
         if contains:
             query = query.where(or_(*(Message.msg.like(f"%{contain}%") for contain in contains)))
 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant