0
0
Fork 0

even more golint cleanups

This commit is contained in:
Marty Schoch 2014-09-03 19:32:27 -04:00
parent e21935f850
commit 8b9255f52f
7 changed files with 58 additions and 58 deletions

View File

@ -40,15 +40,15 @@ func (h *DocDeleteHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
}
// find the doc id
docId := mux.Vars(req)["docId"]
if docId == "" {
docID := mux.Vars(req)["docID"]
if docID == "" {
showError(w, req, "document id cannot be empty", 400)
return
}
err := index.Delete(docId)
err := index.Delete(docID)
if err != nil {
showError(w, req, fmt.Sprintf("error deleting document '%s': %v", docId, err), 500)
showError(w, req, fmt.Sprintf("error deleting document '%s': %v", docID, err), 500)
return
}

View File

@ -42,19 +42,19 @@ func (h *DocGetHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
}
// find the doc id
docId := mux.Vars(req)["docId"]
if docId == "" {
docID := mux.Vars(req)["docID"]
if docID == "" {
showError(w, req, "document id cannot be empty", 400)
return
}
doc, err := index.Document(docId)
doc, err := index.Document(docID)
if err != nil {
showError(w, req, fmt.Sprintf("error deleting document '%s': %v", docId, err), 500)
showError(w, req, fmt.Sprintf("error deleting document '%s': %v", docID, err), 500)
return
}
if doc == nil {
showError(w, req, fmt.Sprintf("no such document '%s'", docId), 404)
showError(w, req, fmt.Sprintf("no such document '%s'", docID), 404)
return
}
@ -62,7 +62,7 @@ func (h *DocGetHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
ID string `json:"id"`
Fields map[string]interface{} `json:"fields"`
}{
ID: docId,
ID: docID,
Fields: map[string]interface{}{},
}
for _, field := range doc.Fields {

View File

@ -41,8 +41,8 @@ func (h *DocIndexHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
}
// find the doc id
docId := mux.Vars(req)["docId"]
if docId == "" {
docID := mux.Vars(req)["docID"]
if docID == "" {
showError(w, req, "document id cannot be empty", 400)
return
}
@ -54,9 +54,9 @@ func (h *DocIndexHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return
}
err = index.Index(docId, requestBody)
err = index.Index(docID, requestBody)
if err != nil {
showError(w, req, fmt.Sprintf("error indexing document '%s': %v", docId, err), 500)
showError(w, req, fmt.Sprintf("error indexing document '%s': %v", docID, err), 500)
return
}

View File

@ -27,7 +27,7 @@ type BooleanSearcher struct {
currMust *search.DocumentMatch
currShould *search.DocumentMatch
currMustNot *search.DocumentMatch
currentId string
currentID string
min uint64
scorer *scorers.ConjunctionQueryScorer
}
@ -91,11 +91,11 @@ func (s *BooleanSearcher) initSearchers() error {
}
if s.mustSearcher != nil && s.currMust != nil {
s.currentId = s.currMust.ID
s.currentID = s.currMust.ID
} else if s.mustSearcher == nil && s.currShould != nil {
s.currentId = s.currShould.ID
s.currentID = s.currShould.ID
} else {
s.currentId = ""
s.currentID = ""
}
s.initialized = true
@ -118,11 +118,11 @@ func (s *BooleanSearcher) advanceNextMust() error {
}
if s.mustSearcher != nil && s.currMust != nil {
s.currentId = s.currMust.ID
s.currentID = s.currMust.ID
} else if s.mustSearcher == nil && s.currShould != nil {
s.currentId = s.currShould.ID
s.currentID = s.currShould.ID
} else {
s.currentId = ""
s.currentID = ""
}
return nil
}
@ -160,31 +160,31 @@ func (s *BooleanSearcher) Next() (*search.DocumentMatch, error) {
var err error
var rv *search.DocumentMatch
for s.currentId != "" {
if s.currMustNot != nil && s.currMustNot.ID < s.currentId {
for s.currentID != "" {
if s.currMustNot != nil && s.currMustNot.ID < s.currentID {
// advance must not searcher to our candidate entry
s.currMustNot, err = s.mustNotSearcher.Advance(s.currentId)
s.currMustNot, err = s.mustNotSearcher.Advance(s.currentID)
if err != nil {
return nil, err
}
if s.currMustNot != nil && s.currMustNot.ID == s.currentId {
if s.currMustNot != nil && s.currMustNot.ID == s.currentID {
// the candidate is excluded
s.advanceNextMust()
continue
}
} else if s.currMustNot != nil && s.currMustNot.ID == s.currentId {
} else if s.currMustNot != nil && s.currMustNot.ID == s.currentID {
// the candidate is excluded
s.advanceNextMust()
continue
}
if s.currShould != nil && s.currShould.ID < s.currentId {
if s.currShould != nil && s.currShould.ID < s.currentID {
// advance should searcher to our candidate entry
s.currShould, err = s.shouldSearcher.Advance(s.currentId)
s.currShould, err = s.shouldSearcher.Advance(s.currentID)
if err != nil {
return nil, err
}
if s.currShould != nil && s.currShould.ID == s.currentId {
if s.currShould != nil && s.currShould.ID == s.currentID {
// score bonus matches should
cons := []*search.DocumentMatch{}
if s.currMust != nil {
@ -200,7 +200,7 @@ func (s *BooleanSearcher) Next() (*search.DocumentMatch, error) {
s.advanceNextMust()
break
}
} else if s.currShould != nil && s.currShould.ID == s.currentId {
} else if s.currShould != nil && s.currShould.ID == s.currentID {
// score bonus matches should
cons := []*search.DocumentMatch{}
if s.currMust != nil {
@ -252,11 +252,11 @@ func (s *BooleanSearcher) Advance(ID string) (*search.DocumentMatch, error) {
}
if s.mustSearcher != nil && s.currMust != nil {
s.currentId = s.currMust.ID
s.currentID = s.currMust.ID
} else if s.mustSearcher == nil && s.currShould != nil {
s.currentId = s.currShould.ID
s.currentID = s.currShould.ID
} else {
s.currentId = ""
s.currentID = ""
}
return s.Next()

View File

@ -25,7 +25,7 @@ type ConjunctionSearcher struct {
explain bool
queryNorm float64
currs []*search.DocumentMatch
currentId string
currentID string
scorer *scorers.ConjunctionQueryScorer
}
@ -75,9 +75,9 @@ func (s *ConjunctionSearcher) initSearchers() error {
if len(s.currs) > 0 {
if s.currs[0] != nil {
s.currentId = s.currs[0].ID
s.currentID = s.currs[0].ID
} else {
s.currentId = ""
s.currentID = ""
}
}
@ -109,26 +109,26 @@ func (s *ConjunctionSearcher) Next() (*search.DocumentMatch, error) {
var rv *search.DocumentMatch
var err error
OUTER:
for s.currentId != "" {
for s.currentID != "" {
for i, termSearcher := range s.searchers {
if s.currs[i] != nil && s.currs[i].ID != s.currentId {
// this reader doesn't have the currentId, try to advance
s.currs[i], err = termSearcher.Advance(s.currentId)
if s.currs[i] != nil && s.currs[i].ID != s.currentID {
// this reader doesn't have the currentID, try to advance
s.currs[i], err = termSearcher.Advance(s.currentID)
if err != nil {
return nil, err
}
if s.currs[i] == nil {
s.currentId = ""
s.currentID = ""
continue OUTER
}
if s.currs[i].ID != s.currentId {
if s.currs[i].ID != s.currentID {
// we just advanced, so it doesn't match, it must be greater
// no need to call next
s.currentId = s.currs[i].ID
s.currentID = s.currs[i].ID
continue OUTER
}
} else if s.currs[i] == nil {
s.currentId = ""
s.currentID = ""
continue OUTER
}
}
@ -141,9 +141,9 @@ OUTER:
return nil, err
}
if s.currs[0] == nil {
s.currentId = ""
s.currentID = ""
} else {
s.currentId = s.currs[0].ID
s.currentID = s.currs[0].ID
}
// don't continue now, wait for next call the Next()
break
@ -165,7 +165,7 @@ func (s *ConjunctionSearcher) Advance(ID string) (*search.DocumentMatch, error)
return nil, err
}
}
s.currentId = ID
s.currentID = ID
return s.Next()
}

View File

@ -24,7 +24,7 @@ type DisjunctionSearcher struct {
searchers OrderedSearcherList
queryNorm float64
currs []*search.DocumentMatch
currentId string
currentID string
scorer *scorers.DisjunctionQueryScorer
min float64
}
@ -73,12 +73,12 @@ func (s *DisjunctionSearcher) initSearchers() error {
}
}
s.currentId = s.nextSmallestId()
s.currentID = s.nextSmallestID()
s.initialized = true
return nil
}
func (s *DisjunctionSearcher) nextSmallestId() string {
func (s *DisjunctionSearcher) nextSmallestID() string {
rv := ""
for _, curr := range s.currs {
if curr != nil && (curr.ID < rv || rv == "") {
@ -114,9 +114,9 @@ func (s *DisjunctionSearcher) Next() (*search.DocumentMatch, error) {
matching := make([]*search.DocumentMatch, 0)
found := false
for !found && s.currentId != "" {
for !found && s.currentID != "" {
for _, curr := range s.currs {
if curr != nil && curr.ID == s.currentId {
if curr != nil && curr.ID == s.currentID {
matching = append(matching, curr)
}
}
@ -131,7 +131,7 @@ func (s *DisjunctionSearcher) Next() (*search.DocumentMatch, error) {
matching = make([]*search.DocumentMatch, 0)
// invoke next on all the matching searchers
for i, curr := range s.currs {
if curr != nil && curr.ID == s.currentId {
if curr != nil && curr.ID == s.currentID {
searcher := s.searchers[i]
s.currs[i], err = searcher.Next()
if err != nil {
@ -139,7 +139,7 @@ func (s *DisjunctionSearcher) Next() (*search.DocumentMatch, error) {
}
}
}
s.currentId = s.nextSmallestId()
s.currentID = s.nextSmallestID()
}
return rv, nil
}
@ -160,7 +160,7 @@ func (s *DisjunctionSearcher) Advance(ID string) (*search.DocumentMatch, error)
}
}
s.currentId = s.nextSmallestId()
s.currentID = s.nextSmallestID()
return s.Next()
}

View File

@ -22,7 +22,7 @@ import (
var indexPath = flag.String("index", "", "index path")
var fieldsOnly = flag.Bool("fields", false, "fields only")
var docId = flag.String("docId", "", "docId to dump")
var docID = flag.String("docID", "", "docID to dump")
var mappingOnly = flag.Bool("mapping", false, "print mapping")
func main() {
@ -48,8 +48,8 @@ func main() {
}
var dumpChan chan interface{}
if *docId != "" {
dumpChan = index.DumpDoc(*docId)
if *docID != "" {
dumpChan = index.DumpDoc(*docID)
} else if *fieldsOnly {
dumpChan = index.DumpFields()
} else {