Implement searching int events

This commit is contained in:
2022-08-09 07:20:30 +01:00
parent 83cd5e7ee7
commit 9a92429291
9 changed files with 122 additions and 124 deletions

View File

@@ -1,17 +1,34 @@
def construct_query(net, channel, src, num, size):
def construct_query(index, net, channel, src, num, size):
# Get the initial query
extra_must = []
if num:
extra_must.append({"match": {"num": num}})
if net:
extra_must.append({"match": {"net": net}})
if channel:
extra_must.append({"match": {"channel": channel}})
types = ["msg", "notice", "action", "kick", "topic", "mode"]
query_should = [{"match": {"type": x}} for x in types]
fields = [
"nick",
"ident",
"host",
"channel",
"ts",
"msg",
"type",
"net",
"src",
]
if index == "int":
fields.append("mtype")
query_should = [{"match": {"mtype": x}} for x in types]
else:
query_should = [{"match": {"type": x}} for x in types]
query = {
"size": size,
"query": {
"bool": {
"must": [
{"match": {"net": net}},
{"match": {"channel": channel}},
{"match": {"src": src}},
{
"bool": {
@@ -22,17 +39,7 @@ def construct_query(net, channel, src, num, size):
]
}
},
"fields": [
"nick",
"ident",
"host",
"channel",
"ts",
"msg",
"type",
"net",
"src",
],
"fields": fields,
"_source": False,
}
return query

View File

@@ -365,13 +365,15 @@ def query_results(request, query_params, size=None, annotate=True, custom_query=
if "index" in query_params:
index = query_params["index"]
print("INDEX IS HERE", index)
if index == "main":
index = settings.OPENSEARCH_INDEX_MAIN
else:
if request.user.is_superuser:
if index == "meta":
print("INDEX IS META")
index = settings.OPENSEARCH_INDEX_META
if index == "int":
elif index == "int":
index = settings.OPENSEARCH_INDEX_INT
else:
message = "Index is not valid."
@@ -383,6 +385,7 @@ def query_results(request, query_params, size=None, annotate=True, custom_query=
return {"message": message, "class": message_class}
else:
index = settings.OPENSEARCH_INDEX_MAIN
print("RUNNING QUERY", index, search_query)
results = run_main_query(
client,
request.user, # passed through run_main_query to filter_blacklisted
@@ -405,6 +408,7 @@ def query_results(request, query_params, size=None, annotate=True, custom_query=
results_parsed = parse_results(results)
if annotate:
annotate_results(results_parsed)
print("FNL", results_parsed)
context = {
"object_list": results_parsed,