From e1b77956d4d73fb0164b26c9d03e4c9567805616 Mon Sep 17 00:00:00 2001 From: Marty Schoch Date: Wed, 3 Sep 2014 18:47:02 -0400 Subject: [PATCH] more golint cleanups --- http/registry.go | 2 +- index/store/boltdb/store.go | 2 +- index/upside_down/dump_test.go | 2 +- index/upside_down/field_reader_test.go | 6 ++--- index/upside_down/reader.go | 14 +++++------- index/upside_down/reader_test.go | 14 ++++++------ numeric_util/prefix_coded.go | 2 +- registry/registry.go | 22 +++++++++---------- search/collectors/collector_top_score.go | 5 ++--- .../html/fragment_formatter_html.go | 8 +++---- .../html/fragment_formatter_html_test.go | 8 +++---- .../highlighters/simple/highlighter_simple.go | 2 +- search/searchers/search_boolean.go | 2 +- search/searchers/search_conjunction.go | 2 +- search/searchers/search_disjunction.go | 2 +- search/searchers/search_numeric_range.go | 4 ++-- search/searchers/search_phrase.go | 4 ++-- 17 files changed, 48 insertions(+), 53 deletions(-) diff --git a/http/registry.go b/http/registry.go index a8ef159c..2ed97620 100644 --- a/http/registry.go +++ b/http/registry.go @@ -55,7 +55,7 @@ func IndexNames() []string { rv := make([]string, len(indexNameMapping)) count := 0 - for k, _ := range indexNameMapping { + for k := range indexNameMapping { rv[count] = k count++ } diff --git a/index/store/boltdb/store.go b/index/store/boltdb/store.go index 7eb389df..dbb4c50c 100644 --- a/index/store/boltdb/store.go +++ b/index/store/boltdb/store.go @@ -50,7 +50,7 @@ func Open(path string, bucket string) (*BoltDBStore, error) { } func (bs *BoltDBStore) Get(key []byte) ([]byte, error) { - var rv []byte = nil + var rv []byte err := bs.db.View(func(tx *bolt.Tx) error { rv = tx.Bucket([]byte(bs.bucket)).Get(key) diff --git a/index/upside_down/dump_test.go b/index/upside_down/dump_test.go index e39a8a6d..acec5007 100644 --- a/index/upside_down/dump_test.go +++ b/index/upside_down/dump_test.go @@ -32,7 +32,7 @@ func TestDump(t *testing.T) { } defer idx.Close() - var expectedCount uint64 = 0 + var expectedCount uint64 docCount := idx.DocCount() if docCount != expectedCount { t.Errorf("Expected document count to be %d got %d", expectedCount, docCount) diff --git a/index/upside_down/field_reader_test.go b/index/upside_down/field_reader_test.go index 95ac11f5..c0a01bd7 100644 --- a/index/upside_down/field_reader_test.go +++ b/index/upside_down/field_reader_test.go @@ -29,14 +29,14 @@ func TestIndexFieldReader(t *testing.T) { } defer idx.Close() - var expectedCount uint64 = 0 + var expectedCount uint64 doc := document.NewDocument("1") doc.AddField(document.NewTextField("name", []uint64{}, []byte("test"))) err = idx.Update(doc) if err != nil { t.Errorf("Error updating index: %v", err) } - expectedCount += 1 + expectedCount++ doc = document.NewDocument("2") doc.AddField(document.NewTextFieldWithAnalyzer("name", []uint64{}, []byte("test test test"), testAnalyzer)) @@ -46,7 +46,7 @@ func TestIndexFieldReader(t *testing.T) { if err != nil { t.Errorf("Error updating index: %v", err) } - expectedCount += 1 + expectedCount++ reader, err := idx.FieldReader("name", nil, nil) if err != nil { diff --git a/index/upside_down/reader.go b/index/upside_down/reader.go index 2aa58e5d..6cb20dac 100644 --- a/index/upside_down/reader.go +++ b/index/upside_down/reader.go @@ -28,7 +28,7 @@ func newUpsideDownCouchTermFieldReader(index *UpsideDownCouch, term []byte, fiel tfr := NewTermFrequencyRow(term, field, "", 0, 0) it := index.store.Iterator(tfr.Key()) - var count uint64 = 0 + var count uint64 key, val, valid := it.Current() if valid { if bytes.Equal(key, tfr.Key()) { @@ -72,9 +72,8 @@ func (r *UpsideDownCouchTermFieldReader) Next() (*index.TermFieldDoc, error) { Norm: float64(tfr.norm), Vectors: r.index.termFieldVectorsFromTermVectors(tfr.vectors), }, nil - } else { - return nil, nil } + return nil, nil } func (r *UpsideDownCouchTermFieldReader) Advance(docId string) (*index.TermFieldDoc, error) { @@ -97,9 +96,8 @@ func (r *UpsideDownCouchTermFieldReader) Advance(docId string) (*index.TermField Norm: float64(tfr.norm), Vectors: r.index.termFieldVectorsFromTermVectors(tfr.vectors), }, nil - } else { - return nil, nil } + return nil, nil } func (r *UpsideDownCouchTermFieldReader) Close() { @@ -145,9 +143,8 @@ func (r *UpsideDownCouchDocIdReader) Next() (string, error) { } r.iterator.Next() return string(br.doc), nil - } else { - return "", nil } + return "", nil } func (r *UpsideDownCouchDocIdReader) Advance(docId string) (string, error) { @@ -166,9 +163,8 @@ func (r *UpsideDownCouchDocIdReader) Advance(docId string) (string, error) { } r.iterator.Next() return string(br.doc), nil - } else { - return "", nil } + return "", nil } func (r *UpsideDownCouchDocIdReader) Close() { diff --git a/index/upside_down/reader_test.go b/index/upside_down/reader_test.go index 5d7c8695..6d8457eb 100644 --- a/index/upside_down/reader_test.go +++ b/index/upside_down/reader_test.go @@ -30,14 +30,14 @@ func TestIndexReader(t *testing.T) { } defer idx.Close() - var expectedCount uint64 = 0 + var expectedCount uint64 doc := document.NewDocument("1") doc.AddField(document.NewTextField("name", []uint64{}, []byte("test"))) err = idx.Update(doc) if err != nil { t.Errorf("Error updating index: %v", err) } - expectedCount += 1 + expectedCount++ doc = document.NewDocument("2") doc.AddField(document.NewTextFieldWithAnalyzer("name", []uint64{}, []byte("test test test"), testAnalyzer)) @@ -46,7 +46,7 @@ func TestIndexReader(t *testing.T) { if err != nil { t.Errorf("Error updating index: %v", err) } - expectedCount += 1 + expectedCount++ // first look for a term that doesnt exist reader, err := idx.TermFieldReader([]byte("nope"), "name") @@ -78,7 +78,7 @@ func TestIndexReader(t *testing.T) { if err != nil { t.Errorf("unexpected error reading next") } - actualCount += 1 + actualCount++ } if actualCount != count { t.Errorf("count was 2, but only saw %d", actualCount) @@ -172,14 +172,14 @@ func TestIndexDocIdReader(t *testing.T) { } defer idx.Close() - var expectedCount uint64 = 0 + var expectedCount uint64 doc := document.NewDocument("1") doc.AddField(document.NewTextField("name", []uint64{}, []byte("test"))) err = idx.Update(doc) if err != nil { t.Errorf("Error updating index: %v", err) } - expectedCount += 1 + expectedCount++ doc = document.NewDocument("2") doc.AddField(document.NewTextField("name", []uint64{}, []byte("test test test"))) @@ -188,7 +188,7 @@ func TestIndexDocIdReader(t *testing.T) { if err != nil { t.Errorf("Error updating index: %v", err) } - expectedCount += 1 + expectedCount++ // first get all doc ids reader, err := idx.DocIdReader("", "") diff --git a/numeric_util/prefix_coded.go b/numeric_util/prefix_coded.go index d55eae18..263a1cf4 100644 --- a/numeric_util/prefix_coded.go +++ b/numeric_util/prefix_coded.go @@ -65,7 +65,7 @@ func (p PrefixCoded) Int64() (int64, error) { if err != nil { return 0, err } - var sortableBits int64 = 0 + var sortableBits int64 for _, inbyte := range p[1:] { sortableBits <<= 7 sortableBits |= int64(inbyte) diff --git a/registry/registry.go b/registry/registry.go index 412fcde2..206362c4 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -178,7 +178,7 @@ func (c *Cache) DefineHighlighter(name string, config map[string]interface{}) (h func PrintRegistry() { sorted := make(sort.StringSlice, 0, len(charFilters)) - for name, _ := range charFilters { + for name := range charFilters { sorted = append(sorted, name) } sorted.Sort() @@ -189,7 +189,7 @@ func PrintRegistry() { fmt.Println() sorted = make(sort.StringSlice, 0, len(tokenizers)) - for name, _ := range tokenizers { + for name := range tokenizers { sorted = append(sorted, name) } sorted.Sort() @@ -200,7 +200,7 @@ func PrintRegistry() { fmt.Println() sorted = make(sort.StringSlice, 0, len(tokenMaps)) - for name, _ := range tokenMaps { + for name := range tokenMaps { sorted = append(sorted, name) } sorted.Sort() @@ -211,7 +211,7 @@ func PrintRegistry() { fmt.Println() sorted = make(sort.StringSlice, 0, len(tokenFilters)) - for name, _ := range tokenFilters { + for name := range tokenFilters { sorted = append(sorted, name) } sorted.Sort() @@ -222,7 +222,7 @@ func PrintRegistry() { fmt.Println() sorted = make(sort.StringSlice, 0, len(analyzers)) - for name, _ := range analyzers { + for name := range analyzers { sorted = append(sorted, name) } sorted.Sort() @@ -233,7 +233,7 @@ func PrintRegistry() { fmt.Println() sorted = make(sort.StringSlice, 0, len(dateTimeParsers)) - for name, _ := range dateTimeParsers { + for name := range dateTimeParsers { sorted = append(sorted, name) } sorted.Sort() @@ -244,7 +244,7 @@ func PrintRegistry() { fmt.Println() sorted = make(sort.StringSlice, 0, len(stores)) - for name, _ := range stores { + for name := range stores { sorted = append(sorted, name) } sorted.Sort() @@ -255,7 +255,7 @@ func PrintRegistry() { fmt.Println() sorted = make(sort.StringSlice, 0, len(byteArrayConverters)) - for name, _ := range byteArrayConverters { + for name := range byteArrayConverters { sorted = append(sorted, name) } sorted.Sort() @@ -266,7 +266,7 @@ func PrintRegistry() { fmt.Println() sorted = make(sort.StringSlice, 0, len(fragmentFormatters)) - for name, _ := range fragmentFormatters { + for name := range fragmentFormatters { sorted = append(sorted, name) } sorted.Sort() @@ -277,7 +277,7 @@ func PrintRegistry() { fmt.Println() sorted = make(sort.StringSlice, 0, len(fragmenters)) - for name, _ := range fragmenters { + for name := range fragmenters { sorted = append(sorted, name) } sorted.Sort() @@ -288,7 +288,7 @@ func PrintRegistry() { fmt.Println() sorted = make(sort.StringSlice, 0, len(highlighters)) - for name, _ := range highlighters { + for name := range highlighters { sorted = append(sorted, name) } sorted.Sort() diff --git a/search/collectors/collector_top_score.go b/search/collectors/collector_top_score.go index 8264e2e1..d0729966 100644 --- a/search/collectors/collector_top_score.go +++ b/search/collectors/collector_top_score.go @@ -74,7 +74,7 @@ func (tksc *TopScoreCollector) Collect(searcher search.Searcher) error { func (tksc *TopScoreCollector) collectSingle(dm *search.DocumentMatch) { // increment total hits - tksc.total += 1 + tksc.total++ // update max score if dm.Score > tksc.maxScore { @@ -127,7 +127,6 @@ func (tksc *TopScoreCollector) SetFacetsBuilder(facetsBuilder *search.FacetsBuil func (tksc *TopScoreCollector) FacetResults() search.FacetResults { if tksc.facetsBuilder != nil { return tksc.facetsBuilder.Results() - } else { - return search.FacetResults{} } + return search.FacetResults{} } diff --git a/search/highlight/fragment_formatters/html/fragment_formatter_html.go b/search/highlight/fragment_formatters/html/fragment_formatter_html.go index 93281fed..3a2c5629 100644 --- a/search/highlight/fragment_formatters/html/fragment_formatter_html.go +++ b/search/highlight/fragment_formatters/html/fragment_formatter_html.go @@ -17,8 +17,8 @@ import ( const Name = "html" -const defaultHtmlHighlightBefore = "" -const defaultHtmlHighlightAfter = "" +const defaultHTMLHighlightBefore = "" +const defaultHTMLHighlightAfter = "" type HTMLFragmentFormatter struct { before string @@ -61,12 +61,12 @@ func (a *HTMLFragmentFormatter) Format(f *highlight.Fragment, tlm search.TermLoc } func Constructor(config map[string]interface{}, cache *registry.Cache) (highlight.FragmentFormatter, error) { - before := defaultHtmlHighlightBefore + before := defaultHTMLHighlightBefore beforeVal, ok := config["before"].(string) if ok { before = beforeVal } - after := defaultHtmlHighlightAfter + after := defaultHTMLHighlightAfter afterVal, ok := config["after"].(string) if ok { after = afterVal diff --git a/search/highlight/fragment_formatters/html/fragment_formatter_html_test.go b/search/highlight/fragment_formatters/html/fragment_formatter_html_test.go index e8aa6e00..5fe46ab1 100644 --- a/search/highlight/fragment_formatters/html/fragment_formatter_html_test.go +++ b/search/highlight/fragment_formatters/html/fragment_formatter_html_test.go @@ -41,9 +41,9 @@ func TestHTMLFragmentFormatter1(t *testing.T) { }, } - emHtmlFormatter := NewHTMLFragmentFormatter("", "") + emHTMLFormatter := NewHTMLFragmentFormatter("", "") for _, test := range tests { - result := emHtmlFormatter.Format(test.fragment, test.tlm) + result := emHTMLFormatter.Format(test.fragment, test.tlm) if result != test.output { t.Errorf("expected `%s`, got `%s`", test.output, result) } @@ -75,9 +75,9 @@ func TestHTMLFragmentFormatter2(t *testing.T) { }, } - emHtmlFormatter := NewHTMLFragmentFormatter("", "") + emHTMLFormatter := NewHTMLFragmentFormatter("", "") for _, test := range tests { - result := emHtmlFormatter.Format(test.fragment, test.tlm) + result := emHTMLFormatter.Format(test.fragment, test.tlm) if result != test.output { t.Errorf("expected `%s`, got `%s`", test.output, result) } diff --git a/search/highlight/highlighters/simple/highlighter_simple.go b/search/highlight/highlighters/simple/highlighter_simple.go index c2deccae..68685ba9 100644 --- a/search/highlight/highlighters/simple/highlighter_simple.go +++ b/search/highlight/highlighters/simple/highlighter_simple.go @@ -140,7 +140,7 @@ func (s *SimpleHighlighter) BestFragmentsInField(dm *search.DocumentMatch, doc * return formattedFragments } -// A PriorityQueue implements heap.Interface and holds Items. +// FragmentQueue implements heap.Interface and holds Items. type FragmentQueue []*highlight.Fragment func (fq FragmentQueue) Len() int { return len(fq) } diff --git a/search/searchers/search_boolean.go b/search/searchers/search_boolean.go index 98930d80..5fa90c5d 100644 --- a/search/searchers/search_boolean.go +++ b/search/searchers/search_boolean.go @@ -265,7 +265,7 @@ func (s *BooleanSearcher) Advance(ID string) (*search.DocumentMatch, error) { func (s *BooleanSearcher) Count() uint64 { // for now return a worst case - var sum uint64 = 0 + var sum uint64 if s.mustSearcher != nil { sum += s.mustSearcher.Count() } diff --git a/search/searchers/search_conjunction.go b/search/searchers/search_conjunction.go index 7ab27440..29dfccd5 100644 --- a/search/searchers/search_conjunction.go +++ b/search/searchers/search_conjunction.go @@ -171,7 +171,7 @@ func (s *ConjunctionSearcher) Advance(ID string) (*search.DocumentMatch, error) func (s *ConjunctionSearcher) Count() uint64 { // for now return a worst case - var sum uint64 = 0 + var sum uint64 for _, searcher := range s.searchers { sum += searcher.Count() } diff --git a/search/searchers/search_disjunction.go b/search/searchers/search_disjunction.go index 84e0d40c..93935adb 100644 --- a/search/searchers/search_disjunction.go +++ b/search/searchers/search_disjunction.go @@ -167,7 +167,7 @@ func (s *DisjunctionSearcher) Advance(ID string) (*search.DocumentMatch, error) func (s *DisjunctionSearcher) Count() uint64 { // for now return a worst case - var sum uint64 = 0 + var sum uint64 for _, searcher := range s.searchers { sum += searcher.Count() } diff --git a/search/searchers/search_numeric_range.go b/search/searchers/search_numeric_range.go index fec22ec1..c5fed0b1 100644 --- a/search/searchers/search_numeric_range.go +++ b/search/searchers/search_numeric_range.go @@ -48,11 +48,11 @@ func NewNumericRangeSearcher(index index.Index, min *float64, max *float64, incl // find all the ranges minInt64 := numeric_util.Float64ToInt64(*min) if !*inclusiveMin && minInt64 != math.MaxInt64 { - minInt64 += 1 + minInt64++ } maxInt64 := numeric_util.Float64ToInt64(*max) if !*inclusiveMax && maxInt64 != math.MinInt64 { - maxInt64 -= 1 + maxInt64-- } // FIXME hard-coded precion, should match field declaration termRanges := splitInt64Range(minInt64, maxInt64, 4) diff --git a/search/searchers/search_phrase.go b/search/searchers/search_phrase.go index d53015bb..3b22f0ab 100644 --- a/search/searchers/search_phrase.go +++ b/search/searchers/search_phrase.go @@ -134,7 +134,7 @@ func (s *PhraseSearcher) Next() (*search.DocumentMatch, error) { } } // if we got here all the terms matched - freq += 1 + freq++ search.MergeTermLocationMaps(rvtlm, crvtlm) rvftlm[field] = rvtlm } @@ -168,7 +168,7 @@ func (s *PhraseSearcher) Advance(ID string) (*search.DocumentMatch, error) { func (s *PhraseSearcher) Count() uint64 { // for now return a worst case - var sum uint64 = 0 + var sum uint64 sum += s.mustSearcher.Count() return sum }