diff --git a/section_synonym.go b/section_synonym.go index ef237bc..cf52bc6 100644 --- a/section_synonym.go +++ b/section_synonym.go @@ -719,7 +719,7 @@ func mergeSynonyms(synItr *SynonymsIterator, newDocNums []uint64, newRoaring *ro synTermMap map[uint32]string, termSynMap map[string]uint32, newSynonymID uint32) (uint32, error) { next, err := synItr.Next() for next != nil && err == nil { - synNewDocNum := newDocNums[next.DocNum()] + synNewDocNum := newDocNums[next.Number()] if synNewDocNum == docDropped { return 0, fmt.Errorf("see hit with dropped docNum") } diff --git a/synonym_posting.go b/synonym_posting.go index c965c16..9bec776 100644 --- a/synonym_posting.go +++ b/synonym_posting.go @@ -35,7 +35,7 @@ func init() { var si SynonymsIterator reflectStaticSizeSynonymsIterator = int(reflect.TypeOf(si).Size()) var s Synonym - reflectStaticSizePosting = int(reflect.TypeOf(s).Size()) + reflectStaticSizeSynonym = int(reflect.TypeOf(s).Size()) } type SynonymsList struct { @@ -205,7 +205,7 @@ type Synonym struct { } func (p *Synonym) Size() int { - sizeInBytes := reflectStaticSizePosting + SizeOfPtr + + sizeInBytes := reflectStaticSizeSynonym + SizeOfPtr + len(p.term) return sizeInBytes @@ -215,11 +215,7 @@ func (s *Synonym) Term() string { return s.term } -func (s *Synonym) SynonymID() uint32 { - return s.synID -} - -func (s *Synonym) DocNum() uint32 { +func (s *Synonym) Number() uint32 { return s.docNum } diff --git a/thesaurus.go b/thesaurus.go index 28515f9..e488ae6 100644 --- a/thesaurus.go +++ b/thesaurus.go @@ -19,6 +19,7 @@ import ( "fmt" "github.com/RoaringBitmap/roaring" + index "github.com/blevesearch/bleve_index_api" segment "github.com/blevesearch/scorch_segment_api/v2" "github.com/blevesearch/vellum" ) @@ -112,3 +113,47 @@ func (t *Thesaurus) Contains(key []byte) (bool, error) { } return false, nil } + +// AutomatonIterator returns an iterator which only visits terms +// having the the vellum automaton and start/end key range +func (t *Thesaurus) AutomatonIterator(a segment.Automaton, + startKeyInclusive, endKeyExclusive []byte) segment.ThesaurusIterator { + if t.fst != nil { + rv := &ThesaurusIterator{ + t: t, + } + + itr, err := t.fst.Search(a, startKeyInclusive, endKeyExclusive) + if err == nil { + rv.itr = itr + } else if err != vellum.ErrIteratorDone { + rv.err = err + } + + return rv + } + return emptyThesaurusIterator +} + +var emptyThesaurusIterator = &ThesaurusIterator{} + +// ThesaurusIterator is an iterator for term dictionary +type ThesaurusIterator struct { + t *Thesaurus + itr vellum.Iterator + err error + entry index.ThesaurusEntry +} + +// Next returns the next entry in the dictionary +func (i *ThesaurusIterator) Next() (*index.ThesaurusEntry, error) { + if i.err != nil && i.err != vellum.ErrIteratorDone { + return nil, i.err + } else if i.itr == nil || i.err == vellum.ErrIteratorDone { + return nil, nil + } + term, _ := i.itr.Current() + i.entry.Term = string(term) + i.err = i.itr.Next() + return &i.entry, nil +}