Merge branch 'Shugyousha-codesimplification'
This commit is contained in:
commit
21473509b2
34
error.go
34
error.go
|
@ -33,23 +33,23 @@ const (
|
||||||
type Error int
|
type Error int
|
||||||
|
|
||||||
func (e Error) Error() string {
|
func (e Error) Error() string {
|
||||||
return errorMessages[int(e)]
|
return errorMessages[e]
|
||||||
}
|
}
|
||||||
|
|
||||||
var errorMessages = map[int]string{
|
var errorMessages = map[Error]string{
|
||||||
int(ErrorIndexPathExists): "cannot create new index, path already exists",
|
ErrorIndexPathExists: "cannot create new index, path already exists",
|
||||||
int(ErrorIndexPathDoesNotExist): "cannot open index, path does not exist",
|
ErrorIndexPathDoesNotExist: "cannot open index, path does not exist",
|
||||||
int(ErrorIndexMetaMissing): "cannot open index, metadata missing",
|
ErrorIndexMetaMissing: "cannot open index, metadata missing",
|
||||||
int(ErrorIndexMetaCorrupt): "cannot open index, metadata corrupt",
|
ErrorIndexMetaCorrupt: "cannot open index, metadata corrupt",
|
||||||
int(ErrorDisjunctionFewerThanMinClauses): "disjunction query has fewer than the minimum number of clauses to satisfy",
|
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",
|
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",
|
ErrorNumericQueryNoBounds: "numeric range query must specify min or max",
|
||||||
int(ErrorPhraseQueryNoTerms): "phrase query must contain at least one term",
|
ErrorPhraseQueryNoTerms: "phrase query must contain at least one term",
|
||||||
int(ErrorUnknownQueryType): "unknown query type",
|
ErrorUnknownQueryType: "unknown query type",
|
||||||
int(ErrorUnknownStorageType): "unknown storage type",
|
ErrorUnknownStorageType: "unknown storage type",
|
||||||
int(ErrorIndexClosed): "index is closed",
|
ErrorIndexClosed: "index is closed",
|
||||||
int(ErrorAliasMulti): "cannot perform single index operation on multiple index alias",
|
ErrorAliasMulti: "cannot perform single index operation on multiple index alias",
|
||||||
int(ErrorAliasEmpty): "cannot perform operation on empty alias",
|
ErrorAliasEmpty: "cannot perform operation on empty alias",
|
||||||
int(ErrorUnknownIndexType): "unknown index type",
|
ErrorUnknownIndexType: "unknown index type",
|
||||||
int(ErrorEmptyID): "document ID cannot be empty",
|
ErrorEmptyID: "document ID cannot be empty",
|
||||||
}
|
}
|
||||||
|
|
|
@ -282,7 +282,7 @@ func (i *indexImpl) Mapping() *IndexMapping {
|
||||||
// Index the object with the specified identifier.
|
// Index the object with the specified identifier.
|
||||||
// The IndexMapping for this index will determine
|
// The IndexMapping for this index will determine
|
||||||
// how the object is indexed.
|
// 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 == "" {
|
if id == "" {
|
||||||
return ErrorEmptyID
|
return ErrorEmptyID
|
||||||
}
|
}
|
||||||
|
@ -295,20 +295,17 @@ 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 = i.i.Update(doc)
|
err = i.i.Update(doc)
|
||||||
if err != nil {
|
return
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete entries for the specified identifier from
|
// Delete entries for the specified identifier from
|
||||||
// the index.
|
// the index.
|
||||||
func (i *indexImpl) Delete(id string) error {
|
func (i *indexImpl) Delete(id string) (err error) {
|
||||||
if id == "" {
|
if id == "" {
|
||||||
return ErrorEmptyID
|
return ErrorEmptyID
|
||||||
}
|
}
|
||||||
|
@ -320,11 +317,8 @@ func (i *indexImpl) Delete(id string) error {
|
||||||
return ErrorIndexClosed
|
return ErrorIndexClosed
|
||||||
}
|
}
|
||||||
|
|
||||||
err := i.i.Delete(id)
|
err = i.i.Delete(id)
|
||||||
if err != nil {
|
return
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Batch executes multiple Index and Delete
|
// Batch executes multiple Index and Delete
|
||||||
|
|
|
@ -50,7 +50,11 @@ func (dm *DocumentMatch) AddFieldValue(name string, value interface{}) {
|
||||||
dm.Fields = make(map[string]interface{})
|
dm.Fields = make(map[string]interface{})
|
||||||
}
|
}
|
||||||
existingVal, ok := dm.Fields[name]
|
existingVal, ok := dm.Fields[name]
|
||||||
if ok {
|
if !ok {
|
||||||
|
dm.Fields[name] = value
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
valSlice, ok := existingVal.([]interface{})
|
valSlice, ok := existingVal.([]interface{})
|
||||||
if ok {
|
if ok {
|
||||||
// already a slice, append to it
|
// already a slice, append to it
|
||||||
|
@ -60,9 +64,6 @@ func (dm *DocumentMatch) AddFieldValue(name string, value interface{}) {
|
||||||
valSlice = []interface{}{existingVal, value}
|
valSlice = []interface{}{existingVal, value}
|
||||||
}
|
}
|
||||||
dm.Fields[name] = valSlice
|
dm.Fields[name] = valSlice
|
||||||
} else {
|
|
||||||
dm.Fields[name] = value
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type DocumentMatchCollection []*DocumentMatch
|
type DocumentMatchCollection []*DocumentMatch
|
||||||
|
|
Loading…
Reference in New Issue
Block a user