support for accessing the underlying index/store impls
now you can access the underlying index/store implementations using the Advanced() method. this is intedned for advanced usage only, and can lead to problems if misused. also, there is a new method NewUsing(...) which allows callers of the top-level API to choose which underlying k/v store they want to use.
This commit is contained in:
parent
38bdcbeb62
commit
68712cd142
15
index.go
15
index.go
|
@ -11,6 +11,8 @@ package bleve
|
|||
|
||||
import (
|
||||
"github.com/blevesearch/bleve/document"
|
||||
"github.com/blevesearch/bleve/index"
|
||||
"github.com/blevesearch/bleve/index/store"
|
||||
)
|
||||
|
||||
// A Batch groups together multiple Index and Delete
|
||||
|
@ -90,6 +92,8 @@ type Index interface {
|
|||
GetInternal(key []byte) ([]byte, error)
|
||||
SetInternal(key, val []byte) error
|
||||
DeleteInternal(key []byte) error
|
||||
|
||||
Advanced() (index.Index, store.KVStore, error)
|
||||
}
|
||||
|
||||
// A Classifier is an interface describing any object
|
||||
|
@ -105,6 +109,17 @@ func New(path string, mapping *IndexMapping) (Index, error) {
|
|||
return newIndex(path, mapping)
|
||||
}
|
||||
|
||||
// NewUsing creates index at the specified path,
|
||||
// which must not already exist.
|
||||
// The provided mapping will be used for all
|
||||
// Index/Search operations.
|
||||
// The specified kvstore implemenation will be used
|
||||
// and the provided kvconfig will be passed to its
|
||||
// constructor.
|
||||
func NewUsing(path string, mapping *IndexMapping, kvstore string, kvconfig map[string]interface{}) (Index, error) {
|
||||
return newIndexUsing(path, mapping, kvstore, kvconfig)
|
||||
}
|
||||
|
||||
// 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) {
|
||||
|
|
|
@ -14,6 +14,8 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/blevesearch/bleve/document"
|
||||
"github.com/blevesearch/bleve/index"
|
||||
"github.com/blevesearch/bleve/index/store"
|
||||
"github.com/blevesearch/bleve/search"
|
||||
)
|
||||
|
||||
|
@ -298,6 +300,22 @@ func (i *indexAliasImpl) DeleteInternal(key []byte) error {
|
|||
return i.indexes[0].DeleteInternal(key)
|
||||
}
|
||||
|
||||
func (i *indexAliasImpl) Advanced() (index.Index, store.KVStore, error) {
|
||||
i.mutex.RLock()
|
||||
defer i.mutex.RUnlock()
|
||||
|
||||
if !i.open {
|
||||
return nil, nil, ErrorIndexClosed
|
||||
}
|
||||
|
||||
err := i.isAliasToSingleIndex()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return i.indexes[0].Advanced()
|
||||
}
|
||||
|
||||
func (i *indexAliasImpl) Add(indexes ...Index) {
|
||||
i.mutex.Lock()
|
||||
defer i.mutex.Unlock()
|
||||
|
|
|
@ -7,6 +7,8 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/blevesearch/bleve/document"
|
||||
"github.com/blevesearch/bleve/index"
|
||||
"github.com/blevesearch/bleve/index/store"
|
||||
"github.com/blevesearch/bleve/search"
|
||||
)
|
||||
|
||||
|
@ -725,3 +727,7 @@ func (i *stubIndex) SetInternal(key, val []byte) error {
|
|||
func (i *stubIndex) DeleteInternal(key []byte) error {
|
||||
return i.err
|
||||
}
|
||||
|
||||
func (i *stubIndex) Advanced() (index.Index, store.KVStore, error) {
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ func newMemIndex(mapping *IndexMapping) (*indexImpl, error) {
|
|||
return &rv, nil
|
||||
}
|
||||
|
||||
func newIndex(path string, mapping *IndexMapping) (*indexImpl, error) {
|
||||
func newIndexUsing(path string, mapping *IndexMapping, kvstore string, kvconfig map[string]interface{}) (*indexImpl, error) {
|
||||
// first validate the mapping
|
||||
err := mapping.validate()
|
||||
if err != nil {
|
||||
|
@ -104,7 +104,7 @@ func newIndex(path string, mapping *IndexMapping) (*indexImpl, error) {
|
|||
rv := indexImpl{
|
||||
path: path,
|
||||
m: mapping,
|
||||
meta: newIndexMeta(Config.DefaultKVStore),
|
||||
meta: newIndexMeta(kvstore),
|
||||
stats: &IndexStat{},
|
||||
}
|
||||
storeConstructor := registry.KVStoreConstructorByName(rv.meta.Storage)
|
||||
|
@ -116,14 +116,13 @@ func newIndex(path string, mapping *IndexMapping) (*indexImpl, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
storeConfig := map[string]interface{}{
|
||||
"path": indexStorePath(path),
|
||||
"create_if_missing": true,
|
||||
"error_if_exists": true,
|
||||
if kvconfig == nil {
|
||||
kvconfig = map[string]interface{}{}
|
||||
}
|
||||
kvconfig["path"] = indexStorePath(path)
|
||||
|
||||
// now open the store
|
||||
rv.s, err = storeConstructor(storeConfig)
|
||||
rv.s, err = storeConstructor(kvconfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -153,6 +152,14 @@ func newIndex(path string, mapping *IndexMapping) (*indexImpl, error) {
|
|||
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) {
|
||||
|
||||
rv := indexImpl{
|
||||
|
@ -224,6 +231,12 @@ func openIndex(path string) (*indexImpl, error) {
|
|||
return &rv, nil
|
||||
}
|
||||
|
||||
// Advanced returns implementation internals
|
||||
// necessary ONLY for advanced usage.
|
||||
func (i *indexImpl) Advanced() (index.Index, store.KVStore, error) {
|
||||
return i.i, i.s, nil
|
||||
}
|
||||
|
||||
// Mapping returns the IndexMapping in use by this
|
||||
// Index.
|
||||
func (i *indexImpl) Mapping() *IndexMapping {
|
||||
|
|
Loading…
Reference in New Issue