geocoder_core/profile/
default.rs1use super::{Boost, FieldSpec, Profile};
5use crate::doc::{Document, first_str};
6use crate::text::{Token, TokenKind, is_digit};
7
8pub const FIELDS: &[FieldSpec] = &[
10 FieldSpec {
11 key: "name",
12 boost: Boost::Const(4.0),
13 required: true,
14 },
15 FieldSpec::new("street"),
16 FieldSpec {
17 key: "postcode",
18 boost: Boost::ByType {
19 doc_type: "municipality",
20 matched: 1.2,
21 otherwise: 1.0,
22 },
23 required: false,
24 },
25 FieldSpec::new("city"),
26 FieldSpec::new("context"),
27];
28
29pub const FILTERS: &[&str] = &["type", "postcode"];
31
32pub struct DefaultProfile;
34
35impl Profile for DefaultProfile {
36 fn name(&self) -> &'static str {
37 "default"
38 }
39
40 fn version(&self) -> u32 {
41 1
42 }
43}
44
45pub fn flag_housenumber(mut tokens: Vec<Token>) -> Vec<Token> {
47 for token in &mut tokens {
48 if token.is_first && is_digit(token) {
49 token.kind = Some(TokenKind::Housenumber);
50 }
51 }
52 tokens
53}
54
55pub fn make_labels(doc: &Document, housenumber: Option<&str>) -> Vec<String> {
57 let mut labels = crate::doc::str_values(doc, "name");
58 let Some(first) = labels.first().cloned() else {
59 return labels;
60 };
61 let mut label = first;
62 if let Some(city) = first_str(doc, "city").filter(|c| !c.is_empty())
63 && city != label
64 {
65 if let Some(postcode) = first_str(doc, "postcode").filter(|p| !p.is_empty()) {
66 label = format!("{label} {postcode}");
67 }
68 label = format!("{label} {city}");
69 labels.insert(0, label.clone());
70 }
71 if let Some(housenumber) = housenumber.filter(|h| !h.is_empty()) {
72 labels.insert(0, format!("{housenumber} {label}"));
73 }
74 labels
75}