NewUsing persists the provided config to index meta
new method OpenUsing allows user to override values in the persisted config example would be opening the index, but using a different buffer size for leveldb (not actually supported yet, but that is the idea) closes #138
This commit is contained in:
parent
d442713de6
commit
1368d7b3b4
12
index.go
12
index.go
|
@ -106,7 +106,7 @@ type Classifier interface {
|
|||
// The provided mapping will be used for all
|
||||
// Index/Search operations.
|
||||
func New(path string, mapping *IndexMapping) (Index, error) {
|
||||
return newIndex(path, mapping)
|
||||
return newIndexUsing(path, mapping, Config.DefaultKVStore, nil)
|
||||
}
|
||||
|
||||
// NewUsing creates index at the specified path,
|
||||
|
@ -123,5 +123,13 @@ func NewUsing(path string, mapping *IndexMapping, kvstore string, kvconfig map[s
|
|||
// Open index at the specified path, must exist.
|
||||
// The mapping used when it was created will be used for all Index/Search operations.
|
||||
func Open(path string) (Index, error) {
|
||||
return openIndex(path)
|
||||
return openIndexUsing(path, nil)
|
||||
}
|
||||
|
||||
// OpenUsing opens index at the specified path, must exist.
|
||||
// The mapping used when it was created will be used for all Index/Search operations.
|
||||
// The provided runtimeConfig can override settings
|
||||
// persisted when the kvstore was created.
|
||||
func OpenUsing(path string, runtimeConfig map[string]interface{}) (Index, error) {
|
||||
return openIndexUsing(path, runtimeConfig)
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ func newMemIndex(mapping *IndexMapping) (*indexImpl, error) {
|
|||
rv := indexImpl{
|
||||
path: "",
|
||||
m: mapping,
|
||||
meta: newIndexMeta("mem"),
|
||||
meta: newIndexMeta("mem", nil),
|
||||
stats: &IndexStat{},
|
||||
}
|
||||
|
||||
|
@ -101,10 +101,14 @@ func newIndexUsing(path string, mapping *IndexMapping, kvstore string, kvconfig
|
|||
return newMemIndex(mapping)
|
||||
}
|
||||
|
||||
if kvconfig == nil {
|
||||
kvconfig = map[string]interface{}{}
|
||||
}
|
||||
|
||||
rv := indexImpl{
|
||||
path: path,
|
||||
m: mapping,
|
||||
meta: newIndexMeta(kvstore),
|
||||
meta: newIndexMeta(kvstore, kvconfig),
|
||||
stats: &IndexStat{},
|
||||
}
|
||||
storeConstructor := registry.KVStoreConstructorByName(rv.meta.Storage)
|
||||
|
@ -116,9 +120,8 @@ func newIndexUsing(path string, mapping *IndexMapping, kvstore string, kvconfig
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if kvconfig == nil {
|
||||
kvconfig = map[string]interface{}{}
|
||||
}
|
||||
kvconfig["create_if_missing"] = true
|
||||
kvconfig["error_if_exists"] = true
|
||||
kvconfig["path"] = indexStorePath(path)
|
||||
|
||||
// now open the store
|
||||
|
@ -152,15 +155,7 @@ func newIndexUsing(path string, mapping *IndexMapping, kvstore string, kvconfig
|
|||
return &rv, nil
|
||||
}
|
||||
|
||||
func newIndex(path string, mapping *IndexMapping) (*indexImpl, error) {
|
||||
defaultKVConfig := map[string]interface{}{
|
||||
"create_if_missing": true,
|
||||
"error_if_exists": true,
|
||||
}
|
||||
return newIndexUsing(path, mapping, Config.DefaultKVStore, defaultKVConfig)
|
||||
}
|
||||
|
||||
func openIndex(path string) (*indexImpl, error) {
|
||||
func openIndexUsing(path string, runtimeConfig map[string]interface{}) (*indexImpl, error) {
|
||||
|
||||
rv := indexImpl{
|
||||
path: path,
|
||||
|
@ -177,10 +172,16 @@ func openIndex(path string) (*indexImpl, error) {
|
|||
return nil, ErrorUnknownStorageType
|
||||
}
|
||||
|
||||
storeConfig := map[string]interface{}{
|
||||
"path": indexStorePath(path),
|
||||
"create_if_missing": false,
|
||||
"error_if_exists": false,
|
||||
storeConfig := rv.meta.Config
|
||||
if storeConfig == nil {
|
||||
storeConfig = map[string]interface{}{}
|
||||
}
|
||||
|
||||
storeConfig["path"] = indexStorePath(path)
|
||||
storeConfig["create_if_missing"] = false
|
||||
storeConfig["error_if_exists"] = false
|
||||
for rck, rcv := range runtimeConfig {
|
||||
storeConfig[rck] = rcv
|
||||
}
|
||||
|
||||
// now open the store
|
||||
|
|
|
@ -18,11 +18,15 @@ import (
|
|||
const metaFilename = "index_meta.json"
|
||||
|
||||
type indexMeta struct {
|
||||
Storage string `json:"storage"`
|
||||
Storage string `json:"storage"`
|
||||
Config map[string]interface{} `json:"config,omitempty"`
|
||||
}
|
||||
|
||||
func newIndexMeta(storage string) *indexMeta {
|
||||
return &indexMeta{Storage: storage}
|
||||
func newIndexMeta(storage string, config map[string]interface{}) *indexMeta {
|
||||
return &indexMeta{
|
||||
Storage: storage,
|
||||
Config: config,
|
||||
}
|
||||
}
|
||||
|
||||
func openIndexMeta(path string) (*indexMeta, error) {
|
||||
|
|
Loading…
Reference in New Issue