Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added normalised roomcodes to search for #1766

Merged
merged 7 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions data/processors/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ 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')
if not parts[i]:
parts[i]="0"
result: str = "";
for part in parts:
result+=part;
return ".".join(parts)

CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved

def export_for_search(data: dict) -> None:
"""Export a subset of the data for the /search api"""
Expand Down Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion server/src/search_executor/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn irregular_split(lex: &mut Lexer<Token>) -> (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<Token>, prefix: &'static str) -> String {
lex.slice()[prefix.len()..].trim().to_string()
}
Expand Down
4 changes: 3 additions & 1 deletion server/src/setup/meilisearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down