diff options
| author | Alexander_Kabui <alexanderkabui@proton.me> | 2026-11-17 12:11:19 +0300 |
|---|---|---|
| committer | Alexander_Kabui <alexanderkabui@proton.me> | 2026-11-17 14:06:50 +0300 |
| commit | f76043bf82b6c86b5e844b27b53e957d770aeb33 (patch) | |
| tree | 5b4257c2523410f077e9fbc4f71f3fd797360b9f /src | |
| parent | e13bbd27d0b7addd277d0f50d9e90fee2a936211 (diff) | |
| download | genenetwork4-search/extract-engine.tar.gz | |
* src/search (engine): no default arm, so a wrong name is refused. search/extract-engine
An unrecognised SEARCH_ENGINE used to fall through to the gn3 proxy, which turned a typo into a silently different engine. The arms are now explicit - "crate"/"native" for the in-process engine, "forward" for the proxy - and anything else returns the value it was given. src/search/native.rs is deleted; the former name resolves through the same arm.
Diffstat (limited to 'src')
| -rw-r--r-- | src/search/mod.rs | 20 | ||||
| -rw-r--r-- | src/search/native.rs | 43 |
2 files changed, 15 insertions, 48 deletions
diff --git a/src/search/mod.rs b/src/search/mod.rs index f8797e7..3e2611e 100644 --- a/src/search/mod.rs +++ b/src/search/mod.rs @@ -86,14 +86,13 @@ //! impl is speculation). The overnight schedule overrides that: the //! [`Engine`] trait is defined so the native engine can land behind //! it. The gn3-forwarding implementation ([`gn3::Gn3`]) remains the -//! default backend; [`native::Native`] is opt-in via `SEARCH_ENGINE` +//! default backend; the in-process engine is opt-in via `SEARCH_ENGINE` //! (see [`search`]). use std::future::Future; pub mod gn3; pub mod gnindex; -pub mod native; /// Run a search through the configured engine: the gn3 forwarder by /// default, the native xapian engine when `SEARCH_ENGINE=native` @@ -106,9 +105,20 @@ pub async fn search( page: u64, ) -> Result<Vec<SearchHit>, SearchError> { match crate::config::Config::load().search_engine.as_str() { - "native" => native::Native.search(q, type_, limit, page).await, - "crate" => gnindex::CrateEngine::from_config().search(q, type_, limit, page).await, - _ => gn3::Gn3.search(q, type_, limit, page).await, + // The in-process engine, in the crate; `native` is its former name. + "crate" | "native" => { + gnindex::CrateEngine::from_config() + .search(q, type_, limit, page) + .await + } + // The gn3 proxy, asked over HTTP. Deleted together with gn3. + "forward" => gn3::Gn3.search(q, type_, limit, page).await, + // No default arm: an unrecognised value is a misconfiguration, and a + // silent fall-through would hide it behind whichever engine happened to + // be last in the match. + other => Err(SearchError::Internal(format!( + "SEARCH_ENGINE={other:?} is not an engine: expected \"crate\", \"native\" or \"forward\"" + ))), } } diff --git a/src/search/native.rs b/src/search/native.rs deleted file mode 100644 index 667e786..0000000 --- a/src/search/native.rs +++ /dev/null @@ -1,43 +0,0 @@ -//! The native [`Engine`]: a thin wrapper over the extracted engine. -//! -//! The engine itself — the `QueryParser` configuration and every -//! prefix/slot registration, the checked parse, the Hs/Mm and numeric-range -//! guards, `open_database` and its pre-checks, the full-match-set fetch and -//! the doc-data decode — now lives in the `gn-search` crate -//! (`gn-search/src/native.rs`; before the move this file was the whole -//! 1003-line engine, and that code is unchanged there). -//! -//! What is left here is the [`Engine`] impl and nothing else: it delegates -//! to [`CrateEngine`], so `SEARCH_ENGINE=native` and `SEARCH_ENGINE=crate` -//! are the same engine, reached through the same seam, with the same error -//! classes — including the unset-index `Internal` that names -//! `XAPIAN_DB_PATH`. They cannot diverge, and no behaviour above this -//! module learns that the engine moved. -//! -//! The async shell stays here rather than in the crate because xapian calls -//! are synchronous C++ work: [`CrateEngine`] keeps them off the runtime's -//! workers with `spawn_blocking` (the house pattern, cf. every -//! `spawn_blocking` handler in `src/routes`), and that is the only thing -//! this module adds. - -use super::gnindex::CrateEngine; -use super::{Engine, SearchError, SearchHit}; - -/// The native xapian search engine. Configure the index directory with -/// `XAPIAN_DB_PATH` and select it with `SEARCH_ENGINE=native`; the -/// default remains the gn3 forwarder (see [`crate::search::search`]). -pub struct Native; - -impl Engine for Native { - async fn search( - &self, - q: &str, - type_: &str, - limit: u64, - page: u64, - ) -> Result<Vec<SearchHit>, SearchError> { - CrateEngine::from_config() - .search(q, type_, limit, page) - .await - } -} |
