diff options
Diffstat (limited to 'src/ft/mod.rs')
-rw-r--r-- | src/ft/mod.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/ft/mod.rs b/src/ft/mod.rs new file mode 100644 index 0000000..6b91848 --- /dev/null +++ b/src/ft/mod.rs @@ -0,0 +1,30 @@ +use std::path::PathBuf; +use std::path::Path; + +use anyhow::Result; +use crate::Server; + +pub trait FileTypeParser { + fn parse(&self, server: &Server, path: &Path, ext: &str, doc: tantivy::Document) -> Result<tantivy::Document>; +} + + +pub struct TextFileParser; + +impl FileTypeParser for TextFileParser { + fn parse(&self, server: &Server, path: &Path, ext: &str, mut doc: tantivy::Document) -> Result<tantivy::Document> { + let body = std::fs::read_to_string(path)?; + doc.add_text(server.field_body(), body); + Ok(doc) + } +} + + +pub struct MarkdownParser; + +impl FileTypeParser for MarkdownParser { + fn parse(&self, server: &Server, path: &Path, ext: &str, doc: tantivy::Document) -> Result<tantivy::Document> { + unimplemented!() + } +} + |