Skip to content

Commit

Permalink
addess comments
Browse files Browse the repository at this point in the history
  • Loading branch information
CascadingRadium committed Dec 19, 2024
1 parent 0d80cde commit c94e916
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
15 changes: 6 additions & 9 deletions section_synonym_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (so *synonymIndexOpaque) Reset() (err error) {
func (so *synonymIndexOpaque) process(field index.SynonymField, fieldID uint16, docNum uint32) {
// if this is the first time we are processing a synonym field in this batch
// we need to allocate memory for the thesauri and related data structures
if !so.init && so.results != nil {
if !so.init {
so.realloc()
so.init = true
}
Expand Down Expand Up @@ -434,6 +434,9 @@ func (s *synonymIndexSection) Persist(opaque map[int]resetable, w *CountHashWrit
// Implements the AddrForField API for the synonym index section.
func (s *synonymIndexSection) AddrForField(opaque map[int]resetable, fieldID int) int {
synIndexOpaque := s.getSynonymIndexOpaque(opaque)
if synIndexOpaque == nil || synIndexOpaque.FieldIDtoThesaurusID == nil {
return 0
}
tid, exists := synIndexOpaque.FieldIDtoThesaurusID[uint16(fieldID)]
if !exists {
return 0
Expand Down Expand Up @@ -578,8 +581,6 @@ func mergeAndPersistSynonymSection(segments []*SegmentBase, dropsIn []*roaring.B

fieldIDtoThesaurusID := make(map[uint16]int)

synTermMap := make(map[uint32]string)
termSynMap := make(map[string]uint32)
var thesaurusID int
var newSynonymID uint32

Expand All @@ -591,12 +592,8 @@ func mergeAndPersistSynonymSection(segments []*SegmentBase, dropsIn []*roaring.B
thesauri = thesauri[:0]
itrs = itrs[:0]
newSynonymID = 0
for syn := range synTermMap {
delete(synTermMap, syn)
}
for syn := range termSynMap {
delete(termSynMap, syn)
}
synTermMap := make(map[uint32]string)
termSynMap := make(map[string]uint32)

for segmentI, segment := range segments {
// check for the closure in meantime
Expand Down
13 changes: 7 additions & 6 deletions segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,19 +492,20 @@ func (sb *SegmentBase) thesaurus(name string) (rv *Thesaurus, err error) {
if fieldIDPlus1 == 0 {
return nil, nil
}
thesaurusStart := sb.fieldsSectionsMap[fieldIDPlus1-1][SectionSynonymIndex]
if thesaurusStart > 0 {
pos := sb.fieldsSectionsMap[fieldIDPlus1-1][SectionSynonymIndex]
if pos > 0 {
rv = &Thesaurus{
sb: sb,
name: name,
fieldID: fieldIDPlus1 - 1,
}
// skip the doc value offsets as doc values are not supported in thesaurus
for i := 0; i < 2; i++ {
_, n := binary.Uvarint(sb.mem[thesaurusStart : thesaurusStart+binary.MaxVarintLen64])
thesaurusStart += uint64(n)
_, n := binary.Uvarint(sb.mem[pos : pos+binary.MaxVarintLen64])
pos += uint64(n)
}
thesLoc, n := binary.Uvarint(sb.mem[thesaurusStart : thesaurusStart+binary.MaxVarintLen64])
thesaurusStart += uint64(n)
thesLoc, n := binary.Uvarint(sb.mem[pos : pos+binary.MaxVarintLen64])
pos += uint64(n)
fst, synTermMap, err := sb.synIndexCache.loadOrCreate(rv.fieldID, sb.mem[thesLoc:])
if err != nil {
return nil, fmt.Errorf("thesaurus name %s err: %v", name, err)
Expand Down

0 comments on commit c94e916

Please sign in to comment.