Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
CascadingRadium committed Dec 11, 2024
1 parent 2f8298c commit 5e40167
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 13 deletions.
2 changes: 0 additions & 2 deletions doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,5 +330,3 @@ func newStubSynonymDocument(id string, synonymField index.SynonymField) index.Sy
}
return rv
}

// -----------------------------------------------------------------------------
4 changes: 2 additions & 2 deletions section_inverted_text_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,6 @@ func (io *invertedIndexOpaque) writeDicts(w *CountHashWriter) (dictOffsets []uin
}

for fieldID, terms := range io.DictKeys {
dict := io.Dicts[fieldID]

if cap(docTermMap) < len(io.results) {
docTermMap = make([][]byte, len(io.results))
} else {
Expand All @@ -461,6 +459,8 @@ func (io *invertedIndexOpaque) writeDicts(w *CountHashWriter) (dictOffsets []uin
}
}

dict := io.Dicts[fieldID]

for _, term := range terms { // terms are already sorted
pid := dict[term] - 1

Expand Down
6 changes: 1 addition & 5 deletions segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func (sb *SegmentBase) dictionary(field string) (rv *Dictionary, err error) {
return rv, nil
}

// Thesaurus returns the term thesaurus for the specified field
// Thesaurus returns the thesaurus with the specified name, or an empty thesaurus if not found.
func (s *SegmentBase) Thesaurus(name string) (segment.Thesaurus, error) {

Check failure on line 482 in segment.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, macos-latest)

undefined: segment.Thesaurus

Check failure on line 482 in segment.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, ubuntu-latest)

undefined: segment.Thesaurus

Check failure on line 482 in segment.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, ubuntu-latest)

undefined: segment.Thesaurus

Check failure on line 482 in segment.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, macos-latest)

undefined: segment.Thesaurus

Check failure on line 482 in segment.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, ubuntu-latest)

undefined: segment.Thesaurus
thesaurus, err := s.thesaurus(name)
if err == nil && thesaurus == nil {
Expand All @@ -499,14 +499,10 @@ func (sb *SegmentBase) thesaurus(name string) (rv *Thesaurus, err error) {
name: name,
fieldID: fieldIDPlus1 - 1,
}
// the below loop loads the following:
// 1. doc values(first 2 iterations) - adhering to the sections format. never
// valid values for synonym section.
for i := 0; i < 2; i++ {
_, n := binary.Uvarint(sb.mem[thesaurusStart : thesaurusStart+binary.MaxVarintLen64])
thesaurusStart += uint64(n)
}
// 2. thesaurus location - valid value for synonym section.
thesLoc, n := binary.Uvarint(sb.mem[thesaurusStart : thesaurusStart+binary.MaxVarintLen64])
thesaurusStart += uint64(n)
fst, synTermMap, err := sb.synIndexCache.loadOrCreate(rv.fieldID, sb.mem[thesLoc:])
Expand Down
3 changes: 1 addition & 2 deletions synonym_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func (sc *synonymIndexCache) loadOrCreate(fieldID uint16, mem []byte) (*vellum.F

func (sc *synonymIndexCache) createAndCacheLOCKED(fieldID uint16, mem []byte) (*vellum.FST, map[uint32][]byte, error) {
var pos uint64
// read the length of the vellum data
vellumLen, read := binary.Uvarint(mem[pos : pos+binary.MaxVarintLen64])
if vellumLen == 0 || read <= 0 {
return nil, nil, fmt.Errorf("vellum length is 0")
Expand All @@ -77,12 +76,12 @@ func (sc *synonymIndexCache) createAndCacheLOCKED(fieldID uint16, mem []byte) (*
return nil, nil, fmt.Errorf("vellum err: %v", err)
}
pos += vellumLen
synTermMap := make(map[uint32][]byte)
numSyns, n := binary.Uvarint(mem[pos : pos+binary.MaxVarintLen64])
pos += uint64(n)
if numSyns == 0 {
return nil, nil, fmt.Errorf("no synonyms found")
}
synTermMap := make(map[uint32][]byte, numSyns)
for i := 0; i < int(numSyns); i++ {
synID, n := binary.Uvarint(mem[pos : pos+binary.MaxVarintLen64])
pos += uint64(n)
Expand Down
2 changes: 0 additions & 2 deletions synonym_posting.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ func (s *SynonymsList) iterator(rv *SynonymsIterator) *SynonymsIterator {
rv.except = s.except
rv.Actual = s.synonyms.Iterator()
rv.ActualBM = s.synonyms

rv.synIDTermMap = s.synIDTermMap

return rv
}

Expand Down

0 comments on commit 5e40167

Please sign in to comment.