Don't filter 4chan for blacklist

This commit is contained in:
Mark Veidemanis 2022-08-30 10:52:43 +01:00
parent a026fbf900
commit bcf3ad708a
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 11 additions and 4 deletions

View File

@ -216,7 +216,7 @@ def construct_query(query, size, use_query_string=True, tokens=False):
return query_base return query_base
def run_main_query(client, user, query, custom_query=False, index=None, size=None): def run_main_query(client, user, query, custom_query=False, index=None, size=None, filter=True):
""" """
Low level helper to run an ES query. Low level helper to run an ES query.
Accept a user to pass it to the filter, so we can Accept a user to pass it to the filter, so we can
@ -238,6 +238,7 @@ def run_main_query(client, user, query, custom_query=False, index=None, size=Non
except NotFoundError as err: except NotFoundError as err:
print("OpenSearch error", err) print("OpenSearch error", err)
return err return err
if filter:
filter_blacklisted(user, response) filter_blacklisted(user, response)
return response return response
@ -539,6 +540,9 @@ def query_results(
else: else:
index = settings.OPENSEARCH_INDEX_MAIN index = settings.OPENSEARCH_INDEX_MAIN
filter = True
if source in settings.SAFE_SOURCES:
filter = False
results = run_main_query( results = run_main_query(
client, client,
request.user, # passed through run_main_query to filter_blacklisted request.user, # passed through run_main_query to filter_blacklisted
@ -546,6 +550,7 @@ def query_results(
custom_query=True, custom_query=True,
index=index, index=index,
size=size, size=size,
filter=filter,
) )
if not results: if not results:
return False return False
@ -598,9 +603,11 @@ def query_results(
"object_list": results_parsed, "object_list": results_parsed,
"card": results["hits"]["total"]["value"], "card": results["hits"]["total"]["value"],
"took": results["took"], "took": results["took"],
"redacted": results["redacted"],
"exemption": results["exemption"],
} }
if "redacted" in results:
context["redacted"] = results["redacted"]
if "exemption" in results:
context["exemption"] = results["exemption"]
if query: if query:
context["query"] = query context["query"] = query
if settings.DELAY_RESULTS: if settings.DELAY_RESULTS: