diff --git a/data/processors/export.py b/data/processors/export.py index 2005e557d..587937a0e 100644 --- a/data/processors/export.py +++ b/data/processors/export.py @@ -41,6 +41,12 @@ def unlocalise(value: str | list[Any] | dict[str, Any]) -> Any: raise ValueError(f"Unhandled type {type(value)}") +def normalise_id(_id: str) -> str: + """Remove leading zeros from all point-separated parts of input string""" + parts = [part.lstrip("0") or "0" for part in _id.split(".")] + return ".".join(parts) + + def export_for_search(data: dict) -> None: """Export a subset of the data for the /search api""" export = [] @@ -75,9 +81,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/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() } 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",