Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow searching by Issue Index #19646

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion modules/indexer/issues/bleve.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
const (
issueIndexerAnalyzer = "issueIndexer"
issueIndexerDocType = "issueIndexerDocType"
issueIndexerLatestVersion = 1
issueIndexerLatestVersion = 2
)

// indexerID a bleve-compatible unique identifier for an integer id
Expand Down Expand Up @@ -128,6 +128,7 @@ func createIssueIndexer(path string, latestVersion int) (bleve.Index, error) {
docMapping.AddFieldMappingsAt("Title", textFieldMapping)
docMapping.AddFieldMappingsAt("Content", textFieldMapping)
docMapping.AddFieldMappingsAt("Comments", textFieldMapping)
docMapping.AddFieldMappingsAt("Index", numericFieldMapping)

if err := addUnicodeNormalizeTokenFilter(mapping); err != nil {
return nil, err
Expand Down Expand Up @@ -214,11 +215,13 @@ func (b *BleveIndexer) Index(issues []*IndexerData) error {
Title string
Content string
Comments []string
Index int64
}{
RepoID: issue.RepoID,
Title: issue.Title,
Content: issue.Content,
Comments: issue.Comments,
Index: issue.Index,
}); err != nil {
return err
}
Expand All @@ -244,6 +247,7 @@ func (b *BleveIndexer) Search(ctx context.Context, keyword string, repoIDs []int
for _, repoID := range repoIDs {
repoQueriesP = append(repoQueriesP, numericEqualityQuery(repoID, "RepoID"))
}
index, _ := strconv.ParseInt(keyword, 10, 64)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we need to check if index > 0 to decide to if we need search the field.

repoQueries := make([]query.Query, len(repoQueriesP))
for i, v := range repoQueriesP {
repoQueries[i] = query.Query(v)
Expand All @@ -252,6 +256,7 @@ func (b *BleveIndexer) Search(ctx context.Context, keyword string, repoIDs []int
indexerQuery := bleve.NewConjunctionQuery(
bleve.NewDisjunctionQuery(repoQueries...),
bleve.NewDisjunctionQuery(
numericEqualityQuery(index, "Index"),
newMatchPhraseQuery(keyword, "Title", issueIndexerAnalyzer),
newMatchPhraseQuery(keyword, "Content", issueIndexerAnalyzer),
newMatchPhraseQuery(keyword, "Comments", issueIndexerAnalyzer),
Expand Down
6 changes: 6 additions & 0 deletions modules/indexer/issues/bleve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestBleveIndexAndSearch(t *testing.T) {
"test1",
"test2",
},
Index: 1,
},
{
ID: 2,
Expand All @@ -50,6 +51,7 @@ func TestBleveIndexAndSearch(t *testing.T) {
"LGTM",
"Good idea",
},
Index: 14,
},
})
assert.NoError(t, err)
Expand Down Expand Up @@ -82,6 +84,10 @@ func TestBleveIndexAndSearch(t *testing.T) {
Keyword: "help",
IDs: []int64{},
},
{
Keyword: "14",
IDs: []int64{2},
},
}

for _, kw := range keywords {
Expand Down
8 changes: 7 additions & 1 deletion modules/indexer/issues/elastic_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ const (
"type" : "text",
"index": true
}
"index": {
"type": "integer",
"index": true
},
}
}
}`
Expand Down Expand Up @@ -168,6 +172,7 @@ func (b *ElasticSearchIndexer) Index(issues []*IndexerData) error {
"title": issue.Title,
"content": issue.Content,
"comments": issue.Comments,
"index": issue.Index,
}).
Do(graceful.GetManager().HammerContext())
return b.checkError(err)
Expand All @@ -185,6 +190,7 @@ func (b *ElasticSearchIndexer) Index(issues []*IndexerData) error {
"title": issue.Title,
"content": issue.Content,
"comments": issue.Comments,
"index": issue.Index,
}),
)
}
Expand Down Expand Up @@ -227,7 +233,7 @@ func (b *ElasticSearchIndexer) Delete(ids ...int64) error {
// Search searches for issues by given conditions.
// Returns the matching issue IDs
func (b *ElasticSearchIndexer) Search(ctx context.Context, keyword string, repoIDs []int64, limit, start int) (*SearchResult, error) {
kwQuery := elastic.NewMultiMatchQuery(keyword, "title", "content", "comments")
kwQuery := elastic.NewMultiMatchQuery(keyword, "title", "content", "comments", "index")
query := elastic.NewBoolQuery()
query = query.Must(kwQuery)
if len(repoIDs) > 0 {
Expand Down
2 changes: 2 additions & 0 deletions modules/indexer/issues/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type IndexerData struct {
Comments []string `json:"comments"`
IsDelete bool `json:"is_delete"`
IDs []int64 `json:"ids"`
Index int64 `json:"index"`
}

// Match represents on search result
Expand Down Expand Up @@ -352,6 +353,7 @@ func UpdateIssueIndexer(issue *models.Issue) {
Title: issue.Title,
Content: issue.Content,
Comments: comments,
Index: issue.Index,
}
log.Debug("Adding to channel: %v", indexerData)
if err := issueIndexerQueue.Push(indexerData); err != nil {
Expand Down