Skip to content
Snippets Groups Projects
Commit e788ae11 authored by lass's avatar lass
Browse files

Remove debug print & add hit number variable

parent d7d6cfd2
No related branches found
No related tags found
1 merge request!380Greg 321 improve search
Pipeline #179255 passed
......@@ -5,6 +5,7 @@ from greg.models import Identity, Person
def person_by_string_query(request):
search = request.query_params["q"]
number_of_hits = 20
if "gregui" in request.version:
id_field_name = "pid"
else:
......@@ -13,7 +14,7 @@ def person_by_string_query(request):
split_search = search.lower().split()
search_regex = "(.*)".join(split_search)
reversed_search_regex = "(.*)".join(list(reversed(split_search)))
print(split_search, search_regex)
hits = []
# First look for hits on name and birth date
persons = Person.objects.annotate(
......@@ -25,9 +26,9 @@ def person_by_string_query(request):
| Q(full_name__iregex=reversed_search_regex)
| Q(date_of_birth__iregex=search_regex)
)[
:20
:number_of_hits
]
print(persons)
included_persons = []
for person in persons:
hits.append(
......@@ -40,7 +41,7 @@ def person_by_string_query(request):
)
included_persons.append(person.id)
if len(hits) == 20:
if len(hits) == number_of_hits:
# Max number of hits, no need to search more
return hits
......@@ -51,7 +52,7 @@ def person_by_string_query(request):
Identity.IdentityType.PRIVATE_EMAIL,
Identity.IdentityType.PRIVATE_MOBILE_NUMBER,
],
)[: (20 - len(hits))]
)[: (number_of_hits - len(hits))]
for identity in identities:
if identity.person_id in included_persons:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment