pub mod browse;
pub mod document;
pub mod metadata;
pub mod stats;
use crate::index::traits::{SearchFilters, SearchIndex};
use crate::model::directory::{BrowseResponse, DirectoryDocument};
use crate::model::document::{
DocumentDetail, DocumentMetadata, DocumentSummary, HeadingInfo, IndexStats,
MetadataQueryResponse, ParseError, SearchResponse, SearchResult,
};
impl super::database::RepositoryIndex {
pub fn browse_directory(
&self,
path: &str,
depth: usize,
limit: usize,
) -> Result<BrowseResponse, anyhow::Error> {
browse::browse_directory(self, path, depth, limit)
}
pub fn get_document(
&self,
doc_path: &str,
include: &[String],
max_body_chars: usize,
) -> Result<DocumentDetail, anyhow::Error> {
document::get_document(self, doc_path, include, max_body_chars)
}
pub fn get_section(
&self,
doc_path: &str,
heading: &str,
max_chars: usize,
) -> Result<Option<(String, String)>, anyhow::Error> {
document::get_section(self, doc_path, heading, max_chars)
}
pub fn search(
&self,
query: &str,
path_prefix: Option<&str>,
types: Option<&[String]>,
tags: Option<&[String]>,
limit: usize,
) -> Result<SearchResponse, anyhow::Error> {
self.search_index.search(
query,
&SearchFilters {
path_prefix: path_prefix.map(str::to_string),
concept_types: types.map(<[String]>::to_vec),
tags: tags.map(<[String]>::to_vec),
},
limit,
)
}
pub fn query_metadata(
&self,
filters: &std::collections::HashMap<String, serde_json::Value>,
select: &[String],
limit: usize,
) -> Result<MetadataQueryResponse, anyhow::Error> {
metadata::query_metadata(self, filters, select, limit)
}
pub fn get_recently_modified(
&self,
limit: usize,
) -> Result<Vec<DocumentSummary>, anyhow::Error> {
stats::get_recently_modified(self, limit)
}
pub fn get_stats(&self) -> Result<IndexStats, anyhow::Error> {
stats::get_stats(self)
}
}
fn slugify(text: &str) -> String {
text.to_lowercase()
.chars()
.filter(|c| c.is_alphanumeric() || *c == ' ' || *c == '-' || *c == '_')
.collect::<String>()
.split_whitespace()
.collect::<Vec<_>>()
.join("-")
}