aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authortechknowlogick <techknowlogick@gitea.io>2023-07-07 13:10:13 -0400
committerGitHub <noreply@github.com>2023-07-07 17:10:13 +0000
commitcb01b8691db6ff13db3331dbe90ea291e1d6eadd (patch)
tree2702a23613951866fc9438ef3052ddf22e8b2bdf /modules
parent7586b5815ac503d6d3d0f37248da0c9cefd08ba5 (diff)
downloadgitea-cb01b8691db6ff13db3331dbe90ea291e1d6eadd.tar.gz
gitea-cb01b8691db6ff13db3331dbe90ea291e1d6eadd.zip
Add open/closed field support for issue index (#25708)
A couple of notes: * Future changes should refactor arguments into a struct * This filtering only is supported by meilisearch right now * Issue index number is bumped which will cause a re-index
Diffstat (limited to 'modules')
-rw-r--r--modules/indexer/issues/bleve/bleve.go2
-rw-r--r--modules/indexer/issues/bleve/bleve_test.go2
-rw-r--r--modules/indexer/issues/db/db.go2
-rw-r--r--modules/indexer/issues/elasticsearch/elasticsearch.go2
-rw-r--r--modules/indexer/issues/indexer.go20
-rw-r--r--modules/indexer/issues/indexer_test.go16
-rw-r--r--modules/indexer/issues/internal/indexer.go4
-rw-r--r--modules/indexer/issues/internal/model.go16
-rw-r--r--modules/indexer/issues/meilisearch/meilisearch.go11
9 files changed, 45 insertions, 30 deletions
diff --git a/modules/indexer/issues/bleve/bleve.go b/modules/indexer/issues/bleve/bleve.go
index 4cc58acac7..c368a67ab5 100644
--- a/modules/indexer/issues/bleve/bleve.go
+++ b/modules/indexer/issues/bleve/bleve.go
@@ -138,7 +138,7 @@ func (b *Indexer) Delete(_ context.Context, ids ...int64) error {
// Search searches for issues by given conditions.
// Returns the matching issue IDs
-func (b *Indexer) Search(ctx context.Context, keyword string, repoIDs []int64, limit, start int) (*internal.SearchResult, error) {
+func (b *Indexer) Search(ctx context.Context, keyword string, repoIDs []int64, limit, start int, state string) (*internal.SearchResult, error) {
var repoQueriesP []*query.NumericRangeQuery
for _, repoID := range repoIDs {
repoQueriesP = append(repoQueriesP, numericEqualityQuery(repoID, "repo_id"))
diff --git a/modules/indexer/issues/bleve/bleve_test.go b/modules/indexer/issues/bleve/bleve_test.go
index f890f8eb48..0eb136d22b 100644
--- a/modules/indexer/issues/bleve/bleve_test.go
+++ b/modules/indexer/issues/bleve/bleve_test.go
@@ -77,7 +77,7 @@ func TestBleveIndexAndSearch(t *testing.T) {
}
for _, kw := range keywords {
- res, err := indexer.Search(context.TODO(), kw.Keyword, []int64{2}, 10, 0)
+ res, err := indexer.Search(context.TODO(), kw.Keyword, []int64{2}, 10, 0, "")
assert.NoError(t, err)
ids := make([]int64, 0, len(res.Hits))
diff --git a/modules/indexer/issues/db/db.go b/modules/indexer/issues/db/db.go
index 17ed426b38..b054b9d800 100644
--- a/modules/indexer/issues/db/db.go
+++ b/modules/indexer/issues/db/db.go
@@ -36,7 +36,7 @@ func (i *Indexer) Delete(_ context.Context, _ ...int64) error {
}
// Search searches for issues
-func (i *Indexer) Search(ctx context.Context, kw string, repoIDs []int64, limit, start int) (*internal.SearchResult, error) {
+func (i *Indexer) Search(ctx context.Context, kw string, repoIDs []int64, limit, start int, state string) (*internal.SearchResult, error) {
total, ids, err := issues_model.SearchIssueIDsByKeyword(ctx, kw, repoIDs, limit, start)
if err != nil {
return nil, err
diff --git a/modules/indexer/issues/elasticsearch/elasticsearch.go b/modules/indexer/issues/elasticsearch/elasticsearch.go
index 62889ea578..cfd3628c18 100644
--- a/modules/indexer/issues/elasticsearch/elasticsearch.go
+++ b/modules/indexer/issues/elasticsearch/elasticsearch.go
@@ -140,7 +140,7 @@ func (b *Indexer) Delete(ctx context.Context, ids ...int64) error {
// Search searches for issues by given conditions.
// Returns the matching issue IDs
-func (b *Indexer) Search(ctx context.Context, keyword string, repoIDs []int64, limit, start int) (*internal.SearchResult, error) {
+func (b *Indexer) Search(ctx context.Context, keyword string, repoIDs []int64, limit, start int, state string) (*internal.SearchResult, error) {
kwQuery := elastic.NewMultiMatchQuery(keyword, "title", "content", "comments")
query := elastic.NewBoolQuery()
query = query.Must(kwQuery)
diff --git a/modules/indexer/issues/indexer.go b/modules/indexer/issues/indexer.go
index 9e2f13371e..fe5c5d8f26 100644
--- a/modules/indexer/issues/indexer.go
+++ b/modules/indexer/issues/indexer.go
@@ -242,12 +242,18 @@ func UpdateIssueIndexer(issue *issues_model.Issue) {
comments = append(comments, comment.Content)
}
}
+ issueType := "issue"
+ if issue.IsPull {
+ issueType = "pull"
+ }
indexerData := &internal.IndexerData{
- ID: issue.ID,
- RepoID: issue.RepoID,
- Title: issue.Title,
- Content: issue.Content,
- Comments: comments,
+ ID: issue.ID,
+ RepoID: issue.RepoID,
+ State: string(issue.State()),
+ IssueType: issueType,
+ Title: issue.Title,
+ Content: issue.Content,
+ Comments: comments,
}
log.Debug("Adding to channel: %v", indexerData)
if err := issueIndexerQueue.Push(indexerData); err != nil {
@@ -278,10 +284,10 @@ func DeleteRepoIssueIndexer(ctx context.Context, repo *repo_model.Repository) {
// SearchIssuesByKeyword search issue ids by keywords and repo id
// WARNNING: You have to ensure user have permission to visit repoIDs' issues
-func SearchIssuesByKeyword(ctx context.Context, repoIDs []int64, keyword string) ([]int64, error) {
+func SearchIssuesByKeyword(ctx context.Context, repoIDs []int64, keyword, state string) ([]int64, error) {
var issueIDs []int64
indexer := *globalIndexer.Load()
- res, err := indexer.Search(ctx, keyword, repoIDs, 50, 0)
+ res, err := indexer.Search(ctx, keyword, repoIDs, 50, 0, state)
if err != nil {
return nil, err
}
diff --git a/modules/indexer/issues/indexer_test.go b/modules/indexer/issues/indexer_test.go
index 5962a4ee9c..757eb2f3d9 100644
--- a/modules/indexer/issues/indexer_test.go
+++ b/modules/indexer/issues/indexer_test.go
@@ -50,19 +50,19 @@ func TestBleveSearchIssues(t *testing.T) {
time.Sleep(5 * time.Second)
- ids, err := SearchIssuesByKeyword(context.TODO(), []int64{1}, "issue2")
+ ids, err := SearchIssuesByKeyword(context.TODO(), []int64{1}, "issue2", "")
assert.NoError(t, err)
assert.EqualValues(t, []int64{2}, ids)
- ids, err = SearchIssuesByKeyword(context.TODO(), []int64{1}, "first")
+ ids, err = SearchIssuesByKeyword(context.TODO(), []int64{1}, "first", "")
assert.NoError(t, err)
assert.EqualValues(t, []int64{1}, ids)
- ids, err = SearchIssuesByKeyword(context.TODO(), []int64{1}, "for")
+ ids, err = SearchIssuesByKeyword(context.TODO(), []int64{1}, "for", "")
assert.NoError(t, err)
assert.ElementsMatch(t, []int64{1, 2, 3, 5, 11}, ids)
- ids, err = SearchIssuesByKeyword(context.TODO(), []int64{1}, "good")
+ ids, err = SearchIssuesByKeyword(context.TODO(), []int64{1}, "good", "")
assert.NoError(t, err)
assert.EqualValues(t, []int64{1}, ids)
}
@@ -73,19 +73,19 @@ func TestDBSearchIssues(t *testing.T) {
setting.Indexer.IssueType = "db"
InitIssueIndexer(true)
- ids, err := SearchIssuesByKeyword(context.TODO(), []int64{1}, "issue2")
+ ids, err := SearchIssuesByKeyword(context.TODO(), []int64{1}, "issue2", "")
assert.NoError(t, err)
assert.EqualValues(t, []int64{2}, ids)
- ids, err = SearchIssuesByKeyword(context.TODO(), []int64{1}, "first")
+ ids, err = SearchIssuesByKeyword(context.TODO(), []int64{1}, "first", "")
assert.NoError(t, err)
assert.EqualValues(t, []int64{1}, ids)
- ids, err = SearchIssuesByKeyword(context.TODO(), []int64{1}, "for")
+ ids, err = SearchIssuesByKeyword(context.TODO(), []int64{1}, "for", "")
assert.NoError(t, err)
assert.ElementsMatch(t, []int64{1, 2, 3, 5, 11}, ids)
- ids, err = SearchIssuesByKeyword(context.TODO(), []int64{1}, "good")
+ ids, err = SearchIssuesByKeyword(context.TODO(), []int64{1}, "good", "")
assert.NoError(t, err)
assert.EqualValues(t, []int64{1}, ids)
}
diff --git a/modules/indexer/issues/internal/indexer.go b/modules/indexer/issues/internal/indexer.go
index 553c8a573c..b96517bb80 100644
--- a/modules/indexer/issues/internal/indexer.go
+++ b/modules/indexer/issues/internal/indexer.go
@@ -15,7 +15,7 @@ type Indexer interface {
internal.Indexer
Index(ctx context.Context, issue []*IndexerData) error
Delete(ctx context.Context, ids ...int64) error
- Search(ctx context.Context, kw string, repoIDs []int64, limit, start int) (*SearchResult, error)
+ Search(ctx context.Context, kw string, repoIDs []int64, limit, start int, state string) (*SearchResult, error)
}
// NewDummyIndexer returns a dummy indexer
@@ -37,6 +37,6 @@ func (d *dummyIndexer) Delete(ctx context.Context, ids ...int64) error {
return fmt.Errorf("indexer is not ready")
}
-func (d *dummyIndexer) Search(ctx context.Context, kw string, repoIDs []int64, limit, start int) (*SearchResult, error) {
+func (d *dummyIndexer) Search(ctx context.Context, kw string, repoIDs []int64, limit, start int, state string) (*SearchResult, error) {
return nil, fmt.Errorf("indexer is not ready")
}
diff --git a/modules/indexer/issues/internal/model.go b/modules/indexer/issues/internal/model.go
index 8c206fc1cf..2b52d32302 100644
--- a/modules/indexer/issues/internal/model.go
+++ b/modules/indexer/issues/internal/model.go
@@ -5,13 +5,15 @@ package internal
// IndexerData data stored in the issue indexer
type IndexerData struct {
- ID int64 `json:"id"`
- RepoID int64 `json:"repo_id"`
- Title string `json:"title"`
- Content string `json:"content"`
- Comments []string `json:"comments"`
- IsDelete bool `json:"is_delete"`
- IDs []int64 `json:"ids"`
+ ID int64 `json:"id"`
+ RepoID int64 `json:"repo_id"`
+ State string `json:"state"` // open, closed, all
+ IssueType string `json:"type"` // issue or pull
+ Title string `json:"title"`
+ Content string `json:"content"`
+ Comments []string `json:"comments"`
+ IsDelete bool `json:"is_delete"`
+ IDs []int64 `json:"ids"`
}
// Match represents on search result
diff --git a/modules/indexer/issues/meilisearch/meilisearch.go b/modules/indexer/issues/meilisearch/meilisearch.go
index 2a46b1ab15..2ea06b576c 100644
--- a/modules/indexer/issues/meilisearch/meilisearch.go
+++ b/modules/indexer/issues/meilisearch/meilisearch.go
@@ -16,7 +16,7 @@ import (
)
const (
- issueIndexerLatestVersion = 0
+ issueIndexerLatestVersion = 1
)
var _ internal.Indexer = &Indexer{}
@@ -70,12 +70,19 @@ func (b *Indexer) Delete(_ context.Context, ids ...int64) error {
// Search searches for issues by given conditions.
// Returns the matching issue IDs
-func (b *Indexer) Search(ctx context.Context, keyword string, repoIDs []int64, limit, start int) (*internal.SearchResult, error) {
+func (b *Indexer) Search(ctx context.Context, keyword string, repoIDs []int64, limit, start int, state string) (*internal.SearchResult, error) {
repoFilters := make([]string, 0, len(repoIDs))
for _, repoID := range repoIDs {
repoFilters = append(repoFilters, "repo_id = "+strconv.FormatInt(repoID, 10))
}
filter := strings.Join(repoFilters, " OR ")
+ if state == "open" || state == "closed" {
+ if filter != "" {
+ filter = "(" + filter + ") AND state = " + state
+ } else {
+ filter = "state = " + state
+ }
+ }
searchRes, err := b.inner.Client.Index(b.inner.VersionedIndexName()).Search(keyword, &meilisearch.SearchRequest{
Filter: filter,
Limit: int64(limit),