use crate::error::Result;
use crate::lexical::core::document::Document;
use crate::lexical::core::field::FieldValue;
use crate::lexical::index::structures::bkd_tree::BKDTree;
use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct ReaderTermInfo {
pub field: String,
pub term: String,
pub doc_freq: u64,
pub total_freq: u64,
pub posting_offset: u64,
pub posting_size: u64,
}
#[derive(Debug, Clone)]
pub struct FieldStats {
pub field: String,
pub unique_terms: u64,
pub total_terms: u64,
pub doc_count: u64,
pub avg_length: f64,
pub min_length: u64,
pub max_length: u64,
}
#[derive(Debug, Clone)]
pub struct FieldStatistics {
pub avg_field_length: f64,
pub doc_count: u64,
pub total_terms: u64,
}
pub trait LexicalIndexReader: Send + Sync + std::fmt::Debug {
fn doc_count(&self) -> u64;
fn max_doc(&self) -> u64;
fn is_deleted(&self, doc_id: u64) -> bool;
fn document(&self, doc_id: u64) -> Result<Option<Document>>;
fn term_info(&self, field: &str, term: &str) -> Result<Option<ReaderTermInfo>>;
fn postings(&self, field: &str, term: &str) -> Result<Option<Box<dyn PostingIterator>>>;
fn field_stats(&self, field: &str) -> Result<Option<FieldStats>>;
fn close(&mut self) -> Result<()>;
fn is_closed(&self) -> bool;
fn get_bkd_tree(&self, field: &str) -> Result<Option<Arc<dyn BKDTree>>> {
let _ = field;
Ok(None)
}
fn term_doc_freq(&self, field: &str, term: &str) -> Result<u64> {
match self.term_info(field, term)? {
Some(term_info) => Ok(term_info.doc_freq),
None => Ok(0),
}
}
fn field_statistics(&self, field: &str) -> Result<FieldStatistics> {
match self.field_stats(field)? {
Some(field_stats) => Ok(FieldStatistics {
avg_field_length: field_stats.avg_length,
doc_count: field_stats.doc_count,
total_terms: field_stats.total_terms,
}),
None => Ok(FieldStatistics {
avg_field_length: 10.0, doc_count: 0,
total_terms: 0,
}),
}
}
fn as_any(&self) -> &dyn std::any::Any;
fn get_doc_value(&self, field: &str, doc_id: u64) -> Result<Option<FieldValue>> {
let _ = (field, doc_id);
Ok(None)
}
fn has_doc_values(&self, field: &str) -> bool {
let _ = field;
false
}
fn doc_ids(&self) -> Result<Vec<u64>> {
Ok(Vec::new())
}
}
pub trait PostingIterator: Send + std::fmt::Debug {
fn doc_id(&self) -> u64;
fn term_freq(&self) -> u64;
fn positions(&self) -> Result<Vec<u64>>;
fn next(&mut self) -> Result<bool>;
fn skip_to(&mut self, target: u64) -> Result<bool>;
fn cost(&self) -> u64;
}