from core.lib.opensearch import client, run_main_query def get_nicks(request, net, nick, iter=0): """ Get all related nicknames of the given nickname by tracking nickname changes. """ print("GET NICKS INIT", net, nick, iter) # Get the initial query query = { "size": 10000, "query": { "bool": { "must": [ {"match": {"net": net}}, {"match": {"type": "nick"}}, { "bool": { "should": [ {"match": {"nick": nick}}, {"match": {"user": nick}}, ] } }, ] } }, } results = run_main_query(client, request.user, query, custom_query=True) nicks = [] if "hits" in results.keys(): if "hits" in results["hits"]: for item in results["hits"]["hits"]: element = item["_source"] element["id"] = item["_id"] # Split the timestamp into date and time ts = element["ts"] ts_spl = ts.split("T") date = ts_spl[0] time = ts_spl[1] element["date"] = date element["time"] = time if element["nick"] not in nicks: nicks.append(element["nick"]) if element["user"] not in nicks: nicks.append(element["user"]) # if iter < 2: # iter += 1 # collect_nicks = [] # for x in nicks: # nicks_2 = get_nicks(request, net, x, iter) # print("NICKS_2", nicks_2) # for y in nicks_2: # if y not in collect_nicks: # collect_nicks.append(y) # print("RETURN NICKS", nick, collect_nicks) # for x in collect_nicks: # if x not in nicks: # nicks.append(x) # else: # print("ABORTING SEARCH") return nicks # results = set() # nicks = query["nicks"] # for nick in nicks: # if nick not in results: # nicks_result = get_nicks(request, net_nick) # results.add(nick)