use akar_optimizer::fts_estimate::FtsCardinalityEstimator;
use akar_storage::TableCatalog;
use std::sync::Arc;
#[cfg(feature = "fts-extension")]
mod inner {
use super::*;
pub(crate) struct TantivyFtsEstimator {
table_catalog: Arc<TableCatalog>,
}
impl TantivyFtsEstimator {
pub(crate) fn new(table_catalog: Arc<TableCatalog>) -> Self {
Self { table_catalog }
}
}
impl FtsCardinalityEstimator for TantivyFtsEstimator {
fn estimate_match_count(&self, index_name: &str, column_name: &str, query: &str) -> Option<u64> {
let index_dir = self.table_catalog.db_path()?.join("fts").join(index_name);
let handle = akar_fts::index::runtime_handle(&self.table_catalog, index_name, index_dir).ok()?;
handle.estimate_match_count(column_name, query).ok()
}
}
}
pub(crate) fn build(table_catalog: Arc<TableCatalog>) -> Option<Arc<dyn FtsCardinalityEstimator>> {
#[cfg(feature = "fts-extension")]
{
Some(Arc::new(inner::TantivyFtsEstimator::new(table_catalog)))
}
#[cfg(not(feature = "fts-extension"))]
{
let _ = table_catalog;
None
}
}