-
-
Notifications
You must be signed in to change notification settings - Fork 671
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding dragon API to build index without any thread.
Closes #1487
- Loading branch information
1 parent
a451f6d
commit e40d638
Showing
7 changed files
with
102 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use crate::indexer::operation::AddOperation; | ||
use crate::indexer::segment_updater::save_metas; | ||
use crate::indexer::SegmentWriter; | ||
use crate::{Directory, Document, Index, IndexMeta, Opstamp, Segment}; | ||
|
||
#[doc(hidden)] | ||
pub struct IndexSimpleWriter { | ||
segment_writer: SegmentWriter, | ||
segment: Segment, | ||
opstamp: Opstamp, | ||
} | ||
|
||
impl IndexSimpleWriter { | ||
pub fn new(index: Index, mem_budget: usize) -> crate::Result<Self> { | ||
let segment = index.new_segment(); | ||
let segment_writer = SegmentWriter::for_segment(mem_budget, segment.clone())?; | ||
Ok(Self { | ||
segment_writer, | ||
segment, | ||
opstamp: 0, | ||
}) | ||
} | ||
|
||
pub fn add_document(&mut self, document: Document) -> crate::Result<()> { | ||
let opstamp = self.opstamp; | ||
self.opstamp += 1; | ||
self.segment_writer | ||
.add_document(AddOperation { opstamp, document }) | ||
} | ||
|
||
pub fn finalize(self) -> crate::Result<Index> { | ||
let max_doc = self.segment_writer.max_doc(); | ||
self.segment_writer.finalize()?; | ||
let segment: Segment = self.segment.with_max_doc(max_doc); | ||
let index = segment.index(); | ||
let index_meta = IndexMeta { | ||
index_settings: index.settings().clone(), | ||
segments: vec![segment.meta().clone()], | ||
schema: index.schema().clone(), | ||
opstamp: 0, | ||
payload: None, | ||
}; | ||
save_metas(&index_meta, index.directory())?; | ||
index.directory().sync_directory()?; | ||
Ok(segment.index().clone()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters