diff --git a/address_finder/api.py b/address_finder/api.py
index b40d90d..548ff33 100644
--- a/address_finder/api.py
+++ b/address_finder/api.py
@@ -2,6 +2,7 @@ import sqlite3
import sys
import json
from .model import Commune,FantoirVoie
+import re
# DB with addresses info
DB_ADDRESSES_PATH_ENV="DB_ADDRESSES_PATH"
@@ -30,15 +31,29 @@ class AddressFinder:
con.row_factory = sqlite3.Row
cur = con.cursor()
communes: list[Commune] = []
+
+ communeSearch = communeNameOrZip
+ zipSearch = communeNameOrZip
+ searchOpertor = "OR"
+
+ regexCommuneAndZip = r"[0-9]{5} .+" # For example: '33000 BO'
+ if re.match(regexCommuneAndZip, communeNameOrZip):
+ print("MATCH")
+ splitSearch = communeNameOrZip.split(' ')
+ zipSearch = splitSearch[0]
+ communeSearch = ' '.join(splitSearch[1:])
+ searchOpertor = "AND"
+
try:
if communeNameOrZip is None:
cur.execute(f"SELECT * from \"{DB_TABLE_INSEE_NAME}\"")
else:
- cur.execute(f"SELECT * from \"{DB_TABLE_INSEE_NAME}\" WHERE {DB_COL_COMMUNE_NAME}=\"{communeNameOrZip}\" COLLATE nocase OR {DB_COL_COMMUNE_POSTE}=\"{communeNameOrZip}\"")
+ cur.execute(f"SELECT * from \"{DB_TABLE_INSEE_NAME}\" WHERE {DB_COL_COMMUNE_NAME} LIKE \"%{communeSearch}%\" COLLATE nocase {searchOpertor} {DB_COL_COMMUNE_POSTE} LIKE \"{zipSearch}%\"")
except sqlite3.OperationalError as err:
print("Error querying DB : {0}".format(err), file=sys.stderr)
return []
rows = [dict(row) for row in cur.fetchall()]
+ print(rows)
con.close()
for row in rows:
commune=Commune(
diff --git a/templates/landing_form.html b/templates/landing_form.html
index 4192ca8..26bb0f3 100644
--- a/templates/landing_form.html
+++ b/templates/landing_form.html
@@ -5,7 +5,7 @@
-
+
@@ -43,40 +43,90 @@
+
-