ACOR Documentation

Batch Operations

ACOR supports batch operations for better performance when working with multiple keywords.

Overview

Batch operations reduce network round-trips by grouping multiple operations together.

Adding Multiple Keywords

result, err := ac.AddMany([]string{"he", "her", "him", "his"}, &acor.BatchOptions{
    Mode: acor.BatchModeTransactional,
})
if err != nil {
    panic(err)
}

fmt.Printf("Added: %d, Failed: %d\n", result.Success, result.Failed)

Batch Modes

Transactional

Rolls back all changes if any error occurs:

result, err := ac.AddMany(keywords, &acor.BatchOptions{
    Mode: acor.BatchModeTransactional,
})

BestEffort

Continues on errors and returns partial results:

result, err := ac.AddMany(keywords, &acor.BatchOptions{
    Mode: acor.BatchModeBestEffort,
})

Removing Multiple Keywords

result, err := ac.RemoveMany([]string{"he", "her"})
if err != nil {
    panic(err)
}

Finding Matches in Multiple Texts

texts := []string{"he is him", "this is hers", "hello world"}
results, err := ac.FindMany(texts)
if err != nil {
    panic(err)
}

for text, matches := range results {
    fmt.Printf("Text %q: %v\n", text, matches)
}

Batch Result Structure

type BatchResult struct {
    Success int          // Number of successful operations
    Failed  int          // Number of failed operations
    Errors  []BatchError // Individual errors (BestEffort mode only)
}

Performance Tips

  1. Use batch sizes between 100-1000 keywords
  2. Use BatchModeTransactional when data consistency is critical
  3. Use BatchModeBestEffort when partial success is acceptable

Next Steps