Skip to content

Commit e79054f

Browse files
committed
feat: make issuer indexer support multiple projects
1 parent e87dea4 commit e79054f

File tree

6 files changed

+32
-14
lines changed

6 files changed

+32
-14
lines changed

modules/indexer/issues/bleve/bleve.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
const (
2424
issueIndexerAnalyzer = "issueIndexer"
2525
issueIndexerDocType = "issueIndexerDocType"
26-
issueIndexerLatestVersion = 4
26+
issueIndexerLatestVersion = 5
2727
)
2828

2929
const unicodeNormalizeName = "unicodeNormalize"
@@ -82,7 +82,8 @@ func generateIssueIndexMapping() (mapping.IndexMapping, error) {
8282
docMapping.AddFieldMappingsAt("label_ids", numberFieldMapping)
8383
docMapping.AddFieldMappingsAt("no_label", boolFieldMapping)
8484
docMapping.AddFieldMappingsAt("milestone_id", numberFieldMapping)
85-
docMapping.AddFieldMappingsAt("project_id", numberFieldMapping)
85+
docMapping.AddFieldMappingsAt("project_ids", numberFieldMapping)
86+
docMapping.AddFieldMappingsAt("no_project", boolFieldMapping)
8687
docMapping.AddFieldMappingsAt("project_board_id", numberFieldMapping)
8788
docMapping.AddFieldMappingsAt("poster_id", numberFieldMapping)
8889
docMapping.AddFieldMappingsAt("assignee_id", numberFieldMapping)
@@ -226,7 +227,11 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
226227
}
227228

