// OpenIndex open a existing index for read/write operations. func (neo *NeoSearch) OpenIndex(name string) (*index.Index, error) { var ( ok bool cacheIndex interface{} indx *index.Index err error ) cacheIndex, ok = neo.indices.Get(name) if ok && cacheIndex != nil { indx, ok = cacheIndex.(*index.Index) if !ok { panic("NeoSearch has inconsistent data stored in cache") } return indx, nil } ok, err = neo.IndexExists(name) if err == nil && !ok { return nil, fmt.Errorf("Index '%s' not found in directory '%s'.", name, neo.config.DataDir) } else if err != nil { return nil, err } indx, err = index.New( name, index.Config{ DataDir: neo.config.DataDir, Debug: neo.config.Debug, CacheSize: neo.config.KVCacheSize, EnableCache: neo.config.EnableCache, }, false, ) if err != nil { return nil, err } neo.indices.Add(name, indx) cachedIndices.Set(int64(neo.indices.Len())) return indx, nil }
// CreateIndex creates and setup a new index func (neo *NeoSearch) CreateIndex(name string) (*index.Index, error) { indx, err := index.New( name, index.Config{ DataDir: neo.config.DataDir, Debug: neo.config.Debug, CacheSize: neo.config.KVCacheSize, EnableCache: neo.config.EnableCache, }, true, ) if err != nil { return nil, err } neo.indices.Add(name, indx) cachedIndices.Set(int64(neo.indices.Len())) return indx, nil }