mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-28 23:29:42 +09:00
fix(indexer): fix assignee filters in issue search (#38021)
fix(indexer): fix assignee filters in issue search (#38021) Issue search filtering still relied on the legacy single-assignee field, so searches such as "Assigned to you" could miss issues when a keyword query was used. Index all issue assignee IDs and add an explicit no_assignee field so specific, any-assignee, and no-assignee filters work consistently across Bleve, Elasticsearch, and Meilisearch. Fixes #36299.
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
|||||||
indexer_internal "gitea.dev/modules/indexer/internal"
|
indexer_internal "gitea.dev/modules/indexer/internal"
|
||||||
inner_bleve "gitea.dev/modules/indexer/internal/bleve"
|
inner_bleve "gitea.dev/modules/indexer/internal/bleve"
|
||||||
"gitea.dev/modules/indexer/issues/internal"
|
"gitea.dev/modules/indexer/issues/internal"
|
||||||
"gitea.dev/modules/optional"
|
|
||||||
"gitea.dev/modules/util"
|
"gitea.dev/modules/util"
|
||||||
|
|
||||||
"github.com/blevesearch/bleve/v2"
|
"github.com/blevesearch/bleve/v2"
|
||||||
@@ -27,7 +26,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
issueIndexerAnalyzer = "issueIndexer"
|
issueIndexerAnalyzer = "issueIndexer"
|
||||||
issueIndexerDocType = "issueIndexerDocType"
|
issueIndexerDocType = "issueIndexerDocType"
|
||||||
issueIndexerLatestVersion = 6
|
issueIndexerLatestVersion = 7
|
||||||
)
|
)
|
||||||
|
|
||||||
const unicodeNormalizeName = "unicodeNormalize"
|
const unicodeNormalizeName = "unicodeNormalize"
|
||||||
@@ -86,7 +85,8 @@ func generateIssueIndexMapping() (mapping.IndexMapping, error) {
|
|||||||
docMapping.AddFieldMappingsAt("project_ids", numberFieldMapping)
|
docMapping.AddFieldMappingsAt("project_ids", numberFieldMapping)
|
||||||
docMapping.AddFieldMappingsAt("no_project", boolFieldMapping)
|
docMapping.AddFieldMappingsAt("no_project", boolFieldMapping)
|
||||||
docMapping.AddFieldMappingsAt("poster_id", numberFieldMapping)
|
docMapping.AddFieldMappingsAt("poster_id", numberFieldMapping)
|
||||||
docMapping.AddFieldMappingsAt("assignee_id", numberFieldMapping)
|
docMapping.AddFieldMappingsAt("assignee_ids", numberFieldMapping)
|
||||||
|
docMapping.AddFieldMappingsAt("no_assignee", boolFieldMapping)
|
||||||
docMapping.AddFieldMappingsAt("mention_ids", numberFieldMapping)
|
docMapping.AddFieldMappingsAt("mention_ids", numberFieldMapping)
|
||||||
docMapping.AddFieldMappingsAt("reviewed_ids", numberFieldMapping)
|
docMapping.AddFieldMappingsAt("reviewed_ids", numberFieldMapping)
|
||||||
docMapping.AddFieldMappingsAt("review_requested_ids", numberFieldMapping)
|
docMapping.AddFieldMappingsAt("review_requested_ids", numberFieldMapping)
|
||||||
@@ -258,14 +258,15 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
|
|||||||
queries = append(queries, inner_bleve.NumericEqualityQuery(posterIDInt64, "poster_id"))
|
queries = append(queries, inner_bleve.NumericEqualityQuery(posterIDInt64, "poster_id"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.AssigneeID != "" {
|
switch options.AssigneeID {
|
||||||
if options.AssigneeID == "(any)" {
|
case "":
|
||||||
queries = append(queries, inner_bleve.NumericRangeInclusiveQuery(optional.Some[int64](1), optional.None[int64](), "assignee_id"))
|
case "(any)":
|
||||||
} else {
|
queries = append(queries, inner_bleve.BoolFieldQuery(false, "no_assignee"))
|
||||||
// "(none)" becomes 0, it means no assignee
|
case "(none)":
|
||||||
assigneeIDInt64, _ := strconv.ParseInt(options.AssigneeID, 10, 64)
|
queries = append(queries, inner_bleve.BoolFieldQuery(true, "no_assignee"))
|
||||||
queries = append(queries, inner_bleve.NumericEqualityQuery(assigneeIDInt64, "assignee_id"))
|
default:
|
||||||
}
|
assigneeIDInt64, _ := strconv.ParseInt(options.AssigneeID, 10, 64)
|
||||||
|
queries = append(queries, inner_bleve.NumericEqualityQuery(assigneeIDInt64, "assignee_ids"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.MentionID.Has() {
|
if options.MentionID.Has() {
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ package bleve
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"gitea.dev/modules/indexer/issues/internal"
|
||||||
"gitea.dev/modules/indexer/issues/internal/tests"
|
"gitea.dev/modules/indexer/issues/internal/tests"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBleveIndexer(t *testing.T) {
|
func TestBleveIndexer(t *testing.T) {
|
||||||
@@ -16,3 +20,67 @@ func TestBleveIndexer(t *testing.T) {
|
|||||||
|
|
||||||
tests.TestIndexer(t, indexer)
|
tests.TestIndexer(t, indexer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBleveIndexerNoAssignee(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
indexer := NewIndexer(dir)
|
||||||
|
defer indexer.Close()
|
||||||
|
|
||||||
|
_, err := indexer.Init(t.Context())
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.NoError(t, indexer.Index(t.Context(),
|
||||||
|
&internal.IndexerData{ID: 1, Title: "assigned through assignee_ids", AssigneeIDs: []int64{2}},
|
||||||
|
&internal.IndexerData{ID: 2, Title: "unassigned", NoAssignee: true},
|
||||||
|
&internal.IndexerData{ID: 3, Title: "assigned through multiple assignee_ids", AssigneeIDs: []int64{3, 4}},
|
||||||
|
))
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
opts *internal.SearchOptions
|
||||||
|
expectedIDs []int64
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "none",
|
||||||
|
opts: &internal.SearchOptions{AssigneeID: "(none)"},
|
||||||
|
expectedIDs: []int64{2},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "any",
|
||||||
|
opts: &internal.SearchOptions{AssigneeID: "(any)"},
|
||||||
|
expectedIDs: []int64{1, 3},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "specific",
|
||||||
|
opts: &internal.SearchOptions{AssigneeID: "2"},
|
||||||
|
expectedIDs: []int64{1},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "specific first multi-assignee",
|
||||||
|
opts: &internal.SearchOptions{AssigneeID: "3"},
|
||||||
|
expectedIDs: []int64{3},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "specific second multi-assignee",
|
||||||
|
opts: &internal.SearchOptions{AssigneeID: "4"},
|
||||||
|
expectedIDs: []int64{3},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
result, err := indexer.Search(t.Context(), testCase.opts)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, int64(len(testCase.expectedIDs)), result.Total)
|
||||||
|
assert.ElementsMatch(t, testCase.expectedIDs, searchResultIDs(result))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func searchResultIDs(result *internal.SearchResult) []int64 {
|
||||||
|
ids := make([]int64, 0, len(result.Hits))
|
||||||
|
for _, hit := range result.Hits {
|
||||||
|
ids = append(ids, hit.ID)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import (
|
|||||||
"gitea.dev/modules/util"
|
"gitea.dev/modules/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
const issueIndexerLatestVersion = 3
|
const issueIndexerLatestVersion = 4
|
||||||
|
|
||||||
var _ internal.Indexer = &Indexer{}
|
var _ internal.Indexer = &Indexer{}
|
||||||
|
|
||||||
@@ -57,7 +57,8 @@ const (
|
|||||||
"project_ids": { "type": "integer", "index": true },
|
"project_ids": { "type": "integer", "index": true },
|
||||||
"no_project": { "type": "boolean", "index": true },
|
"no_project": { "type": "boolean", "index": true },
|
||||||
"poster_id": { "type": "integer", "index": true },
|
"poster_id": { "type": "integer", "index": true },
|
||||||
"assignee_id": { "type": "integer", "index": true },
|
"assignee_ids": { "type": "integer", "index": true },
|
||||||
|
"no_assignee": { "type": "boolean", "index": true },
|
||||||
"mention_ids": { "type": "integer", "index": true },
|
"mention_ids": { "type": "integer", "index": true },
|
||||||
"reviewed_ids": { "type": "integer", "index": true },
|
"reviewed_ids": { "type": "integer", "index": true },
|
||||||
"review_requested_ids": { "type": "integer", "index": true },
|
"review_requested_ids": { "type": "integer", "index": true },
|
||||||
@@ -177,14 +178,15 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
|
|||||||
query.Must(es.TermQuery("poster_id", posterIDInt64))
|
query.Must(es.TermQuery("poster_id", posterIDInt64))
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.AssigneeID != "" {
|
switch options.AssigneeID {
|
||||||
if options.AssigneeID == "(any)" {
|
case "":
|
||||||
query.Must(es.NewRangeQuery("assignee_id").Gte(1))
|
case "(any)":
|
||||||
} else {
|
query.Must(es.TermQuery("no_assignee", false))
|
||||||
// "(none)" becomes 0, it means no assignee
|
case "(none)":
|
||||||
assigneeIDInt64, _ := strconv.ParseInt(options.AssigneeID, 10, 64)
|
query.Must(es.TermQuery("no_assignee", true))
|
||||||
query.Must(es.TermQuery("assignee_id", assigneeIDInt64))
|
default:
|
||||||
}
|
assigneeIDInt64, _ := strconv.ParseInt(options.AssigneeID, 10, 64)
|
||||||
|
query.Must(es.TermQuery("assignee_ids", assigneeIDInt64))
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.MentionID.Has() {
|
if options.MentionID.Has() {
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ type IndexerData struct {
|
|||||||
NoProject bool `json:"no_project"` // True if ProjectIDs is empty
|
NoProject bool `json:"no_project"` // True if ProjectIDs is empty
|
||||||
ProjectColumnMap map[int64]int64 `json:"project_column_map,omitempty"` // Maps project ID to column ID for each project the issue is in
|
ProjectColumnMap map[int64]int64 `json:"project_column_map,omitempty"` // Maps project ID to column ID for each project the issue is in
|
||||||
PosterID int64 `json:"poster_id"`
|
PosterID int64 `json:"poster_id"`
|
||||||
AssigneeID int64 `json:"assignee_id"`
|
AssigneeIDs []int64 `json:"assignee_ids"`
|
||||||
|
NoAssignee bool `json:"no_assignee"` // True if the issue has no assignees
|
||||||
MentionIDs []int64 `json:"mention_ids"`
|
MentionIDs []int64 `json:"mention_ids"`
|
||||||
ReviewedIDs []int64 `json:"reviewed_ids"`
|
ReviewedIDs []int64 `json:"reviewed_ids"`
|
||||||
ReviewRequestedIDs []int64 `json:"review_requested_ids"`
|
ReviewRequestedIDs []int64 `json:"review_requested_ids"`
|
||||||
|
|||||||
@@ -377,10 +377,10 @@ var cases = []*testIndexerCase{
|
|||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Len(t, result.Hits, 5)
|
assert.Len(t, result.Hits, 5)
|
||||||
for _, v := range result.Hits {
|
for _, v := range result.Hits {
|
||||||
assert.Equal(t, int64(1), data[v.ID].AssigneeID)
|
assert.True(t, slices.Contains(data[v.ID].AssigneeIDs, int64(1)))
|
||||||
}
|
}
|
||||||
assert.Equal(t, countIndexerData(data, func(v *internal.IndexerData) bool {
|
assert.Equal(t, countIndexerData(data, func(v *internal.IndexerData) bool {
|
||||||
return v.AssigneeID == 1
|
return slices.Contains(v.AssigneeIDs, int64(1))
|
||||||
}), result.Total)
|
}), result.Total)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -395,10 +395,10 @@ var cases = []*testIndexerCase{
|
|||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Len(t, result.Hits, 5)
|
assert.Len(t, result.Hits, 5)
|
||||||
for _, v := range result.Hits {
|
for _, v := range result.Hits {
|
||||||
assert.Equal(t, int64(0), data[v.ID].AssigneeID)
|
assert.True(t, data[v.ID].NoAssignee)
|
||||||
}
|
}
|
||||||
assert.Equal(t, countIndexerData(data, func(v *internal.IndexerData) bool {
|
assert.Equal(t, countIndexerData(data, func(v *internal.IndexerData) bool {
|
||||||
return v.AssigneeID == 0
|
return v.NoAssignee
|
||||||
}), result.Total)
|
}), result.Total)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -630,10 +630,10 @@ var cases = []*testIndexerCase{
|
|||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Len(t, result.Hits, 180)
|
assert.Len(t, result.Hits, 180)
|
||||||
for _, v := range result.Hits {
|
for _, v := range result.Hits {
|
||||||
assert.GreaterOrEqual(t, data[v.ID].AssigneeID, int64(1))
|
assert.False(t, data[v.ID].NoAssignee)
|
||||||
}
|
}
|
||||||
assert.Equal(t, countIndexerData(data, func(v *internal.IndexerData) bool {
|
assert.Equal(t, countIndexerData(data, func(v *internal.IndexerData) bool {
|
||||||
return v.AssigneeID >= 1
|
return !v.NoAssignee
|
||||||
}), result.Total)
|
}), result.Total)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -686,6 +686,18 @@ func generateDefaultIndexerData() []*internal.IndexerData {
|
|||||||
for i := range projectIDs {
|
for i := range projectIDs {
|
||||||
projectIDs[i] = int64(i) + 1 // projectID should not be 0
|
projectIDs[i] = int64(i) + 1 // projectID should not be 0
|
||||||
}
|
}
|
||||||
|
var assigneeIDs []int64
|
||||||
|
if issueIndex%10 != 0 {
|
||||||
|
assigneeID := issueIndex % 10
|
||||||
|
assigneeIDs = []int64{assigneeID}
|
||||||
|
if issueIndex%3 == 0 {
|
||||||
|
nextAssigneeID := assigneeID + 1
|
||||||
|
if nextAssigneeID == 10 {
|
||||||
|
nextAssigneeID = 1
|
||||||
|
}
|
||||||
|
assigneeIDs = append(assigneeIDs, nextAssigneeID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
data = append(data, &internal.IndexerData{
|
data = append(data, &internal.IndexerData{
|
||||||
ID: id,
|
ID: id,
|
||||||
@@ -702,7 +714,8 @@ func generateDefaultIndexerData() []*internal.IndexerData {
|
|||||||
ProjectIDs: projectIDs,
|
ProjectIDs: projectIDs,
|
||||||
NoProject: len(projectIDs) == 0,
|
NoProject: len(projectIDs) == 0,
|
||||||
PosterID: id%10 + 1, // PosterID should not be 0
|
PosterID: id%10 + 1, // PosterID should not be 0
|
||||||
AssigneeID: issueIndex % 10,
|
AssigneeIDs: assigneeIDs,
|
||||||
|
NoAssignee: len(assigneeIDs) == 0,
|
||||||
MentionIDs: mentionIDs,
|
MentionIDs: mentionIDs,
|
||||||
ReviewedIDs: reviewedIDs,
|
ReviewedIDs: reviewedIDs,
|
||||||
ReviewRequestedIDs: reviewRequestedIDs,
|
ReviewRequestedIDs: reviewRequestedIDs,
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
issueIndexerLatestVersion = 5
|
issueIndexerLatestVersion = 6
|
||||||
|
|
||||||
// TODO: make this configurable if necessary
|
// TODO: make this configurable if necessary
|
||||||
maxTotalHits = 10000
|
maxTotalHits = 10000
|
||||||
@@ -74,7 +74,8 @@ func NewIndexer(url, apiKey, indexerName string) *Indexer {
|
|||||||
"project_ids",
|
"project_ids",
|
||||||
"no_project",
|
"no_project",
|
||||||
"poster_id",
|
"poster_id",
|
||||||
"assignee_id",
|
"assignee_ids",
|
||||||
|
"no_assignee",
|
||||||
"mention_ids",
|
"mention_ids",
|
||||||
"reviewed_ids",
|
"reviewed_ids",
|
||||||
"review_requested_ids",
|
"review_requested_ids",
|
||||||
@@ -195,14 +196,15 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
|
|||||||
query.And(inner_meilisearch.NewFilterEq("poster_id", posterIDInt64))
|
query.And(inner_meilisearch.NewFilterEq("poster_id", posterIDInt64))
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.AssigneeID != "" {
|
switch options.AssigneeID {
|
||||||
if options.AssigneeID == "(any)" {
|
case "":
|
||||||
query.And(inner_meilisearch.NewFilterGte("assignee_id", 1))
|
case "(any)":
|
||||||
} else {
|
query.And(inner_meilisearch.NewFilterEq("no_assignee", false))
|
||||||
// "(none)" becomes 0, it means no assignee
|
case "(none)":
|
||||||
assigneeIDInt64, _ := strconv.ParseInt(options.AssigneeID, 10, 64)
|
query.And(inner_meilisearch.NewFilterEq("no_assignee", true))
|
||||||
query.And(inner_meilisearch.NewFilterEq("assignee_id", assigneeIDInt64))
|
default:
|
||||||
}
|
assigneeIDInt64, _ := strconv.ParseInt(options.AssigneeID, 10, 64)
|
||||||
|
query.And(inner_meilisearch.NewFilterEq("assignee_ids", assigneeIDInt64))
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.MentionID.Has() {
|
if options.MentionID.Has() {
|
||||||
|
|||||||
@@ -87,6 +87,11 @@ func getIssueIndexerData(ctx context.Context, issueID int64) (*internal.IndexerD
|
|||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assigneeIDs := make([]int64, 0, len(issue.Assignees))
|
||||||
|
for _, a := range issue.Assignees {
|
||||||
|
assigneeIDs = append(assigneeIDs, a.ID)
|
||||||
|
}
|
||||||
|
|
||||||
projectIDs := make([]int64, 0, len(issue.Projects))
|
projectIDs := make([]int64, 0, len(issue.Projects))
|
||||||
for _, project := range issue.Projects {
|
for _, project := range issue.Projects {
|
||||||
projectIDs = append(projectIDs, project.ID)
|
projectIDs = append(projectIDs, project.ID)
|
||||||
@@ -112,7 +117,8 @@ func getIssueIndexerData(ctx context.Context, issueID int64) (*internal.IndexerD
|
|||||||
ProjectIDs: projectIDs,
|
ProjectIDs: projectIDs,
|
||||||
NoProject: len(projectIDs) == 0,
|
NoProject: len(projectIDs) == 0,
|
||||||
PosterID: issue.PosterID,
|
PosterID: issue.PosterID,
|
||||||
AssigneeID: issue.AssigneeID,
|
AssigneeIDs: assigneeIDs,
|
||||||
|
NoAssignee: len(assigneeIDs) == 0,
|
||||||
MentionIDs: mentionIDs,
|
MentionIDs: mentionIDs,
|
||||||
ReviewedIDs: reviewedIDs,
|
ReviewedIDs: reviewedIDs,
|
||||||
ReviewRequestedIDs: reviewRequestedIDs,
|
ReviewRequestedIDs: reviewRequestedIDs,
|
||||||
|
|||||||
Reference in New Issue
Block a user