![]() | BulkCopy Class |
Namespace: SphinxConnector.SphinxQL
The BulkCopy type exposes the following members.
Name | Description | |
---|---|---|
![]() | 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.
|
Name | Description | |
---|---|---|
![]() | CopyAsync |
Copies the data provided by the dataReader to the index.
|
![]() | Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) |
![]() | GetHashCode | Serves as the default hash function. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
//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 <see href="http://www.nuget.org/packages/FastMember" /> //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(); } }