geolith-search-builder 0.3.2

Builds geocoding indexes from Overture Maps and OpenStreetMap: Postgres COPY files, Photon and Pelias bulk files, and the search part of a .glx file
Documentation
//! What one search build reads and writes.

use std::path::PathBuf;

use clap::ValueEnum;

/// Text index to build over the geocoding `search_text` column.
///
/// Both variants emit the same table and the same `PostGIS` location index; only
/// the text index differs.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, ValueEnum)]
pub enum PgIndexFlavor {
    /// TIN, an inverted text index with BM25 ranking, the `==>` operator, and
    /// the TINQL query language.
    ///
    /// Requires the `tin` extension, which ships on `PlanetScale` Postgres and
    /// Neki. Self-hosted Postgres cannot install it; use [`PgIndexFlavor::Gin`]
    /// there, or `lead` for local development and CI.
    #[default]
    Tin,
    /// The built-in Postgres GIN index over `to_tsvector('simple', …)`.
    ///
    /// Slower than TIN and without BM25 ranking, but it needs no extension and
    /// therefore runs on any Postgres.
    Gin,
}

/// What one search build reads and writes.
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct SearchOptions {
    /// The Overture Maps directory (hive-partitioned Parquet).
    pub data: PathBuf,
    /// The file to write.
    pub output: PathBuf,
    /// The output format: `pg-copy`, `photon`, `pelias` or `glx`.
    pub format: String,
    /// An OSM PBF whose settlements, venues and addresses join the records.
    pub osm_pbf: Option<PathBuf>,
    /// The Survey of India outline, needed when the data holds India.
    pub india_outline: Option<PathBuf>,
    /// `west,south,east,north`: only features inside it are read.
    pub bbox: Option<String>,
    /// Directory for temporary files; the system's when `None`.
    pub tmpdir: Option<PathBuf>,
    /// A file that keeps the OSM node coordinates between runs.
    pub node_store: Option<PathBuf>,
    /// Reuse the node store of an earlier run when it exists.
    pub reuse_node_cache: bool,
    /// A Wikimedia importance table for the OSM records.
    pub wikimedia_importance: Option<PathBuf>,
    /// The text index of the `pg-copy` schema.
    pub pg_index_flavor: PgIndexFlavor,
}

impl SearchOptions {
    /// Options that read `data` and write `output` as `pg-copy`, with
    /// nothing optional.
    #[must_use]
    pub fn new(data: impl Into<PathBuf>, output: impl Into<PathBuf>) -> Self {
        Self {
            data: data.into(),
            output: output.into(),
            format: "pg-copy".to_owned(),
            osm_pbf: None,
            india_outline: None,
            bbox: None,
            tmpdir: None,
            node_store: None,
            reuse_node_cache: false,
            wikimedia_importance: None,
            pg_index_flavor: PgIndexFlavor::default(),
        }
    }
}