open use mapping, reduce memory usage by maping.UnmarshalJSON(specially load dict)
Signed-off-by: jerrylou <gunsluo@gmail.com>
This commit is contained in:
parent
6eea5b78da
commit
fceee6be89
13
index.go
13
index.go
|
@ -245,7 +245,7 @@ func NewUsing(path string, mapping mapping.IndexMapping, indexType string, kvsto
|
|||
// 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 openIndexUsing(path, nil)
|
||||
return openIndexUsing(path, nil, nil)
|
||||
}
|
||||
|
||||
// OpenUsing opens index at the specified path, must exist.
|
||||
|
@ -253,5 +253,14 @@ func Open(path string) (Index, error) {
|
|||
// 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)
|
||||
return openIndexUsing(path, nil, runtimeConfig)
|
||||
}
|
||||
|
||||
// OpenUsingMapping 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.
|
||||
// The provided mapping will be used for all, when alias use multiple the same index mapping.
|
||||
func OpenUsingMapping(path string, mapping mapping.IndexMapping) (Index, error) {
|
||||
return openIndexUsing(path, mapping, nil)
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ func newIndexUsing(path string, mapping mapping.IndexMapping, indexType string,
|
|||
return &rv, nil
|
||||
}
|
||||
|
||||
func openIndexUsing(path string, runtimeConfig map[string]interface{}) (rv *indexImpl, err error) {
|
||||
func openIndexUsing(path string, indexMapping mapping.IndexMapping, runtimeConfig map[string]interface{}) (rv *indexImpl, err error) {
|
||||
rv = &indexImpl{
|
||||
path: path,
|
||||
name: path,
|
||||
|
@ -173,6 +173,23 @@ func openIndexUsing(path string, runtimeConfig map[string]interface{}) (rv *inde
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// use mapping
|
||||
if indexMapping != nil {
|
||||
err = indexMapping.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// mark the index as open
|
||||
rv.mutex.Lock()
|
||||
defer rv.mutex.Unlock()
|
||||
rv.open = true
|
||||
|
||||
rv.m = indexMapping
|
||||
indexStats.Register(rv)
|
||||
return rv, err
|
||||
}
|
||||
|
||||
// now load the mapping
|
||||
indexReader, err := rv.i.Reader()
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue