[][src]Struct tantivy::IndexWriter

pub struct IndexWriter { /* fields omitted */ }

IndexWriter is the user entry-point to add document to an index.

It manages a small number of indexing thread, as well as a shared indexing queue. Each indexing thread builds its own independent Segment, via a SegmentWriter object.

Methods

impl IndexWriter[src]

pub fn wait_merging_threads(self) -> Result<()>[src]

The index writer

pub fn new_segment(&self) -> Segment[src]

Creates a new segment.

This method is useful only for users trying to do complex operations, like converting an index format to another.

It is safe to start writing file associated to the new Segment. These will not be garbage collected as long as an instance object of SegmentMeta object associated to the new Segment is "alive".

pub fn get_merge_policy(&self) -> Arc<Box<dyn MergePolicy>>[src]

Accessor to the merge policy.

pub fn set_merge_policy(&self, merge_policy: Box<dyn MergePolicy>)[src]

Set the merge policy.

pub fn garbage_collect_files(&mut self) -> Result<()>[src]

Detects and removes the files that are not used by the index anymore.

pub fn merge(
    &mut self,
    segment_ids: &[SegmentId]
) -> Result<impl Future<Item = SegmentMeta, Error = Canceled>>
[src]

Merges a given list of segments

segment_ids is required to be non-empty.

pub fn rollback(&mut self) -> Result<()>[src]

Rollback to the last commit

This cancels all of the update that happened before after the last commit. After calling rollback, the index is in the same state as it was after the last commit.

The opstamp at the last commit is returned.

pub fn prepare_commit(&mut self) -> Result<PreparedCommit>[src]

Prepares a commit.

Calling prepare_commit() will cut the indexing queue. All pending documents will be sent to the indexing workers. They will then terminate, regardless of the size of their current segment and flush their work on disk.

Once a commit is "prepared", you can either call

  • .commit(): to accept this commit
  • .abort(): to cancel this commit.

In the current implementation, PreparedCommit borrows the IndexWriter mutably so we are guaranteed that no new document can be added as long as it is committed or is dropped.

It is also possible to add a payload to the commit using this API. See PreparedCommit::set_payload()

pub fn commit(&mut self) -> Result<u64>[src]

Commits all of the pending changes

A call to commit blocks. After it returns, all of the document that were added since the last commit are published and persisted.

In case of a crash or an hardware failure (as long as the hard disk is spared), it will be possible to resume indexing from this point.

Commit returns the opstamp of the last document that made it in the commit.

pub fn delete_term(&mut self, term: Term) -> u64[src]

Delete all documents containing a given term.

Delete operation only affects documents that were added in previous commits, and documents that were added previously in the same commit.

Like adds, the deletion itself will be visible only after calling commit().

pub fn commit_opstamp(&self) -> u64[src]

Returns the opstamp of the last successful commit.

This is, for instance, the opstamp the index will rollback to if there is a failure like a power surge.

This is also the opstamp of the commit that is currently available for searchers.

pub fn add_document(&mut self, document: Document) -> u64[src]

Adds a document.

If the indexing pipeline is full, this call may block.

The opstamp is an increasing u64 that can be used by the client to align commits with its own document queue.

Currently it represents the number of documents that have been added since the creation of the index.

pub fn run(&mut self, user_operations: Vec<UserOperation>) -> u64[src]

Runs a group of document operations ensuring that the operations are assigned contigous u64 opstamps and that add operations of the same group are flushed into the same segment.

If the indexing pipeline is full, this call may block.

Each operation of the given user_operations will receive an in-order, contiguous u64 opstamp. The entire batch itself is also given an opstamp that is 1 greater than the last given operation. This batch_opstamp is the return value of run. An empty group of user_operations, an empty Vec<UserOperation>, still receives a valid opstamp even though no changes were actually made to the index.

Like adds and deletes (see IndexWriter.add_document and IndexWriter.delete_term), the changes made by calling run will be visible to readers only after calling commit().

Auto Trait Implementations

impl Send for IndexWriter

impl !Sync for IndexWriter

Blanket Implementations

impl<T> Fruit for T where
    T: Send + Downcast
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Erased for T[src]

impl<T> Downcast for T where
    T: Any
[src]