mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-05-18 09:10:41 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
1
build.rs
1
build.rs
@@ -4,6 +4,7 @@ fn main() {
|
||||
gcc::Config::new()
|
||||
.cpp(true)
|
||||
.flag("-std=c++11")
|
||||
.flag("-O3")
|
||||
.include("./cpp/SIMDCompressionAndIntersection/include")
|
||||
.object("cpp/SIMDCompressionAndIntersection/bitpacking.o")
|
||||
.object("cpp/SIMDCompressionAndIntersection/integratedbitpacking.o")
|
||||
|
||||
@@ -3,6 +3,7 @@ use std::path::{PathBuf, Path};
|
||||
use std::collections::HashMap;
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::fs::File;
|
||||
use std::fs;
|
||||
use core::schema::Schema;
|
||||
use std::io::Write;
|
||||
use std::io::BufWriter;
|
||||
@@ -20,6 +21,7 @@ use fst::raw::MmapReadOnly;
|
||||
use rustc_serialize::json;
|
||||
use atomicwrites;
|
||||
use tempdir::TempDir;
|
||||
use std::io::Read;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SegmentId(pub String);
|
||||
@@ -132,8 +134,8 @@ impl Directory {
|
||||
}
|
||||
|
||||
pub fn load_metas(&self,) -> Result<()> {
|
||||
match self.inner_directory.read() {
|
||||
Ok(dir) => dir.load_metas(),
|
||||
match self.inner_directory.write() {
|
||||
Ok(mut dir) => { dir.load_metas() },
|
||||
Err(e) => Err(Error::LockError(format!("Could not get read lock {:?} for directory", e)))
|
||||
}
|
||||
}
|
||||
@@ -248,8 +250,18 @@ impl InnerDirectory {
|
||||
Ok(directory)
|
||||
}
|
||||
|
||||
pub fn load_metas(&self,) -> Result<()> {
|
||||
// TODO load segment info
|
||||
pub fn load_metas(&mut self,) -> Result<()> {
|
||||
let meta_filepath = self.meta_filepath();
|
||||
let meta_data = fs::metadata(&meta_filepath);
|
||||
if meta_data.is_err() {
|
||||
// There is no meta data file.
|
||||
// TODO check that the directory is empty.
|
||||
return Ok(());
|
||||
}
|
||||
let mut meta_file = File::open(&meta_filepath).unwrap();
|
||||
let mut meta_content = String::new();
|
||||
meta_file.read_to_string(&mut meta_content);
|
||||
self.metas = json::decode(&meta_content).unwrap();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,14 @@ pub struct SegmentPostings {
|
||||
}
|
||||
|
||||
impl SegmentPostings {
|
||||
|
||||
pub fn empty()-> SegmentPostings {
|
||||
SegmentPostings {
|
||||
doc_id: 0,
|
||||
doc_ids: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_data(data: &[u8]) -> SegmentPostings {
|
||||
let mut cursor = Cursor::new(data);
|
||||
let doc_freq = cursor.read_u32::<BigEndian>().unwrap() as usize;
|
||||
@@ -139,6 +147,7 @@ impl SegmentReader {
|
||||
}
|
||||
None => {
|
||||
segment_postings.clear();
|
||||
segment_postings.push(SegmentPostings::empty());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,11 +12,9 @@ impl Searcher {
|
||||
pub fn for_directory(directory: Directory) -> Searcher {
|
||||
let mut segment_readers: Vec<SegmentReader> = Vec::new();
|
||||
for segment in directory.segments().into_iter() {
|
||||
println!("{:?}", segment);
|
||||
match SegmentReader::open(segment.clone()) {
|
||||
Ok(segment_reader) => {
|
||||
segment_readers.push(segment_reader);
|
||||
println!("opened {:?}", segment);
|
||||
}
|
||||
Err(err) => {
|
||||
// TODO return err
|
||||
|
||||
@@ -108,13 +108,6 @@ pub struct SegmentWriter {
|
||||
segment_serializer: SimpleSegmentSerializer,
|
||||
}
|
||||
|
||||
// impl Drop for SegmentWriter {
|
||||
// fn drop(&mut self) {
|
||||
// println!("num tokens {}", self.num_tokens);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
impl SegmentWriter {
|
||||
|
||||
// write on disk all of the stuff that
|
||||
|
||||
Reference in New Issue
Block a user