feat: Add parse record function

This commit is contained in:
2023-10-25 22:31:50 +02:00
parent 1589fdb6b1
commit 413ec2a160
2 changed files with 28 additions and 1 deletions

View File

@@ -173,11 +173,26 @@ impl Rustysearch {
///
pub fn make_segment_name(&self, term: &str) -> String {
let term = &self.hash_name(term, 6);
let index_file_name = format!("{}.index", term);
let segment_path = Path::new(&self.index_path).join(index_file_name);
let segment_path = segment_path.to_str().unwrap().to_string();
fs::write(&segment_path, "").expect("Unable to create segment file");
return segment_path;
}
/// Given a ``line`` from the segment file, this returns the term & its info.
///
/// The term info is stored as serialized JSON. The default separator
/// between the term & info is the ``\t`` character, which would never
/// appear in a term due to the way tokenization is done.
///
pub fn parse_record(&self, line: &str) -> (String, String) {
let mut parts = line.trim().split("\t");
let term = parts.next().unwrap().to_string();
let info = parts.next().unwrap().to_string();
(term, info)
}
}