pass doc by ref

This commit is contained in:
Paul Masurel
2016-03-27 00:32:51 +09:00
parent 56b6907e71
commit 40a2435efa
2 changed files with 9 additions and 14 deletions

View File

@@ -18,7 +18,6 @@ pub struct IndexWriter {
schema: Schema,
}
impl IndexWriter {
pub fn open(directory: &Index) -> io::Result<IndexWriter> {
@@ -32,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(&mut self, doc: &Document) -> io::Result<()> {
Rc::get_mut(&mut self.segment_writer).unwrap().add(&doc, &self.schema)
}
pub fn commit(&mut self,) -> io::Result<Segment> {
@@ -83,10 +82,6 @@ impl SegmentWriter {
self.segment_serializer.close()
}
pub fn max_doc(&self,) -> DocId {
self.max_doc
}
pub fn segment(&self,) -> Segment {
self.segment_serializer.segment()
}
@@ -102,7 +97,7 @@ impl SegmentWriter {
})
}
pub fn add(&mut self, doc: Document, schema: &Schema) -> io::Result<()> {
pub fn add(&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);

View File

@@ -86,17 +86,17 @@ mod tests {
{
let mut doc = Document::new();
doc.set(&text_field, "af b");
index_writer.add(doc).unwrap();
index_writer.add(&doc).unwrap();
}
{
let mut doc = Document::new();
doc.set(&text_field, "a b c");
index_writer.add(doc).unwrap();
index_writer.add(&doc).unwrap();
}
{
let mut doc = Document::new();
doc.set(&text_field, "a b c d");
index_writer.add(doc).unwrap();
index_writer.add(&doc).unwrap();
}
let commit_result = index_writer.commit();
@@ -123,17 +123,17 @@ mod tests {
{
let mut doc = Document::new();
doc.set(&text_field, "af b");
index_writer.add(doc).unwrap();
index_writer.add(&doc).unwrap();
}
{
let mut doc = Document::new();
doc.set(&text_field, "a b c");
index_writer.add(doc).unwrap();
index_writer.add(&doc).unwrap();
}
{
let mut doc = Document::new();
doc.set(&text_field, "a b c d");
index_writer.add(doc).unwrap();
index_writer.add(&doc).unwrap();
}
let commit_result = index_writer.commit();
commit_result.unwrap();