From 305822ad2c6dfc6675e58c729aebbe3d782bd985 Mon Sep 17 00:00:00 2001 From: Enno Nussbaum Date: Wed, 15 Jan 2025 22:59:50 +0100 Subject: [PATCH 1/5] added normalised room_codes to search for --- data/processors/export.py | 15 +++++++++++++++ server/src/setup/meilisearch.rs | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/data/processors/export.py b/data/processors/export.py index 2005e557d..bcf4704ee 100644 --- a/data/processors/export.py +++ b/data/processors/export.py @@ -41,6 +41,18 @@ def unlocalise(value: str | list[Any] | dict[str, Any]) -> Any: raise ValueError(f"Unhandled type {type(value)}") +def normalise_id(_id: str) -> str: + parts=_id.split(".") + for i in range(0, len(parts)): + parts[i]=parts[i] .lstrip('0') + if not parts[i]: + parts[i]="0" + result: str = ""; + for part in parts: + result+=part; + return ".".join(parts) + + def export_for_search(data: dict) -> None: """Export a subset of the data for the /search api""" export = [] @@ -75,9 +87,12 @@ def export_for_search(data: dict) -> None: # MeiliSearch requires an id without "." # also this puts more emphasis on the order (because "." counts as more distance) "ms_id": _id.replace(".", "-"), + "room_code": _id, + "room_code_normalised": normalise_id(_id), "id": _id, # not searchable "name": entry["name"], "arch_name": entry.get("arch_name"), + "arch_name_normalised": normalise_id(entry.get("arch_name")), "type": entry["type"], "type_common_name": entry["type_common_name"], "facet": { diff --git a/server/src/setup/meilisearch.rs b/server/src/setup/meilisearch.rs index 11498c3b9..2b233b146 100644 --- a/server/src/setup/meilisearch.rs +++ b/server/src/setup/meilisearch.rs @@ -79,9 +79,11 @@ pub async fn setup(client: &Client) -> anyhow::Result<()> { ]) .with_sortable_attributes(["_geo"]) .with_searchable_attributes([ - "ms_id", + "room_code", + "room_code_normalised", "name", "arch_name", + "arch_name_normalised", "type", "type_common_name", "parent_building_names", From aad54acfb5ed06d729368508b6e2779681076bcf Mon Sep 17 00:00:00 2001 From: Enno Nussbaum Date: Wed, 15 Jan 2025 23:01:49 +0100 Subject: [PATCH 2/5] fixed a typo --- server/src/search_executor/lexer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/search_executor/lexer.rs b/server/src/search_executor/lexer.rs index 5776ce8aa..563611c55 100644 --- a/server/src/search_executor/lexer.rs +++ b/server/src/search_executor/lexer.rs @@ -18,7 +18,7 @@ fn irregular_split(lex: &mut Lexer) -> (String, String) { } /// Removes the specified prefix and additional whitespace from the token -/// e.g used to remove the "in:" and "@" prefixes from filters +/// e.g. used to remove the "in:" and "@" prefixes from filters fn remove_prefix(lex: &mut Lexer, prefix: &'static str) -> String { lex.slice()[prefix.len()..].trim().to_string() } From 2d8c1fd695a5d7ad9b0b22b7fcb1c26cfacf936b Mon Sep 17 00:00:00 2001 From: Enno Nussbaum Date: Wed, 15 Jan 2025 23:07:34 +0100 Subject: [PATCH 3/5] added docu for normalise_id Co-authored-by: Rishab Garg --- data/processors/export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/processors/export.py b/data/processors/export.py index bcf4704ee..d6256b584 100644 --- a/data/processors/export.py +++ b/data/processors/export.py @@ -40,8 +40,8 @@ def unlocalise(value: str | list[Any] | dict[str, Any]) -> Any: return {k: unlocalise(v) for k, v in value.items()} raise ValueError(f"Unhandled type {type(value)}") - def normalise_id(_id: str) -> str: + """removes leading zeros from all point-separated parts of input string""" parts=_id.split(".") for i in range(0, len(parts)): parts[i]=parts[i] .lstrip('0') From 7b75a3ca8f5b1865f0a53bdef4508a06a0cfc08a Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Thu, 16 Jan 2025 11:17:22 +0100 Subject: [PATCH 4/5] change the formatting of normalise_id --- data/processors/export.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/data/processors/export.py b/data/processors/export.py index d6256b584..02f1d8898 100644 --- a/data/processors/export.py +++ b/data/processors/export.py @@ -40,16 +40,17 @@ def unlocalise(value: str | list[Any] | dict[str, Any]) -> Any: return {k: unlocalise(v) for k, v in value.items()} raise ValueError(f"Unhandled type {type(value)}") + def normalise_id(_id: str) -> str: - """removes leading zeros from all point-separated parts of input string""" - parts=_id.split(".") + """Remove leading zeros from all point-separated parts of input string""" + parts = _id.split(".") for i in range(0, len(parts)): - parts[i]=parts[i] .lstrip('0') + parts[i] = parts[i].lstrip("0") if not parts[i]: - parts[i]="0" - result: str = ""; + parts[i] = "0" + result: str = "" for part in parts: - result+=part; + result += part return ".".join(parts) From b18fd0b152aa9a009a44cb699c7f93c73b929868 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Thu, 16 Jan 2025 11:37:38 +0100 Subject: [PATCH 5/5] Changed to a list comprehension --- data/processors/export.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/data/processors/export.py b/data/processors/export.py index 02f1d8898..587937a0e 100644 --- a/data/processors/export.py +++ b/data/processors/export.py @@ -43,14 +43,7 @@ def unlocalise(value: str | list[Any] | dict[str, Any]) -> Any: def normalise_id(_id: str) -> str: """Remove leading zeros from all point-separated parts of input string""" - parts = _id.split(".") - for i in range(0, len(parts)): - parts[i] = parts[i].lstrip("0") - if not parts[i]: - parts[i] = "0" - result: str = "" - for part in parts: - result += part + parts = [part.lstrip("0") or "0" for part in _id.split(".")] return ".".join(parts)