neptune/core/lib/context.py

59 lines
1.5 KiB
Python
Raw Normal View History

2022-08-03 06:20:30 +00:00
def construct_query(index, net, channel, src, num, size, nicks=None):
2022-08-09 06:20:30 +00:00
# Get the initial query
extra_must = []
2022-08-03 06:20:30 +00:00
extra_should = []
extra_should2 = []
2022-08-09 06:20:30 +00:00
if num:
extra_must.append({"match": {"num": num}})
2022-08-09 06:20:30 +00:00
if net:
extra_must.append({"match": {"net": net}})
if channel:
extra_must.append({"match": {"channel": channel}})
2022-08-03 06:20:30 +00:00
if nicks:
for nick in nicks:
extra_should2.append({"match": {"nick": nick}})
2022-08-09 06:20:30 +00:00
types = ["msg", "notice", "action", "kick", "topic", "mode"]
2022-08-09 06:20:30 +00:00
fields = [
"nick",
"ident",
"host",
"channel",
"ts",
"msg",
"type",
"net",
"src",
]
if index == "int":
fields.append("mtype")
for ctype in types:
extra_should.append({"match": {"mtype": ctype}})
else:
for ctype in types:
extra_should.append({"match": {"type": ctype}})
2022-08-09 06:20:30 +00:00
query = {
"size": size,
"query": {
"bool": {
"must": [
{"match": {"src": src}},
{
"bool": {
2022-08-03 06:20:30 +00:00
"should": [*extra_should],
}
},
{
"bool": {
"should": [*extra_should2],
2022-08-09 06:20:30 +00:00
}
},
*extra_must,
2022-08-09 06:20:30 +00:00
]
}
},
2022-08-09 06:20:30 +00:00
"fields": fields,
2022-08-09 06:20:30 +00:00
"_source": False,
}
2022-08-03 06:20:30 +00:00
return query