0
0
Fork 0

Merge branch 'codesimplification' of https://github.com/Shugyousha/bleve into Shugyousha-codesimplification

This commit is contained in:
Marty Schoch 2015-09-29 13:02:56 -04:00
commit da40935e22
3 changed files with 36 additions and 41 deletions

View File

@ -33,23 +33,23 @@ const (
type Error int
func (e Error) Error() string {
return errorMessages[int(e)]
return errorMessages[e]
}
var errorMessages = map[int]string{
int(ErrorIndexPathExists): "cannot create new index, path already exists",
int(ErrorIndexPathDoesNotExist): "cannot open index, path does not exist",
int(ErrorIndexMetaMissing): "cannot open index, metadata missing",
int(ErrorIndexMetaCorrupt): "cannot open index, metadata corrupt",
int(ErrorDisjunctionFewerThanMinClauses): "disjunction query has fewer than the minimum number of clauses to satisfy",
int(ErrorBooleanQueryNeedsMustOrShouldOrNotMust): "boolean query must contain at least one must or should or not must clause",
int(ErrorNumericQueryNoBounds): "numeric range query must specify min or max",
int(ErrorPhraseQueryNoTerms): "phrase query must contain at least one term",
int(ErrorUnknownQueryType): "unknown query type",
int(ErrorUnknownStorageType): "unknown storage type",
int(ErrorIndexClosed): "index is closed",
int(ErrorAliasMulti): "cannot perform single index operation on multiple index alias",
int(ErrorAliasEmpty): "cannot perform operation on empty alias",
int(ErrorUnknownIndexType): "unknown index type",
int(ErrorEmptyID): "document ID cannot be empty",
var errorMessages = map[Error]string{
ErrorIndexPathExists: "cannot create new index, path already exists",
ErrorIndexPathDoesNotExist: "cannot open index, path does not exist",
ErrorIndexMetaMissing: "cannot open index, metadata missing",
ErrorIndexMetaCorrupt: "cannot open index, metadata corrupt",
ErrorDisjunctionFewerThanMinClauses: "disjunction query has fewer than the minimum number of clauses to satisfy",
ErrorBooleanQueryNeedsMustOrShouldOrNotMust: "boolean query must contain at least one must or should or not must clause",
ErrorNumericQueryNoBounds: "numeric range query must specify min or max",
ErrorPhraseQueryNoTerms: "phrase query must contain at least one term",
ErrorUnknownQueryType: "unknown query type",
ErrorUnknownStorageType: "unknown storage type",
ErrorIndexClosed: "index is closed",
ErrorAliasMulti: "cannot perform single index operation on multiple index alias",
ErrorAliasEmpty: "cannot perform operation on empty alias",
ErrorUnknownIndexType: "unknown index type",
ErrorEmptyID: "document ID cannot be empty",
}

View File

@ -282,7 +282,7 @@ func (i *indexImpl) Mapping() *IndexMapping {
// Index the object with the specified identifier.
// The IndexMapping for this index will determine
// how the object is indexed.
func (i *indexImpl) Index(id string, data interface{}) error {
func (i *indexImpl) Index(id string, data interface{}) (err error) {
if id == "" {
return ErrorEmptyID
}
@ -295,20 +295,17 @@ func (i *indexImpl) Index(id string, data interface{}) error {
}
doc := document.NewDocument(id)
err := i.m.mapDocument(doc, data)
err = i.m.mapDocument(doc, data)
if err != nil {
return err
return
}
err = i.i.Update(doc)
if err != nil {
return err
}
return nil
return
}
// Delete entries for the specified identifier from
// the index.
func (i *indexImpl) Delete(id string) error {
func (i *indexImpl) Delete(id string) (err error) {
if id == "" {
return ErrorEmptyID
}
@ -320,11 +317,8 @@ func (i *indexImpl) Delete(id string) error {
return ErrorIndexClosed
}
err := i.i.Delete(id)
if err != nil {
return err
}
return nil
err = i.i.Delete(id)
return
}
// Batch executes multiple Index and Delete

View File

@ -50,19 +50,20 @@ func (dm *DocumentMatch) AddFieldValue(name string, value interface{}) {
dm.Fields = make(map[string]interface{})
}
existingVal, ok := dm.Fields[name]
if ok {
valSlice, ok := existingVal.([]interface{})
if ok {
// already a slice, append to it
valSlice = append(valSlice, value)
} else {
// create a slice
valSlice = []interface{}{existingVal, value}
}
dm.Fields[name] = valSlice
} else {
if !ok {
dm.Fields[name] = value
return
}
valSlice, ok := existingVal.([]interface{})
if ok {
// already a slice, append to it
valSlice = append(valSlice, value)
} else {
// create a slice
valSlice = []interface{}{existingVal, value}
}
dm.Fields[name] = valSlice
}
type DocumentMatchCollection []*DocumentMatch