adding Merge method to Batch
This commit is contained in:
parent
4b742505aa
commit
8993adc0e2
12
index.go
12
index.go
|
@ -102,6 +102,18 @@ func (b *Batch) Reset() {
|
||||||
b.internal.Reset()
|
b.internal.Reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Merge performs the merge of the internal Index.Batch
|
||||||
|
// of the given batch to the self.
|
||||||
|
func (b *Batch) Merge(other *Batch) {
|
||||||
|
for k, v := range other.internal.IndexOps {
|
||||||
|
b.internal.IndexOps[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range other.internal.InternalOps {
|
||||||
|
b.internal.InternalOps[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// An Index implements all the indexing and searching
|
// An Index implements all the indexing and searching
|
||||||
// capabilities of bleve. An Index can be created
|
// capabilities of bleve. An Index can be created
|
||||||
// using the New() and Open() methods.
|
// using the New() and Open() methods.
|
||||||
|
|
|
@ -1815,3 +1815,72 @@ func TestIndexAdvancedCountMatchSearch(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMatchMerge(t *testing.T) {
|
||||||
|
defer func() {
|
||||||
|
err := os.RemoveAll("testidx")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
index, err := New("testidx", NewIndexMapping())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
doca := map[string]interface{}{
|
||||||
|
"name": "scorcher",
|
||||||
|
"desc": "cbft",
|
||||||
|
}
|
||||||
|
batcha := index.NewBatch()
|
||||||
|
err = batcha.Index("a", doca)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
batcha.SetInternal([]byte("batch_a"), []byte("batch_a_value"))
|
||||||
|
|
||||||
|
docb := map[string]interface{}{
|
||||||
|
"name": "updc down",
|
||||||
|
"desc": "bleve",
|
||||||
|
}
|
||||||
|
|
||||||
|
batchb := index.NewBatch()
|
||||||
|
err = batchb.Index("b", docb)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
batchb.SetInternal([]byte("batch_b"), []byte("batch_b_value"))
|
||||||
|
|
||||||
|
batcha.Merge(batchb)
|
||||||
|
|
||||||
|
err = index.Batch(batcha)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
val, err := index.GetInternal([]byte("batch_b"))
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if string(val) != "batch_b_value" {
|
||||||
|
t.Errorf("expected 'batch_b_value', got '%s'", val)
|
||||||
|
}
|
||||||
|
|
||||||
|
val, err = index.GetInternal([]byte("batch_a"))
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
if string(val) != "batch_a_value" {
|
||||||
|
t.Errorf("expected 'batch_a_value', got '%s'", val)
|
||||||
|
}
|
||||||
|
|
||||||
|
val, err = index.GetInternal([]byte("status"))
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
if val != nil {
|
||||||
|
t.Errorf("expected nil, got '%s'", val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user