mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2025-12-23 02:29:57 +00:00
not compiling
This commit is contained in:
@@ -5,44 +5,53 @@ use self::memmap::{Mmap, Protection};
|
||||
use std::path::PathBuf;
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
use std::rc::Rc;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct SegmentId(String);
|
||||
pub struct SegmentId(String);
|
||||
|
||||
struct IndexDirectory {
|
||||
index_path: PathBuf,
|
||||
pub trait Dir {
|
||||
fn get_file(&self, segment_id: &SegmentId, component: SegmentComponent) -> Result<File, io::Error>;
|
||||
}
|
||||
|
||||
impl IndexDirectory {
|
||||
#[derive(Clone)]
|
||||
pub struct Directory {
|
||||
dir: Rc<Dir>,
|
||||
}
|
||||
|
||||
pub fn for_path(path: PathBuf)-> IndexDirectory {
|
||||
IndexDirectory {
|
||||
index_path: path,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_segment(&self, segment_id: &SegmentId) -> SegmentDirectory {
|
||||
SegmentDirectory {
|
||||
index_path: self.index_path.clone(),
|
||||
impl Directory {
|
||||
fn segment(&self, segment_id: &SegmentId) -> Segment {
|
||||
Segment {
|
||||
directory: self.dir.clone(),
|
||||
segment_id: segment_id.clone()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub fn open(path_str: &str) -> Directory {
|
||||
let path = PathBuf::from(path_str);
|
||||
Directory {
|
||||
dir: Rc::new(FileDirectory::for_path(path)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum SegmentComponent {
|
||||
impl Dir for Directory {
|
||||
fn get_file(&self, segment_id: &SegmentId, component: SegmentComponent) -> Result<File, io::Error> {
|
||||
self.dir.get_file(segment_id, component)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum SegmentComponent {
|
||||
POSTINGS,
|
||||
POSITIONS,
|
||||
}
|
||||
|
||||
struct SegmentDirectory {
|
||||
index_path: PathBuf,
|
||||
pub struct Segment {
|
||||
directory: Rc<Dir>,
|
||||
segment_id: SegmentId,
|
||||
}
|
||||
|
||||
impl SegmentDirectory {
|
||||
impl Segment {
|
||||
|
||||
fn path_suffix(component: SegmentComponent)-> &'static str {
|
||||
match component {
|
||||
@@ -52,11 +61,7 @@ impl SegmentDirectory {
|
||||
}
|
||||
|
||||
fn get_file(&self, component: SegmentComponent) -> Result<File, io::Error> {
|
||||
let mut res = self.index_path.clone();
|
||||
let SegmentId(ref segment_id_str) = self.segment_id;
|
||||
let filename = String::new() + segment_id_str + "." + SegmentDirectory::path_suffix(component);
|
||||
res.push(filename);
|
||||
File::open(res)
|
||||
self.directory.get_file(&self.segment_id, component)
|
||||
}
|
||||
|
||||
pub fn open(&self, component: SegmentComponent) -> Result<Mmap, io::Error> {
|
||||
@@ -64,3 +69,26 @@ impl SegmentDirectory {
|
||||
Mmap::open(&file, Protection::Read)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub struct FileDirectory {
|
||||
index_path: PathBuf,
|
||||
}
|
||||
|
||||
impl FileDirectory {
|
||||
pub fn for_path(path: PathBuf)-> FileDirectory {
|
||||
FileDirectory {
|
||||
index_path: path,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Dir for FileDirectory {
|
||||
fn get_file(&self, segment_id: &SegmentId, component: SegmentComponent) -> Result<File, io::Error> {
|
||||
let mut res = self.index_path.clone();
|
||||
let SegmentId(ref segment_id_str) = *segment_id;
|
||||
let filename = String::new() + segment_id_str + "." + Segment::path_suffix(component);
|
||||
res.push(filename);
|
||||
File::open(res)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Mutex, MutexGuard};
|
||||
|
||||
#[derive(Clone,Debug,PartialEq,PartialOrd,Eq,Hash)]
|
||||
pub struct Field(pub &'static str);
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
|
||||
use std::io;
|
||||
use core::schema::Document;
|
||||
use core::schema::Term;
|
||||
use core::schema::Field ;
|
||||
use core::schema::Field;
|
||||
use core::directory::Directory;
|
||||
use core::analyzer::tokenize;
|
||||
use std::collections::{HashMap, BTreeMap};
|
||||
use core::DocId;
|
||||
@@ -57,14 +57,16 @@ impl FieldWriter {
|
||||
pub struct IndexWriter {
|
||||
max_doc: usize,
|
||||
term_writers: HashMap<Field, FieldWriter>,
|
||||
directory: Directory,
|
||||
}
|
||||
|
||||
impl IndexWriter {
|
||||
|
||||
pub fn new() -> IndexWriter {
|
||||
IndexWriter {
|
||||
pub fn open(directory: &Directory) -> IndexWriter {
|
||||
IndexWriter {
|
||||
max_doc: 0,
|
||||
term_writers: HashMap::new(),
|
||||
directory: (*directory).clone(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use parici::core::postings::{VecPostings, intersection};
|
||||
use parici::core::postings::Postings;
|
||||
use parici::core::analyzer::tokenize;
|
||||
use parici::core::writer::IndexWriter;
|
||||
use parici::core::directory::Directory;
|
||||
use parici::core::schema::{Field, Document};
|
||||
|
||||
#[test]
|
||||
@@ -25,7 +26,8 @@ fn test_tokenizer() {
|
||||
|
||||
#[test]
|
||||
fn test_indexing() {
|
||||
let mut index_writer = IndexWriter::new();
|
||||
let directory = Directory::open("toto");
|
||||
let mut index_writer = IndexWriter::open(&directory);
|
||||
let mut doc = Document::new();
|
||||
doc.set(Field("text"), &String::from("toto"));
|
||||
index_writer.add(doc);
|
||||
|
||||
Reference in New Issue
Block a user