Compare commits

...

5 Commits

Author SHA1 Message Date
2a4db7476f Fix the graph rendering 2022-09-30 07:22:22 +01:00
835be7e001 Allow duplicate tag keys 2022-09-30 07:22:22 +01:00
8010ebf2c1 Render the words as tags 2022-09-30 07:22:22 +01:00
5530fd762c Fix context menu 2022-09-30 07:22:22 +01:00
d8981378bd Switch ujson to orjson 2022-09-30 07:22:22 +01:00
5 changed files with 100 additions and 10 deletions

View File

@@ -110,7 +110,8 @@ class StorageBackend(object):
if not query_created:
search_query = self.construct_query(None, size, index, blank=True)
query_created = True
for tagname, tagvalue in tags.items():
for item in tags:
for tagname, tagvalue in item.items():
add_bool.append({tagname: tagvalue})
valid = self.check_valid_query(query_params, custom_query)

View File

@@ -19,6 +19,64 @@ class DruidBackend(StorageBackend):
# self.client = PyDruid("http://broker:8082", "druid/v2")
pass # we use requests
def construct_context_query(
self, index, net, channel, src, num, size, type=None, nicks=None
):
search_query = self.construct_query(None, size, index, blank=True)
extra_must = []
extra_should = []
extra_should2 = []
if num:
extra_must.append({"num": num})
if net:
extra_must.append({"net": net})
if channel:
extra_must.append({"channel": channel})
if nicks:
for nick in nicks:
extra_should2.append({"nick": nick})
types = ["msg", "notice", "action", "kick", "topic", "mode"]
if index == "internal":
if channel == "*status" or type == "znc":
if {"channel": channel} in extra_must:
extra_must.remove({"channel": channel})
extra_should2 = []
# Type is one of msg or notice
# extra_should.append({"match": {"mtype": "msg"}})
# extra_should.append({"match": {"mtype": "notice"}})
extra_should.append({"type": "znc"})
extra_should.append({"type": "self"})
extra_should2.append({"type": "znc"})
extra_should2.append({"nick": channel})
elif type == "auth":
if {"match": {"channel": channel}} in extra_must:
extra_must.remove({"channel": channel})
extra_should2 = []
extra_should2.append({"nick": channel})
# extra_should2.append({"match": {"mtype": "msg"}})
# extra_should2.append({"match": {"mtype": "notice"}})
extra_should.append({"type": "query"})
extra_should2.append({"type": "self"})
extra_should.append({"nick": channel})
else:
for ctype in types:
extra_should.append({"mtype": ctype})
else:
for ctype in types:
extra_should.append({"type": ctype})
if extra_must:
self.add_type("and", search_query, extra_must)
if extra_should:
self.add_type("or", search_query, extra_should)
if extra_should2:
self.add_type("or", search_query, extra_should2)
return search_query
def construct_query(self, query, size, index, blank=False):
search_query = {
"limit": size,

View File

@@ -43,6 +43,7 @@ $(document).ready(function(){
"guild_member_count": "off",
"bot": "off",
"msg_id": "off",
"user": "off",
"net_id": "off",
"user_id": "off",
"nick_id": "off",
@@ -63,6 +64,12 @@ $(document).ready(function(){
"file_md5": "off",
"file_ext": "off",
"file_size": "off",
"lang_code": "off",
//"lang_name": "off",
"words_noun": "off",
"words_adj": "off",
"words_verb": "off",
"words_adv": "off"
},
};
} else {

View File

@@ -364,6 +364,26 @@
</span>
{% endif %}
</td>
{% elif column.name|slice:":6" == "words_" %}
<td class="{{ column.name }}">
{% if cell.0.1|length == 0 %}
<a
class="tag is-info"
onclick="populateSearch('{{ column.name }}', '{{ cell }}')">
{{ cell }}
</a>
{% else %}
<div class="tags">
{% for word in cell %}
<a
class="tag is-info"
onclick="populateSearch('{{ column.name }}', '{{ word }}')">
{{ word }}
</a>
{% endfor %}
</div>
{% endif %}
</td>
{% else %}
<td class="{{ column.name }}">
<a

View File

@@ -1,7 +1,7 @@
import urllib
import uuid
import ujson
import orjson
from django.conf import settings
from django.http import HttpResponse, JsonResponse
from django.shortcuts import render
@@ -12,7 +12,6 @@ from rest_framework.parsers import FormParser
from rest_framework.views import APIView
from core.db.storage import db
from core.lib.context import construct_query
from core.lib.threshold import (
annotate_num_chans,
annotate_num_users,
@@ -61,14 +60,14 @@ def parse_tags(tags_pre):
"""
Parse the tags from the variable tags_pre.
"""
tags = {}
tags = []
tags_spl = tags_pre.split(",")
if tags_spl:
for tag in tags_spl:
tag = tag.split(": ")
if len(tag) == 2:
key, val = tag
tags[key] = val
tags.append({key: val})
return tags
@@ -95,7 +94,7 @@ def make_graph(results):
"date": date,
}
)
return ujson.dumps(graph)
return orjson.dumps(graph).decode("utf-8")
def drilldown_search(request, return_context=False, template=None):
@@ -361,9 +360,14 @@ class DrilldownContextModal(APIView):
if query_params["type"] not in ["znc", "auth"]:
annotate = True
# Create the query with the context helper
if "num" in query_params:
if query_params["num"]:
if query_params["num"].isdigit():
query_params["num"] = int(query_params["num"])
search_query = construct_query(
else:
return {"message": "Invalid num value", "class": "danger"}
search_query = db.construct_context_query(
query_params["index"],
query_params["net"],
query_params["channel"],