From 7c4ac1eebc6db3a485ace1a9c6a710850263bdf9 Mon Sep 17 00:00:00 2001 From: filipriec Date: Sun, 8 Jun 2025 21:28:10 +0200 Subject: [PATCH] search via tantivy on different grpc port works perfectly well now --- .gitignore | 1 + Cargo.lock | 5 +++-- search/Cargo.toml | 1 + search/src/lib.rs | 11 ++++++++--- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index fedaa2b..0388179 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target .env +/tantivy_indexes diff --git a/Cargo.lock b/Cargo.lock index de0d55e..ac2de13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2742,6 +2742,7 @@ dependencies = [ "tantivy", "tokio", "tonic", + "tonic-reflection", "tracing", ] @@ -3815,9 +3816,9 @@ dependencies = [ [[package]] name = "tonic-reflection" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88fa815be858816dad226a49439ee90b7bcf81ab55bee72fdb217f1e6778c3ca" +checksum = "f9687bd5bfeafebdded2356950f278bba8226f0b32109537c4253406e09aafe1" dependencies = [ "prost", "prost-types", diff --git a/search/Cargo.toml b/search/Cargo.toml index a16a5dd..0273ad7 100644 --- a/search/Cargo.toml +++ b/search/Cargo.toml @@ -15,3 +15,4 @@ tracing = { workspace = true } tantivy = { workspace = true } common = { path = "../common" } +tonic-reflection = "0.13.1" diff --git a/search/src/lib.rs b/search/src/lib.rs index fa710c6..b20375f 100644 --- a/search/src/lib.rs +++ b/search/src/lib.rs @@ -2,14 +2,16 @@ use std::path::Path; use tantivy::{collector::TopDocs, query::QueryParser, Index, TantivyDocument}; -use tantivy::schema::Value; use tonic::{transport::Server, Request, Response, Status}; +use tonic_reflection::server::Builder as ReflectionBuilder; +use common::proto::multieko2::FILE_DESCRIPTOR_SET; use common::proto::multieko2::search::{ search_response::Hit, searcher_server::{Searcher, SearcherServer}, SearchRequest, SearchResponse, }; +use tantivy::schema::Value; pub struct SearcherService; @@ -84,7 +86,6 @@ impl Searcher for SearcherService { // Convert results to our response format let mut hits = Vec::new(); for (score, doc_address) in top_docs { - // FIX: Add explicit type TantivyDocument for the retrieved doc let doc: TantivyDocument = searcher.doc(doc_address).map_err( |e| { Status::internal(format!( @@ -94,7 +95,6 @@ impl Searcher for SearcherService { }, )?; - // Extract the PostgreSQL ID from the document if let Some(pg_id_value) = doc.get_first(pg_id_field) { if let Some(pg_id) = pg_id_value.as_u64() { hits.push(Hit { @@ -116,10 +116,15 @@ pub async fn run_search_service( let addr = addr.parse()?; let searcher_service = SearcherService; + let reflection_service = ReflectionBuilder::configure() + .register_encoded_file_descriptor_set(FILE_DESCRIPTOR_SET) + .build_v1()?; + println!("Search service listening on {}", addr); Server::builder() .add_service(SearcherServer::new(searcher_service)) + .add_service(reflection_service) .serve(addr) .await?;