Properly fetch query data
This commit is contained in:
parent
6af8e94336
commit
60270d9636
|
@ -1,12 +1,18 @@
|
||||||
def construct_query(index, net, channel, src, num, size):
|
def construct_query(index, net, channel, src, num, size, nicks=None):
|
||||||
# Get the initial query
|
# Get the initial query
|
||||||
extra_must = []
|
extra_must = []
|
||||||
|
extra_should = []
|
||||||
|
extra_should2 = []
|
||||||
if num:
|
if num:
|
||||||
extra_must.append({"match": {"num": num}})
|
extra_must.append({"match": {"num": num}})
|
||||||
if net:
|
if net:
|
||||||
extra_must.append({"match": {"net": net}})
|
extra_must.append({"match": {"net": net}})
|
||||||
if channel:
|
if channel:
|
||||||
extra_must.append({"match": {"channel": channel}})
|
extra_must.append({"match": {"channel": channel}})
|
||||||
|
if nicks:
|
||||||
|
print("NICKS", nicks)
|
||||||
|
for nick in nicks:
|
||||||
|
extra_should2.append({"match": {"nick": nick}})
|
||||||
types = ["msg", "notice", "action", "kick", "topic", "mode"]
|
types = ["msg", "notice", "action", "kick", "topic", "mode"]
|
||||||
fields = [
|
fields = [
|
||||||
"nick",
|
"nick",
|
||||||
|
@ -19,11 +25,13 @@ def construct_query(index, net, channel, src, num, size):
|
||||||
"net",
|
"net",
|
||||||
"src",
|
"src",
|
||||||
]
|
]
|
||||||
if index == "int":
|
# if index == "int":
|
||||||
fields.append("mtype")
|
# fields.append("mtype")
|
||||||
query_should = [{"match": {"mtype": x}} for x in types]
|
# for ctype in types:
|
||||||
else:
|
# extra_should.append({"match": {"mtype": ctype}})
|
||||||
query_should = [{"match": {"type": x}} for x in types]
|
# else:
|
||||||
|
# for ctype in types:
|
||||||
|
# extra_should.append({"match": {"type": ctype}})
|
||||||
query = {
|
query = {
|
||||||
"size": size,
|
"size": size,
|
||||||
"query": {
|
"query": {
|
||||||
|
@ -32,7 +40,12 @@ def construct_query(index, net, channel, src, num, size):
|
||||||
{"match": {"src": src}},
|
{"match": {"src": src}},
|
||||||
{
|
{
|
||||||
"bool": {
|
"bool": {
|
||||||
"should": query_should,
|
"should": [*extra_should],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bool": {
|
||||||
|
"should": [*extra_should2],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
*extra_must,
|
*extra_must,
|
||||||
|
@ -42,5 +55,5 @@ def construct_query(index, net, channel, src, num, size):
|
||||||
"fields": fields,
|
"fields": fields,
|
||||||
"_source": False,
|
"_source": False,
|
||||||
}
|
}
|
||||||
print("QUERY", query)
|
|
||||||
return query
|
return query
|
||||||
|
|
|
@ -203,3 +203,9 @@ def send_irc_message(net, num, channel, msg, nick=None):
|
||||||
payload["nick"] = nick
|
payload["nick"] = nick
|
||||||
messaged = threshold_request(url, payload, method="PUT")
|
messaged = threshold_request(url, payload, method="PUT")
|
||||||
return messaged
|
return messaged
|
||||||
|
|
||||||
|
def get_irc_nick(net, num):
|
||||||
|
url = f"irc/nick/{net}/{num}"
|
||||||
|
payload = {}
|
||||||
|
nick = threshold_request(url, payload, method="GET")
|
||||||
|
return nick
|
|
@ -19,7 +19,7 @@ from core.lib.threshold import (
|
||||||
get_users,
|
get_users,
|
||||||
)
|
)
|
||||||
from core.views.ui.tables import DrilldownTable
|
from core.views.ui.tables import DrilldownTable
|
||||||
|
from core.lib import threshold
|
||||||
|
|
||||||
def parse_dates(dates):
|
def parse_dates(dates):
|
||||||
spl = dates.split(" - ")
|
spl = dates.split(" - ")
|
||||||
|
@ -244,6 +244,7 @@ class DrilldownContextModal(APIView):
|
||||||
self.template_name = "modals/context_table.html"
|
self.template_name = "modals/context_table.html"
|
||||||
|
|
||||||
size = 20
|
size = 20
|
||||||
|
nicks = None
|
||||||
# Create the query params from the POST arguments
|
# Create the query params from the POST arguments
|
||||||
mandatory = ["net", "channel", "num", "src", "index", "nick"]
|
mandatory = ["net", "channel", "num", "src", "index", "nick"]
|
||||||
invalid = [None, False, "—", "None"]
|
invalid = [None, False, "—", "None"]
|
||||||
|
@ -257,6 +258,12 @@ class DrilldownContextModal(APIView):
|
||||||
if query_params["index"] == "int":
|
if query_params["index"] == "int":
|
||||||
if "mtype" not in query_params:
|
if "mtype" not in query_params:
|
||||||
query_params["mtype"] = None
|
query_params["mtype"] = None
|
||||||
|
if request.user.is_superuser:
|
||||||
|
if query_params["type"] == "query":
|
||||||
|
#bot_nick = threshold.irc_get_nick(query_params["net"], query_params["num"])
|
||||||
|
print("BOT NICK", query_params["channel"])
|
||||||
|
print("QUERY NICK", query_params["nick"])
|
||||||
|
nicks = [query_params["channel"], query_params["nick"]]
|
||||||
query_params["sorting"] = "desc"
|
query_params["sorting"] = "desc"
|
||||||
if (
|
if (
|
||||||
query_params["index"] == "int"
|
query_params["index"] == "int"
|
||||||
|
@ -272,6 +279,7 @@ class DrilldownContextModal(APIView):
|
||||||
query_params["src"],
|
query_params["src"],
|
||||||
query_params["num"],
|
query_params["num"],
|
||||||
size,
|
size,
|
||||||
|
nicks=nicks,
|
||||||
)
|
)
|
||||||
results = query_results(
|
results = query_results(
|
||||||
request, query_params, annotate=True, custom_query=search_query
|
request, query_params, annotate=True, custom_query=search_query
|
||||||
|
|
Loading…
Reference in New Issue