From ae600763768a5532f965431444c168041dd91736 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Sat, 1 Jul 2023 19:50:43 +0800 Subject: [PATCH 1/4] fix: disable default mapping --- modules/indexer/issues/bleve/bleve.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/indexer/issues/bleve/bleve.go b/modules/indexer/issues/bleve/bleve.go index bb0bc4b04a414..296915baa483b 100644 --- a/modules/indexer/issues/bleve/bleve.go +++ b/modules/indexer/issues/bleve/bleve.go @@ -91,6 +91,7 @@ func generateIssueIndexMapping() (mapping.IndexMapping, error) { mapping.DefaultAnalyzer = issueIndexerAnalyzer mapping.AddDocumentMapping(issueIndexerDocType, docMapping) mapping.AddDocumentMapping("_all", bleve.NewDocumentDisabledMapping()) + mapping.DefaultMapping = bleve.NewDocumentDisabledMapping() // disable default mapping, avoid indexing unexpected structs return mapping, nil } From e952a43ff6d50965936d4155b34d93770dc66225 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Sat, 1 Jul 2023 19:53:02 +0800 Subject: [PATCH 2/4] fix: use IndexerData --- modules/indexer/issues/bleve/bleve.go | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/modules/indexer/issues/bleve/bleve.go b/modules/indexer/issues/bleve/bleve.go index 296915baa483b..9296c1478daa0 100644 --- a/modules/indexer/issues/bleve/bleve.go +++ b/modules/indexer/issues/bleve/bleve.go @@ -67,15 +67,16 @@ func generateIssueIndexMapping() (mapping.IndexMapping, error) { docMapping := bleve.NewDocumentMapping() numericFieldMapping := bleve.NewNumericFieldMapping() + numericFieldMapping.Store = false numericFieldMapping.IncludeInAll = false - docMapping.AddFieldMappingsAt("RepoID", numericFieldMapping) + docMapping.AddFieldMappingsAt("repo_id", numericFieldMapping) textFieldMapping := bleve.NewTextFieldMapping() textFieldMapping.Store = false textFieldMapping.IncludeInAll = false - docMapping.AddFieldMappingsAt("Title", textFieldMapping) - docMapping.AddFieldMappingsAt("Content", textFieldMapping) - docMapping.AddFieldMappingsAt("Comments", textFieldMapping) + docMapping.AddFieldMappingsAt("title", textFieldMapping) + docMapping.AddFieldMappingsAt("content", textFieldMapping) + docMapping.AddFieldMappingsAt("comments", textFieldMapping) if err := addUnicodeNormalizeTokenFilter(mapping); err != nil { return nil, err @@ -117,12 +118,7 @@ func NewIndexer(indexDir string) *Indexer { func (b *Indexer) Index(_ context.Context, issues []*internal.IndexerData) error { batch := inner_bleve.NewFlushingBatch(b.inner.Indexer, maxBatchSize) for _, issue := range issues { - if err := batch.Index(indexer_internal.Base36(issue.ID), struct { - RepoID int64 - Title string - Content string - Comments []string - }{ + if err := batch.Index(indexer_internal.Base36(issue.ID), &IndexerData{ RepoID: issue.RepoID, Title: issue.Title, Content: issue.Content, @@ -150,7 +146,7 @@ func (b *Indexer) Delete(_ context.Context, ids ...int64) error { func (b *Indexer) Search(ctx context.Context, keyword string, repoIDs []int64, limit, start int) (*internal.SearchResult, error) { var repoQueriesP []*query.NumericRangeQuery for _, repoID := range repoIDs { - repoQueriesP = append(repoQueriesP, numericEqualityQuery(repoID, "RepoID")) + repoQueriesP = append(repoQueriesP, numericEqualityQuery(repoID, "repo_id")) } repoQueries := make([]query.Query, len(repoQueriesP)) for i, v := range repoQueriesP { @@ -160,9 +156,9 @@ func (b *Indexer) Search(ctx context.Context, keyword string, repoIDs []int64, l indexerQuery := bleve.NewConjunctionQuery( bleve.NewDisjunctionQuery(repoQueries...), bleve.NewDisjunctionQuery( - newMatchPhraseQuery(keyword, "Title", issueIndexerAnalyzer), - newMatchPhraseQuery(keyword, "Content", issueIndexerAnalyzer), - newMatchPhraseQuery(keyword, "Comments", issueIndexerAnalyzer), + newMatchPhraseQuery(keyword, "title", issueIndexerAnalyzer), + newMatchPhraseQuery(keyword, "content", issueIndexerAnalyzer), + newMatchPhraseQuery(keyword, "comments", issueIndexerAnalyzer), )) search := bleve.NewSearchRequestOptions(indexerQuery, limit, start, false) search.SortBy([]string{"-_score"}) From a23f04f4676344429f426f14345cb6a4c96e5d87 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Sat, 1 Jul 2023 19:53:56 +0800 Subject: [PATCH 3/4] fix: update version --- modules/indexer/issues/bleve/bleve.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/indexer/issues/bleve/bleve.go b/modules/indexer/issues/bleve/bleve.go index 9296c1478daa0..78ba70eaee5a3 100644 --- a/modules/indexer/issues/bleve/bleve.go +++ b/modules/indexer/issues/bleve/bleve.go @@ -23,7 +23,7 @@ import ( const ( issueIndexerAnalyzer = "issueIndexer" issueIndexerDocType = "issueIndexerDocType" - issueIndexerLatestVersion = 2 + issueIndexerLatestVersion = 3 ) // numericEqualityQuery a numeric equality query for the given value and field From a2d591808724b51cbc23be9125780a048ce5891c Mon Sep 17 00:00:00 2001 From: Jason Song Date: Sat, 1 Jul 2023 20:40:04 +0800 Subject: [PATCH 4/4] fix: just convert type --- modules/indexer/issues/bleve/bleve.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/modules/indexer/issues/bleve/bleve.go b/modules/indexer/issues/bleve/bleve.go index 78ba70eaee5a3..50a2306ee6065 100644 --- a/modules/indexer/issues/bleve/bleve.go +++ b/modules/indexer/issues/bleve/bleve.go @@ -118,12 +118,7 @@ func NewIndexer(indexDir string) *Indexer { func (b *Indexer) Index(_ context.Context, issues []*internal.IndexerData) error { batch := inner_bleve.NewFlushingBatch(b.inner.Indexer, maxBatchSize) for _, issue := range issues { - if err := batch.Index(indexer_internal.Base36(issue.ID), &IndexerData{ - RepoID: issue.RepoID, - Title: issue.Title, - Content: issue.Content, - Comments: issue.Comments, - }); err != nil { + if err := batch.Index(indexer_internal.Base36(issue.ID), (*IndexerData)(issue)); err != nil { return err } }