Skip to content

Commit

Permalink
address code review
Browse files Browse the repository at this point in the history
  • Loading branch information
CascadingRadium committed Dec 13, 2024
1 parent 946a369 commit cdad5b4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
6 changes: 3 additions & 3 deletions cmd/zap/cmd/synonym.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
Expand All @@ -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)
}
Expand Down Expand Up @@ -136,5 +136,5 @@ func decodeSynonym(synonymCode uint64) (synonymID uint32, docID uint32) {
}

func init() {
RootCmd.AddCommand(thesCmd)
RootCmd.AddCommand(thesaurusCmd)
}
19 changes: 6 additions & 13 deletions segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion zap.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down

0 comments on commit cdad5b4

Please sign in to comment.