Prettifying json

This commit is contained in:
Paul Masurel
2016-03-27 15:39:22 +09:00
parent e477c28025
commit e2c7d500ec
2 changed files with 9 additions and 7 deletions

View File

@@ -184,11 +184,13 @@ impl Index {
}
pub fn save_metas(&mut self,) -> io::Result<()> {
let encoded = {
let metas_lock = self.metas.read().unwrap();
json::encode(&*metas_lock).unwrap()
let mut w = Vec::new();
{
let metas_lock = self.metas.read().unwrap() ;
let data = write!(&mut w, "{}\n", json::as_pretty_json(&*metas_lock));
};
try!(self.rw_directory()).atomic_write(&META_FILEPATH, encoded.as_bytes())
try!(self.rw_directory())
.atomic_write(&META_FILEPATH, &w[..])
}
}

View File

@@ -31,8 +31,8 @@ impl IndexWriter {
})
}
pub fn add(&mut self, doc: &Document) -> io::Result<()> {
Rc::get_mut(&mut self.segment_writer).unwrap().add(&doc, &self.schema)
pub fn add_document(&mut self, doc: &Document) -> io::Result<()> {
Rc::get_mut(&mut self.segment_writer).unwrap().add_document(&doc, &self.schema)
}
pub fn commit(&mut self,) -> io::Result<Segment> {
@@ -96,7 +96,7 @@ impl SegmentWriter {
})
}
pub fn add(&mut self, doc: &Document, schema: &Schema) -> io::Result<()> {
pub fn add_document(&mut self, doc: &Document, schema: &Schema) -> io::Result<()> {
let doc_id = self.max_doc;
for field_value in doc.text_fields() {
let field_options = schema.text_field_options(&field_value.field);