228229
if options.ProjectID.Has() {
229-
queries = append(queries, inner_bleve.NumericEqualityQuery(options.ProjectID.Value(), "project_id"))
230+
if v := options.ProjectID.Value(); v != 0 {
231+
queries = append(queries, inner_bleve.NumericEqualityQuery(v, "project_ids"))
232+
} else {
233+
queries = append(queries, inner_bleve.BoolFieldQuery(true, "no_project"))
234+
}
230235
}
231236
if options.ProjectBoardID.Has() {
232237
queries = append(queries, inner_bleve.NumericEqualityQuery(options.ProjectBoardID.Value(), "project_board_id"))

modules/indexer/issues/elasticsearch/elasticsearch.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ const (
6161
"label_ids": { "type": "integer", "index": true },
6262
"no_label": { "type": "boolean", "index": true },
6363
"milestone_id": { "type": "integer", "index": true },
64-
"project_id": { "type": "integer", "index": true },
64+
"project_ids": { "type": "integer", "index": true },
65+
"no_project": { "type": "boolean", "index": true },
6566
"project_board_id": { "type": "integer", "index": true },
6667
"poster_id": { "type": "integer", "index": true },
6768
"assignee_id": { "type": "integer", "index": true },
@@ -196,7 +197,11 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
196197
}
197198

198199
if options.ProjectID.Has() {
199-
query.Must(elastic.NewTermQuery("project_id", options.ProjectID.Value()))
200+
if v := options.ProjectID.Value(); v != 0 {
201+
query.Must(elastic.NewTermQuery("project_ids", v))
202+
} else {
203+
query.Must(elastic.NewTermQuery("no_project", true))
204+
}
200205
}
201206
if options.ProjectBoardID.Has() {
202207
query.Must(elastic.NewTermQuery("project_board_id", options.ProjectBoardID.Value()))

modules/indexer/issues/internal/model.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type IndexerData struct {
2727
NoLabel bool `json:"no_label"` // True if LabelIDs is empty
2828
MilestoneID int64 `json:"milestone_id"`
2929
ProjectIDs []int64 `json:"project_ids"`
30+
NoProject bool `json:"no_project"` // True if ProjectIDs is empty
3031
ProjectBoardID int64 `json:"project_board_id"`
3132
PosterID int64 `json:"poster_id"`
3233
AssigneeID int64 `json:"assignee_id"`
@@ -89,7 +90,7 @@ type SearchOptions struct {
8990

9091
MilestoneIDs []int64 // milestones the issues have
9192

92-
ProjectID optional.Option[int64] // project the issues belong to
93+
ProjectID optional.Option[int64] // project the issues belong to, zero means no project
9394
ProjectBoardID optional.Option[int64] // project board the issues belong to
9495

9596
PosterID optional.Option[int64] // poster of the issues

modules/indexer/issues/internal/tests/tests.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,10 @@ var cases = []*testIndexerCase{
312312
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
313313
assert.Equal(t, 5, len(result.Hits))
314314
for _, v := range result.Hits {
315-
assert.Equal(t, int64(1), data[v.ID].ProjectIDs)
315+
assert.Contains(t, data[v.ID].ProjectIDs, int64(1))
316316
}
317317
assert.Equal(t, countIndexerData(data, func(v *internal.IndexerData) bool {
318-
return v.ProjectIDs[0] == 1
318+
return slices.Contains(v.ProjectIDs, 1)
319319
}), result.Total)
320320
},
321321
},
@@ -330,10 +330,10 @@ var cases = []*testIndexerCase{
330330
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
331331
assert.Equal(t, 5, len(result.Hits))
332332
for _, v := range result.Hits {
333-
assert.Equal(t, int64(0), data[v.ID].ProjectIDs)
333+
assert.Empty(t, data[v.ID].ProjectIDs)
334334
}
335335
assert.Equal(t, countIndexerData(data, func(v *internal.IndexerData) bool {
336-
return v.ProjectIDs[0] == 0
336+
return len(v.ProjectIDs) == 0
337337
}), result.Total)
338338
},
339339
},
@@ -694,7 +694,7 @@ func generateDefaultIndexerData() []*internal.IndexerData {
694694
}
695695
projectIDs := make([]int64, id%5)
696696
for i := range projectIDs {
697-
projectIDs[i] = int64(i) + 1
697+
projectIDs[i] = int64(i) + 1 // ProjectID should not be 0
698698
}
699699

700700
data = append(data, &internal.IndexerData{
@@ -710,6 +710,7 @@ func generateDefaultIndexerData() []*internal.IndexerData {
710710
NoLabel: len(labelIDs) == 0,
711711
MilestoneID: issueIndex % 4,
712712
ProjectIDs: projectIDs,
713+
NoProject: len(projectIDs) == 0,
713714
ProjectBoardID: issueIndex % 6,
714715
PosterID: id%10 + 1, // PosterID should not be 0
715716
AssigneeID: issueIndex % 10,

modules/indexer/issues/meilisearch/meilisearch.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
)
1919

2020
const (
21-
issueIndexerLatestVersion = 3
21+
issueIndexerLatestVersion = 4
2222

2323
// TODO: make this configurable if necessary
2424
maxTotalHits = 10000
@@ -64,7 +64,8 @@ func NewIndexer(url, apiKey, indexerName string) *Indexer {
6464
"label_ids",
6565
"no_label",
6666
"milestone_id",
67-
"project_id",
67+
"project_ids",
68+
"no_project",
6869
"project_board_id",
6970
"poster_id",
7071
"assignee_id",
@@ -172,7 +173,11 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
172173
}
173174

174175
if options.ProjectID.Has() {
175-
query.And(inner_meilisearch.NewFilterEq("project_id", options.ProjectID.Value()))
176+
if v := options.ProjectID.Value(); v != 0 {
177+
query.And(inner_meilisearch.NewFilterEq("project_ids", v))
178+
} else {
179+
query.And(inner_meilisearch.NewFilterEq("no_label", true))
180+
}
176181
}
177182
if options.ProjectBoardID.Has() {
178183
query.And(inner_meilisearch.NewFilterEq("project_board_id", options.ProjectBoardID.Value()))

modules/indexer/issues/util.go

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ func getIssueIndexerData(ctx context.Context, issueID int64) (*internal.IndexerD
105105
NoLabel: len(labels) == 0,
106106
MilestoneID: issue.MilestoneID,
107107
ProjectIDs: projectIDs,
108+
NoProject: len(projectIDs) == 0,
108109
ProjectBoardID: issue.ProjectBoardID(ctx),
109110
PosterID: issue.PosterID,
110111
AssigneeID: issue.AssigneeID,

0 commit comments

Comments
 (0)