Merge pull request #594 from mschoch/add-blevetype
add support for BleveType() alternative for type detection
This commit is contained in:
commit
b26b845bd6
11
index.go
11
index.go
@ -110,12 +110,15 @@ func (b *Batch) Reset() {
|
|||||||
// them.
|
// them.
|
||||||
//
|
//
|
||||||
// The DocumentMapping used to index a value is deduced by the following rules:
|
// The DocumentMapping used to index a value is deduced by the following rules:
|
||||||
// 1) If value implements Classifier interface, resolve the mapping from Type().
|
// 1) If value implements mapping.bleveClassifier interface, resolve the mapping
|
||||||
// 2) If value has a string field or value at IndexMapping.TypeField.
|
// from BleveType().
|
||||||
|
// 2) If value implements mapping.Classifier interface, resolve the mapping
|
||||||
|
// from Type().
|
||||||
|
// 3) If value has a string field or value at IndexMapping.TypeField.
|
||||||
// (defaulting to "_type"), use it to resolve the mapping. Fields addressing
|
// (defaulting to "_type"), use it to resolve the mapping. Fields addressing
|
||||||
// is described below.
|
// is described below.
|
||||||
// 3) If IndexMapping.DefaultType is registered, return it.
|
// 4) If IndexMapping.DefaultType is registered, return it.
|
||||||
// 4) Return IndexMapping.DefaultMapping.
|
// 5) Return IndexMapping.DefaultMapping.
|
||||||
//
|
//
|
||||||
// Each field or nested field of the value is identified by a string path, then
|
// Each field or nested field of the value is identified by a string path, then
|
||||||
// mapped to one or several FieldMappings which extract the result for analysis.
|
// mapped to one or several FieldMappings which extract the result for analysis.
|
||||||
|
@ -289,7 +289,12 @@ func (im *IndexMappingImpl) UnmarshalJSON(data []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (im *IndexMappingImpl) determineType(data interface{}) string {
|
func (im *IndexMappingImpl) determineType(data interface{}) string {
|
||||||
// first see if the object implements Classifier
|
// first see if the object implements bleveClassifier
|
||||||
|
bleveClassifier, ok := data.(bleveClassifier)
|
||||||
|
if ok {
|
||||||
|
return bleveClassifier.BleveType()
|
||||||
|
}
|
||||||
|
// next see if the object implements Classifier
|
||||||
classifier, ok := data.(Classifier)
|
classifier, ok := data.(Classifier)
|
||||||
if ok {
|
if ok {
|
||||||
return classifier.Type()
|
return classifier.Type()
|
||||||
|
@ -22,12 +22,21 @@ import (
|
|||||||
"github.com/blevesearch/bleve/document"
|
"github.com/blevesearch/bleve/document"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Classifier is an interface describing any object
|
// A Classifier is an interface describing any object which knows how to
|
||||||
// which knows how to identify its own type.
|
// identify its own type. Alternatively, if a struct already has a Type
|
||||||
|
// field or method in conflict, one can use BleveType instead.
|
||||||
type Classifier interface {
|
type Classifier interface {
|
||||||
Type() string
|
Type() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A bleveClassifier is an interface describing any object which knows how
|
||||||
|
// to identify its own type. This is introduced as an alternative to the
|
||||||
|
// Classifier interface which often has naming conflicts with existing
|
||||||
|
// structures.
|
||||||
|
type bleveClassifier interface {
|
||||||
|
BleveType() string
|
||||||
|
}
|
||||||
|
|
||||||
var logger = log.New(ioutil.Discard, "bleve mapping ", log.LstdFlags)
|
var logger = log.New(ioutil.Discard, "bleve mapping ", log.LstdFlags)
|
||||||
|
|
||||||
// SetLog sets the logger used for logging
|
// SetLog sets the logger used for logging
|
||||||
|
Loading…
Reference in New Issue
Block a user