BulkCopy Class

A convenience class to copy data from an IDataReader to an index.

Definition

Namespace: SphinxConnector.SphinxQL
Assembly: SphinxConnector (in SphinxConnector.dll) Version: 6.1.0
C#
public class BulkCopy
Inheritance
Object    BulkCopy

Example

C#
//DataTable implements IDataReader and can be used directly.
DataTable data = GetData();

//If you have an enumarable of objects you want to bulk copy, you can use 
//to create an implementation of IDataReader on the fly:

IEnumerable<Product> products = GetProducts();
IDataReader productsDataReader = FastMember.ObjectReader.Create(products);

using (var connection = new SphinxQLConnection())
{
    await connection.OpenAsync();
    using (var tx = await connection.BeginTransactionAsync())
    {
        var bulkCopy = new BulkCopy(connection, "rt");
        {
            BatchSize = 1000, //Default batch size is a very conservative 16, do some tests and adjust to what gives the best performance for your workload. You may also need to adjust max_packet_size in your searchd config.
            Progress = new Progress<int>(c => Debug.WriteLine($"{c} documents written"))
        };
        int count = await bulkLoader.CopyAsync(data);
        //or
        int count = await bulkLoader.CopyAsync(productsDataReader);
        await tx.CommitAsync();
    }
}

Constructors

BulkCopy Initializes a new instance of the BulkCopy class.

Properties

BatchSize Gets or sets the batch size to use when inserting data into the index. Default is 16.
CopyMethod Gets or sets the BulkCopyMethod. Default is BulkCopyMethod.Replace
IndexName Gets or sets the name if the index to copy data to.
Progress Get or sets an (optional) implementation of IProgressT to report progress to.
ProgressNotificationAfter By default progress notification happens for each processed batch, set this to a value greater 0 to adjust when a notification should occur.

Methods

CopyAsync Copies the data provided by the dataReader to the index.
EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
GetHashCodeServes as the default hash function.
(Inherited from Object)
GetTypeGets the Type of the current instance.
(Inherited from Object)
ToStringReturns a string that represents the current object.
(Inherited from Object)

See Also