use std::collections::HashSet;
use nodedb_types::error::NodeDbResult;
use nodedb_types::result::SearchResult;
use nodedb_types::text_search::TextSearchParams;
use crate::row_decode::decode_search_hits;
use crate::search_sql::{TextSearchRequest, text_hit_source, text_search_sql};
use super::core::NodeDbRemote;
impl NodeDbRemote {
pub(super) async fn text_search_impl(
&self,
collection: &str,
field: &str,
query: &str,
top_k: usize,
params: TextSearchParams,
allowed_ids: Option<&HashSet<String>>,
) -> NodeDbResult<Vec<SearchResult>> {
if allowed_ids.is_some_and(HashSet::is_empty) || top_k == 0 {
return Ok(Vec::new());
}
let key = match allowed_ids {
Some(_) => Some(self.identity_column(collection).await?),
None => None,
};
let sql = text_search_sql(&TextSearchRequest {
collection,
field,
query,
top_k,
params: ¶ms,
allowed: key.as_deref().zip(allowed_ids),
});
let (columns, rows) = self.simple_query_raw(&sql).await?;
decode_search_hits(&text_hit_source(collection), &columns, &rows)
}
}