made more of index mapping private
This commit is contained in:
parent
2ea1f526e7
commit
8c6427959c
@ -62,9 +62,10 @@ func buildIndexMapping() *bleve.IndexMapping {
|
|||||||
|
|
||||||
indexMapping := bleve.NewIndexMapping().
|
indexMapping := bleve.NewIndexMapping().
|
||||||
AddDocumentMapping("beer", beerMapping).
|
AddDocumentMapping("beer", beerMapping).
|
||||||
AddDocumentMapping("brewery", breweryMapping).
|
AddDocumentMapping("brewery", breweryMapping)
|
||||||
SetTypeField("type").
|
|
||||||
SetDefaultAnalyzer(textFieldAnalyzer)
|
indexMapping.TypeField = "type"
|
||||||
|
indexMapping.DefaultAnalyzer = textFieldAnalyzer
|
||||||
|
|
||||||
return indexMapping
|
return indexMapping
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ func newMemIndex(mapping *IndexMapping) (*indexImpl, error) {
|
|||||||
|
|
||||||
func newIndex(path string, mapping *IndexMapping) (*indexImpl, error) {
|
func newIndex(path string, mapping *IndexMapping) (*indexImpl, error) {
|
||||||
// first validate the mapping
|
// first validate the mapping
|
||||||
err := mapping.Validate()
|
err := mapping.validate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -198,7 +198,7 @@ func openIndex(path string) (*indexImpl, error) {
|
|||||||
rv.open = true
|
rv.open = true
|
||||||
|
|
||||||
// validate the mapping
|
// validate the mapping
|
||||||
err = im.Validate()
|
err = im.validate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// note even if the mapping is invalid
|
// note even if the mapping is invalid
|
||||||
// we still return an open usable index
|
// we still return an open usable index
|
||||||
@ -222,7 +222,7 @@ func (i *indexImpl) Index(id string, data interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
doc := document.NewDocument(id)
|
doc := document.NewDocument(id)
|
||||||
err := i.m.MapDocument(doc, data)
|
err := i.m.mapDocument(doc, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -262,7 +262,7 @@ func (i *indexImpl) Batch(b Batch) error {
|
|||||||
ib.Delete(bk)
|
ib.Delete(bk)
|
||||||
} else {
|
} else {
|
||||||
doc := document.NewDocument(bk)
|
doc := document.NewDocument(bk)
|
||||||
err := i.m.MapDocument(doc, bd)
|
err := i.m.mapDocument(doc, bd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ package bleve
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
@ -44,10 +43,6 @@ type IndexMapping struct {
|
|||||||
cache *registry.Cache `json:"_"`
|
cache *registry.Cache `json:"_"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (im *IndexMapping) GoString() string {
|
|
||||||
return fmt.Sprintf("&bleve.IndexMapping{TypeMapping:%#v, TypeField:%s, DefaultType:%s}", im.TypeMapping, im.TypeField, im.DefaultType)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewIndexMapping() *IndexMapping {
|
func NewIndexMapping() *IndexMapping {
|
||||||
return &IndexMapping{
|
return &IndexMapping{
|
||||||
TypeMapping: make(map[string]*DocumentMapping),
|
TypeMapping: make(map[string]*DocumentMapping),
|
||||||
@ -66,7 +61,7 @@ func NewIndexMapping() *IndexMapping {
|
|||||||
// explicitly named and default analyzers can be built
|
// explicitly named and default analyzers can be built
|
||||||
// explicitly named and default date parsers can be built
|
// explicitly named and default date parsers can be built
|
||||||
// field type names are valid
|
// field type names are valid
|
||||||
func (im *IndexMapping) Validate() error {
|
func (im *IndexMapping) validate() error {
|
||||||
_, err := im.cache.AnalyzerNamed(im.DefaultAnalyzer)
|
_, err := im.cache.AnalyzerNamed(im.DefaultAnalyzer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -93,36 +88,6 @@ func (im *IndexMapping) AddDocumentMapping(doctype string, dm *DocumentMapping)
|
|||||||
return im
|
return im
|
||||||
}
|
}
|
||||||
|
|
||||||
func (im *IndexMapping) SetDefaultMapping(defaultMapping *DocumentMapping) *IndexMapping {
|
|
||||||
im.DefaultMapping = defaultMapping
|
|
||||||
return im
|
|
||||||
}
|
|
||||||
|
|
||||||
func (im *IndexMapping) SetTypeField(typeField string) *IndexMapping {
|
|
||||||
im.TypeField = typeField
|
|
||||||
return im
|
|
||||||
}
|
|
||||||
|
|
||||||
func (im *IndexMapping) SetDefaultType(defaultType string) *IndexMapping {
|
|
||||||
im.DefaultType = defaultType
|
|
||||||
return im
|
|
||||||
}
|
|
||||||
|
|
||||||
func (im *IndexMapping) SetDefaultAnalyzer(analyzer string) *IndexMapping {
|
|
||||||
im.DefaultAnalyzer = analyzer
|
|
||||||
return im
|
|
||||||
}
|
|
||||||
|
|
||||||
func (im *IndexMapping) SetDefaultField(field string) *IndexMapping {
|
|
||||||
im.DefaultField = field
|
|
||||||
return im
|
|
||||||
}
|
|
||||||
|
|
||||||
func (im *IndexMapping) SetByteArrayConverter(byteArrayConverter string) *IndexMapping {
|
|
||||||
im.ByteArrayConverter = byteArrayConverter
|
|
||||||
return im
|
|
||||||
}
|
|
||||||
|
|
||||||
func (im *IndexMapping) mappingForType(docType string) *DocumentMapping {
|
func (im *IndexMapping) mappingForType(docType string) *DocumentMapping {
|
||||||
docMapping := im.TypeMapping[docType]
|
docMapping := im.TypeMapping[docType]
|
||||||
if docMapping == nil {
|
if docMapping == nil {
|
||||||
@ -207,7 +172,7 @@ func (im *IndexMapping) determineType(data interface{}) string {
|
|||||||
return im.DefaultType
|
return im.DefaultType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (im *IndexMapping) MapDocument(doc *document.Document, data interface{}) error {
|
func (im *IndexMapping) mapDocument(doc *document.Document, data interface{}) error {
|
||||||
// see if the top level object is a byte array, and possibly run through conveter
|
// see if the top level object is a byte array, and possibly run through conveter
|
||||||
byteArrayData, ok := data.([]byte)
|
byteArrayData, ok := data.([]byte)
|
||||||
if ok {
|
if ok {
|
||||||
|
Loading…
Reference in New Issue
Block a user