Skip to main content

geolith_search_builder/
options.rs

1//! What one search build reads and writes.
2
3use std::path::PathBuf;
4
5use clap::ValueEnum;
6
7/// Text index to build over the geocoding `search_text` column.
8///
9/// Both variants emit the same table and the same `PostGIS` location index; only
10/// the text index differs.
11#[non_exhaustive]
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, ValueEnum)]
13pub enum PgIndexFlavor {
14    /// TIN, an inverted text index with BM25 ranking, the `==>` operator, and
15    /// the TINQL query language.
16    ///
17    /// Requires the `tin` extension, which ships on `PlanetScale` Postgres and
18    /// Neki. Self-hosted Postgres cannot install it; use [`PgIndexFlavor::Gin`]
19    /// there, or `lead` for local development and CI.
20    #[default]
21    Tin,
22    /// The built-in Postgres GIN index over `to_tsvector('simple', …)`.
23    ///
24    /// Slower than TIN and without BM25 ranking, but it needs no extension and
25    /// therefore runs on any Postgres.
26    Gin,
27}
28
29/// What one search build reads and writes.
30#[derive(Debug, Clone)]
31#[non_exhaustive]
32pub struct SearchOptions {
33    /// The Overture Maps directory (hive-partitioned Parquet).
34    pub data: PathBuf,
35    /// The file to write.
36    pub output: PathBuf,
37    /// The output format: `pg-copy`, `photon`, `pelias` or `glx`.
38    pub format: String,
39    /// An OSM PBF whose settlements, venues and addresses join the records.
40    pub osm_pbf: Option<PathBuf>,
41    /// The Survey of India outline, needed when the data holds India.
42    pub india_outline: Option<PathBuf>,
43    /// `west,south,east,north`: only features inside it are read.
44    pub bbox: Option<String>,
45    /// Directory for temporary files; the system's when `None`.
46    pub tmpdir: Option<PathBuf>,
47    /// A file that keeps the OSM node coordinates between runs.
48    pub node_store: Option<PathBuf>,
49    /// Reuse the node store of an earlier run when it exists.
50    pub reuse_node_cache: bool,
51    /// A Wikimedia importance table for the OSM records.
52    pub wikimedia_importance: Option<PathBuf>,
53    /// The text index of the `pg-copy` schema.
54    pub pg_index_flavor: PgIndexFlavor,
55}
56
57impl SearchOptions {
58    /// Options that read `data` and write `output` as `pg-copy`, with
59    /// nothing optional.
60    #[must_use]
61    pub fn new(data: impl Into<PathBuf>, output: impl Into<PathBuf>) -> Self {
62        Self {
63            data: data.into(),
64            output: output.into(),
65            format: "pg-copy".to_owned(),
66            osm_pbf: None,
67            india_outline: None,
68            bbox: None,
69            tmpdir: None,
70            node_store: None,
71            reuse_node_cache: false,
72            wikimedia_importance: None,
73            pg_index_flavor: PgIndexFlavor::default(),
74        }
75    }
76}