Repository: go-gitea/gitea
File: modules/indexer/issues/elasticsearch/elasticsearch.go (Go)

Code before:
	}

	if options.NoLabelOnly {
		query.Must(elastic.NewTermQuery("no_label", true))
	} else {
		if len(options.IncludedLabelIDs) > 0 {
			q := elastic.NewBoolQuery()
			for _, labelID := range options.IncludedLabelIDs {
				q.Must(elastic.NewTermQuery("label_ids", labelID))
			}
			query.Must(q)
		} else if len(options.IncludedAnyLabelIDs) > 0 {
			query.Must(elastic.NewTermsQuery("label_ids", toAnySlice(options.IncludedAnyLabelIDs)...))
		}
		if len(options.ExcludedLabelIDs) > 0 {
			q := elastic.NewBoolQuery()
			for _, labelID := range options.ExcludedLabelIDs {
				q.MustNot(elastic.NewTermQuery("label_ids", labelID))
			}
			query.Must(q)
		}
	}

	if len(options.IssueIDs) > 0 {
		query.Must(elastic.NewTermsQuery("id", toAnySlice(options.IssueIDs)...))
	}

	if len(options.MilestoneIDs) > 0 {
		query.Must(elastic.NewTermsQuery("milestone_id", toAnySlice(options.MilestoneIDs)...))
	}

	if options.ProjectID.Has() {
		query.Must(elastic.NewTermQuery("project_id", options.ProjectID.Value()))
	}
	if options.ProjectColumnID.Has() {
		query.Must(elastic.NewTermQuery("project_board_id", options.ProjectColumnID.Value()))
	}

	if options.PosterID != "" {
		// "(none)" becomes 0, it means no poster
		posterIDInt64, _ := strconv.ParseInt(options.PosterID, 10, 64)
		query.Must(elastic.NewTermQuery("poster_id", posterIDInt64))
	}

	if options.AssigneeID != "" {
		if options.AssigneeID == "(any)" {
			q := elastic.NewRangeQuery("assignee_id")
			q.Gte(1)
			query.Must(q)
		} else {
			// "(none)" becomes 0, it means no assignee

Review comment (bug):
~~At least for ES it will fail on a Gitea instance with more than 1000 issues.~~

<details>

![image](https://github.com/user-attachments/assets/c5f6aedd-e237-4d33-b1b2-640dad9c55f0)

</details>

Hmmm, maybe another limit "terms query"(65535):

<details>

![image](https://github.com/user-attachments/assets/b0976dbe-8771-4498-b576-e4bd7ecab7c4)

</details>

Code after:

	if options.NoLabelOnly {
		query.Must(elastic.NewTermQuery("no_label", true))
	} else {
		if len(options.IncludedLabelIDs) > 0 {
			q := elastic.NewBoolQuery()
			for _, labelID := range options.IncludedLabelIDs {
				q.Must(elastic.NewTermQuery("label_ids", labelID))
			}
			query.Must(q)
		} else if len(options.IncludedAnyLabelIDs) > 0 {
			query.Must(elastic.NewTermsQuery("label_ids", toAnySlice(options.IncludedAnyLabelIDs)...))
		}
		if len(options.ExcludedLabelIDs) > 0 {
			q := elastic.NewBoolQuery()
			for _, labelID := range options.ExcludedLabelIDs {
				q.MustNot(elastic.NewTermQuery("label_ids", labelID))
			}
			query.Must(q)
		}
	}

	if len(options.MilestoneIDs) > 0 {
		query.Must(elastic.NewTermsQuery("milestone_id", toAnySlice(options.MilestoneIDs)...))
	}

	if options.ProjectID.Has() {
		query.Must(elastic.NewTermQuery("project_id", options.ProjectID.Value()))
	}
	if options.ProjectColumnID.Has() {
		query.Must(elastic.NewTermQuery("project_board_id", options.ProjectColumnID.Value()))
	}

	if options.PosterID != "" {
		// "(none)" becomes 0, it means no poster
		posterIDInt64, _ := strconv.ParseInt(options.PosterID, 10, 64)
		query.Must(elastic.NewTermQuery("poster_id", posterIDInt64))
	}

	if options.AssigneeID != "" {
		if options.AssigneeID == "(any)" {
			q := elastic.NewRangeQuery("assignee_id")
			q.Gte(1)
			query.Must(q)
		} else {
			// "(none)" becomes 0, it means no assignee
			assigneeIDInt64, _ := strconv.ParseInt(options.AssigneeID, 10, 64)
			query.Must(elastic.NewTermQuery("assignee_id", assigneeIDInt64))
		}
	}