summaryrefslogtreecommitdiffstats
path: root/src/ft/mod.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-04-18 10:41:38 +0200
committerMatthias Beyer <mail@beyermatthias.de>2021-04-18 11:00:19 +0200
commitdfc38880b32112f2dda6b6c55c6c55830b0c92e7 (patch)
treee79c652eb48b78c9a22e10d61fadd05335cc34f5 /src/ft/mod.rs
parent8dfd21ed430e9407880a5fc640b3351ccf34db5c (diff)
Move to dedicated types for filetype parsing
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/ft/mod.rs')
-rw-r--r--src/ft/mod.rs30
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!()
+ }
+}
+