0
0
Fork 0
This commit is contained in:
luoji 2018-03-23 22:53:06 +00:00 committed by GitHub
commit da968949e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 3 deletions

View File

@ -246,7 +246,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.
@ -254,5 +254,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)
}

View File

@ -131,7 +131,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,
@ -178,6 +178,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 {