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: if not query_created:
search_query = self.construct_query(None, size, index, blank=True) search_query = self.construct_query(None, size, index, blank=True)
query_created = 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}) add_bool.append({tagname: tagvalue})
valid = self.check_valid_query(query_params, custom_query) 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") # self.client = PyDruid("http://broker:8082", "druid/v2")
pass # we use requests 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): def construct_query(self, query, size, index, blank=False):
search_query = { search_query = {
"limit": size, "limit": size,

View File

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

View File

@@ -364,6 +364,26 @@
</span> </span>
{% endif %} {% endif %}
</td> </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 %} {% else %}
<td class="{{ column.name }}"> <td class="{{ column.name }}">
<a <a

View File

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