From cdad5b4dec7be6980c5bb6866cc9ba6b3ed552de Mon Sep 17 00:00:00 2001 From: CascadingRadium Date: Fri, 13 Dec 2024 12:56:16 +0530 Subject: [PATCH] address code review --- cmd/zap/cmd/synonym.go | 6 +++--- segment.go | 19 ++++++------------- zap.md | 3 ++- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/cmd/zap/cmd/synonym.go b/cmd/zap/cmd/synonym.go index d6ee14c..fbc579b 100644 --- a/cmd/zap/cmd/synonym.go +++ b/cmd/zap/cmd/synonym.go @@ -24,7 +24,7 @@ import ( "github.com/spf13/cobra" ) -var thesCmd = &cobra.Command{ +var thesaurusCmd = &cobra.Command{ Use: "thesaurus [path] [name]", Short: "thesaurus prints the thesaurus with the specified name", Long: `The thesaurus command lets you print the thesaurus with the specified name.`, @@ -38,7 +38,7 @@ var thesCmd = &cobra.Command{ return fmt.Errorf("must specify thesaurus name") } - pos, err := segment.ThesAddr(args[1]) + pos, err := segment.ThesaurusAddr(args[1]) if err != nil { return fmt.Errorf("error determining address: %v", err) } @@ -136,5 +136,5 @@ func decodeSynonym(synonymCode uint64) (synonymID uint32, docID uint32) { } func init() { - RootCmd.AddCommand(thesCmd) + RootCmd.AddCommand(thesaurusCmd) } diff --git a/segment.go b/segment.go index 13079c2..3be1a67 100644 --- a/segment.go +++ b/segment.go @@ -479,22 +479,14 @@ func (sb *SegmentBase) dictionary(field string) (rv *Dictionary, err error) { } // Thesaurus returns the thesaurus with the specified name, or an empty thesaurus if not found. -func (s *SegmentBase) Thesaurus(name string) (segment.Thesaurus, error) { - thesaurus, err := s.thesaurus(name) - if err == nil && thesaurus == nil { - return emptyThesaurus, nil - } - return thesaurus, err -} - -func (sb *SegmentBase) thesaurus(name string) (rv *Thesaurus, err error) { +func (sb *SegmentBase) Thesaurus(name string) (segment.Thesaurus, error) { fieldIDPlus1 := sb.fieldsMap[name] if fieldIDPlus1 == 0 { return nil, nil } thesaurusStart := sb.fieldsSectionsMap[fieldIDPlus1-1][SectionSynonymIndex] if thesaurusStart > 0 { - rv = &Thesaurus{ + rv := &Thesaurus{ sb: sb, name: name, fieldID: fieldIDPlus1 - 1, @@ -515,8 +507,9 @@ func (sb *SegmentBase) thesaurus(name string) (rv *Thesaurus, err error) { if err != nil { return nil, fmt.Errorf("thesaurus name %s vellum reader err: %v", name, err) } + return rv, nil } - return rv, nil + return emptyThesaurus, nil } // visitDocumentCtx holds data structures that are reusable across @@ -767,9 +760,9 @@ func (s *Segment) DictAddr(field string) (uint64, error) { return s.dictLocs[fieldIDPlus1-1], nil } -// ThesAddr is a helper function to compute the file offset where the +// ThesaurusAddr is a helper function to compute the file offset where the // thesaurus is stored with the specified name. -func (s *Segment) ThesAddr(name string) (uint64, error) { +func (s *Segment) ThesaurusAddr(name string) (uint64, error) { fieldIDPlus1, ok := s.fieldsMap[name] if !ok { return 0, fmt.Errorf("no such thesaurus '%s'", name) diff --git a/zap.md b/zap.md index 3186823..ef41364 100644 --- a/zap.md +++ b/zap.md @@ -209,7 +209,8 @@ In a synonyms index, the relationship between a term and its synonyms is represe ROARING64 BITMAP - Each 64-bit entry consists of two parts: the first 32 bits represent the Term ID (TID), and the next 32 bits represent the Document Number (DN). + Each 64-bit entry consists of two parts: the first 32 bits represent the Term ID (TID), + and the next 32 bits represent the Document Number (DN). [{~~~~~+~~~~~}{~~~~~+~~~~~}...{~~~~~+~~~~~}] | TID | DN || TID | DN | | TID | DN |