diff --git a/index/file_category.go b/index/file_category.go index 6ca4800af..172ec4754 100644 --- a/index/file_category.go +++ b/index/file_category.go @@ -111,4 +111,4 @@ func decodeCategory(c byte) (FileCategory, error) { default: return FileCategoryMissing, errors.New("unrecognized file category") } -} +} \ No newline at end of file diff --git a/index/indexdata.go b/index/indexdata.go index 6793ec377..7ce1bc265 100644 --- a/index/indexdata.go +++ b/index/indexdata.go @@ -103,6 +103,9 @@ type indexData struct { // rawConfigMasks contains the encoded RawConfig for each repository rawConfigMasks []uint8 + + //topic + topic String } type symbolData struct { @@ -188,6 +191,19 @@ func (d *indexData) getCategory(idx uint32) FileCategory { return category } +func (d *indexData) geTopic(idx uint32) String { + if len(d.topic) == 0 { + // So return 'Error' + return Error + } + + topic, err := decodeTopic(d.topic[idx]) + if err != nil { + return None + } + return topic +} + // calculates stats for files in the range [start, end). func (d *indexData) calculateStatsForFileRange(start, end uint32) zoekt.RepoStats { if start >= end { diff --git a/index/matchtree.go b/index/matchtree.go index 6929b350c..628db2b2d 100644 --- a/index/matchtree.go +++ b/index/matchtree.go @@ -1222,6 +1222,19 @@ func (d *indexData) newMatchTree(q query.Q, opt matchTreeOpt) (matchTree, error) }, }, nil + case *query.topic: + code, ok := d.metaData.LanguageMap[s.Language] + if !ok { + return &noMatchTree{Why: "topic"}, nil + } + return &docMatchTree{ + reason: "topic", + numDocs: d.numDocs(), + predicate: func(docID uint32) bool { + return d.geTopic(docID) == code //replace getLanguage by getTopic + }, + }, nil + case query.RawConfig: return &docMatchTree{ reason: s.String(), diff --git a/index/toc.go b/index/toc.go index f42887939..1cbaa01f8 100644 --- a/index/toc.go +++ b/index/toc.go @@ -101,6 +101,8 @@ type indexTOC struct { reposIDsBitmap simpleSection ranks simpleSection + + topic simpleSection } func (t *indexTOC) sections() []section { @@ -132,6 +134,7 @@ func (t *indexTOC) sections() []section { &t.contentChecksums, &t.languages, &t.runeDocSections, + &t.topic, } } @@ -185,6 +188,7 @@ func (t *indexTOC) sectionsTaggedList() []taggedSection { {"runeDocSections", &t.runeDocSections}, {"repos", &t.repos}, {"reposIDsBitmap", &t.reposIDsBitmap}, + {"topic", &t.topic}, // We no longer write these sections, but we still return them here to avoid // warnings about unknown sections.