From dfc38880b32112f2dda6b6c55c6c55830b0c92e7 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 18 Apr 2021 10:41:38 +0200 Subject: Move to dedicated types for filetype parsing Signed-off-by: Matthias Beyer --- src/ft/mod.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/ft/mod.rs (limited to 'src/ft/mod.rs') 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; +} + + +pub struct TextFileParser; + +impl FileTypeParser for TextFileParser { + fn parse(&self, server: &Server, path: &Path, ext: &str, mut doc: tantivy::Document) -> Result { + 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 { + unimplemented!() + } +} + -- cgit v1.2.3