blob: 6b918485f33c1020676113054e8146314cb7d0d2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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!()
}
}
|