neptune/core/lib/context.py

59 lines
1.5 KiB
Python

def construct_query(index, net, channel, src, num, size, nicks=None):
# Get the initial query
extra_must = []
extra_should = []
extra_should2 = []
if num:
extra_must.append({"match": {"num": num}})
if net:
extra_must.append({"match": {"net": net}})
if channel:
extra_must.append({"match": {"channel": channel}})
if nicks:
for nick in nicks:
extra_should2.append({"match": {"nick": nick}})
types = ["msg", "notice", "action", "kick", "topic", "mode"]
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}})
query = {
"size": size,
"query": {
"bool": {
"must": [
{"match": {"src": src}},
{
"bool": {
"should": [*extra_should],
}
},
{
"bool": {
"should": [*extra_should2],
}
},
*extra_must,
]
}
},
"fields": fields,
"_source": False,
}
return query