diff --git a/analysis/token/lowercase/lowercase.go b/analysis/token/lowercase/lowercase.go index eca62ee8..adb740c3 100644 --- a/analysis/token/lowercase/lowercase.go +++ b/analysis/token/lowercase/lowercase.go @@ -78,11 +78,11 @@ func toLowerDeferredCopy(s []byte) []byte { // Handles the Unicode edge-case where the last // rune in a word on the greek Σ needs to be converted // differently. - if l == 'σ' && i + 2 == len(s) { + if l == 'σ' && i+2 == len(s) { l = 'ς' } - lwid := utf8.RuneLen(l) + lwid := utf8.RuneLen(l) if lwid > wid { // utf-8 encoded replacement is wider // for now, punt and defer diff --git a/index/upsidedown/field_dict.go b/index/upsidedown/field_dict.go index ee8d2014..20d4eb34 100644 --- a/index/upsidedown/field_dict.go +++ b/index/upsidedown/field_dict.go @@ -44,7 +44,7 @@ func newUpsideDownCouchFieldDict(indexReader *IndexReader, field uint16, startTe return &UpsideDownCouchFieldDict{ indexReader: indexReader, iterator: it, - dictRow: &DictionaryRow{}, // Pre-alloced, reused row. + dictRow: &DictionaryRow{}, // Pre-alloced, reused row. dictEntry: &index.DictEntry{}, // Pre-alloced, reused entry. field: field, }, nil diff --git a/index/upsidedown/row.go b/index/upsidedown/row.go index b2ab21ab..5d9c80ee 100644 --- a/index/upsidedown/row.go +++ b/index/upsidedown/row.go @@ -242,9 +242,9 @@ func NewFieldRowKV(key, value []byte) (*FieldRow, error) { const DictionaryRowMaxValueSize = binary.MaxVarintLen64 type DictionaryRow struct { - field uint16 term []byte count uint64 + field uint16 } func (dr *DictionaryRow) Key() []byte { @@ -315,35 +315,20 @@ func NewDictionaryRowK(key []byte) (*DictionaryRow, error) { } func (dr *DictionaryRow) parseDictionaryK(key []byte) error { - buf := bytes.NewBuffer(key) - _, err := buf.ReadByte() // type - if err != nil { - return err + dr.field = binary.LittleEndian.Uint16(key[1:3]) + if dr.term != nil { + dr.term = dr.term[:0] } - - err = binary.Read(buf, binary.LittleEndian, &dr.field) - if err != nil { - return err - } - - dr.term, err = buf.ReadBytes(ByteSeparator) - // there is no separator expected here, should get EOF - if err != io.EOF { - return err - } - + dr.term = append(dr.term, key[3:]...) return nil } func (dr *DictionaryRow) parseDictionaryV(value []byte) error { - buf := bytes.NewBuffer(value) - - count, err := binary.ReadUvarint(buf) - if err != nil { - return err + count, nread := binary.Uvarint(value) + if nread <= 0 { + return fmt.Errorf("DictionaryRow parse Uvarint error, nread: %d", nread) } dr.count = count - return nil } diff --git a/search/searcher/search_disjunction.go b/search/searcher/search_disjunction.go index bf416baa..bd2ff68a 100644 --- a/search/searcher/search_disjunction.go +++ b/search/searcher/search_disjunction.go @@ -127,7 +127,7 @@ func (s *DisjunctionSearcher) updateMatches() error { return err } - last := len(s.searchers)-1 + last := len(s.searchers) - 1 s.searchers[i] = s.searchers[last] s.searchers = s.searchers[0:last] s.currs[i] = s.currs[last]