search via tantivy on different grpc port works perfectly well now

This commit is contained in:
filipriec
2025-06-08 21:28:10 +02:00
parent 4b4301ad49
commit 7c4ac1eebc
4 changed files with 13 additions and 5 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
/target /target
.env .env
/tantivy_indexes

5
Cargo.lock generated
View File

@@ -2742,6 +2742,7 @@ dependencies = [
"tantivy", "tantivy",
"tokio", "tokio",
"tonic", "tonic",
"tonic-reflection",
"tracing", "tracing",
] ]
@@ -3815,9 +3816,9 @@ dependencies = [
[[package]] [[package]]
name = "tonic-reflection" name = "tonic-reflection"
version = "0.13.0" version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88fa815be858816dad226a49439ee90b7bcf81ab55bee72fdb217f1e6778c3ca" checksum = "f9687bd5bfeafebdded2356950f278bba8226f0b32109537c4253406e09aafe1"
dependencies = [ dependencies = [
"prost", "prost",
"prost-types", "prost-types",

View File

@@ -15,3 +15,4 @@ tracing = { workspace = true }
tantivy = { workspace = true } tantivy = { workspace = true }
common = { path = "../common" } common = { path = "../common" }
tonic-reflection = "0.13.1"

View File

@@ -2,14 +2,16 @@
use std::path::Path; use std::path::Path;
use tantivy::{collector::TopDocs, query::QueryParser, Index, TantivyDocument}; use tantivy::{collector::TopDocs, query::QueryParser, Index, TantivyDocument};
use tantivy::schema::Value;
use tonic::{transport::Server, Request, Response, Status}; 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::{ use common::proto::multieko2::search::{
search_response::Hit, search_response::Hit,
searcher_server::{Searcher, SearcherServer}, searcher_server::{Searcher, SearcherServer},
SearchRequest, SearchResponse, SearchRequest, SearchResponse,
}; };
use tantivy::schema::Value;
pub struct SearcherService; pub struct SearcherService;
@@ -84,7 +86,6 @@ impl Searcher for SearcherService {
// Convert results to our response format // Convert results to our response format
let mut hits = Vec::new(); let mut hits = Vec::new();
for (score, doc_address) in top_docs { 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( let doc: TantivyDocument = searcher.doc(doc_address).map_err(
|e| { |e| {
Status::internal(format!( 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_value) = doc.get_first(pg_id_field) {
if let Some(pg_id) = pg_id_value.as_u64() { if let Some(pg_id) = pg_id_value.as_u64() {
hits.push(Hit { hits.push(Hit {
@@ -116,10 +116,15 @@ pub async fn run_search_service(
let addr = addr.parse()?; let addr = addr.parse()?;
let searcher_service = SearcherService; 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); println!("Search service listening on {}", addr);
Server::builder() Server::builder()
.add_service(SearcherServer::new(searcher_service)) .add_service(SearcherServer::new(searcher_service))
.add_service(reflection_service)
.serve(addr) .serve(addr)
.await?; .await?;