I need to serialize/deserialize bleve indexes to/from []byte. This PR is the best way I can see how to do so based on my reading of your code. If there is a better way, please tell me about it and ignore this PR.
The calling code that uses the proposed code change in this PR looks like this.
import (
btreap "github.com/blevesearch/bleve/index/store/gtreap"
"github.com/blevesearch/blevex/preload"
"github.com/blevesearch/bleve"
)
// ExportBleveMem serializes `index` to a byte slice.
func ExportBleveMem(index bleve.Index) ([]byte, error) {
var b bytes.Buffer
w := &b
i, _, err := index.Advanced()
if err != nil {
return nil, err
}
if err = preload.ExportBleve(i, w); err != nil {
return nil, err
}
return b.Bytes(), nil
}
// ImportBleveMem deserializes `data` to a byte bleve.Index.
func ImportBleveMem(data []byte) (bleve.Index, error) {
return bleve.NewUsing(
"",
bleve.NewIndexMapping(),
bleve.Config.DefaultIndexType,
preload.Name,
map[string]interface{}{
"kvStoreName_actual": btreap.Name,
"preloadmem": data,
})
}
I need to serialize/deserialize bleve indexes to/from []byte. This PR is the best way I can see how to do so based on my reading of your code. If there is a better way, please tell me about it and ignore this PR.
The calling code that uses the proposed code change in this PR looks like this.
The code that uses this is in https://github.com/PaperCutSoftware/pdfsearch