Skip to content

Commit 95f5017

Browse files
author
lukas
committed
Allow searching by issue ID
Add issue ID to found issues if it is a string
1 parent 0a9fcf6 commit 95f5017

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

modules/indexer/issues/bleve.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
const (
2828
issueIndexerAnalyzer = "issueIndexer"
2929
issueIndexerDocType = "issueIndexerDocType"
30-
issueIndexerLatestVersion = 1
30+
issueIndexerLatestVersion = 2
3131
)
3232

3333
// indexerID a bleve-compatible unique identifier for an integer id
@@ -127,6 +127,7 @@ func createIssueIndexer(path string, latestVersion int) (bleve.Index, error) {
127127
docMapping.AddFieldMappingsAt("Title", textFieldMapping)
128128
docMapping.AddFieldMappingsAt("Content", textFieldMapping)
129129
docMapping.AddFieldMappingsAt("Comments", textFieldMapping)
130+
docMapping.AddFieldMappingsAt("Index", numericFieldMapping)
130131

131132
if err := addUnicodeNormalizeTokenFilter(mapping); err != nil {
132133
return nil, err
@@ -206,11 +207,13 @@ func (b *BleveIndexer) Index(issues []*IndexerData) error {
206207
Title string
207208
Content string
208209
Comments []string
210+
Index int64
209211
}{
210212
RepoID: issue.RepoID,
211213
Title: issue.Title,
212214
Content: issue.Content,
213215
Comments: issue.Comments,
216+
Index: issue.Index,
214217
}); err != nil {
215218
return err
216219
}
@@ -236,6 +239,7 @@ func (b *BleveIndexer) Search(keyword string, repoIDs []int64, limit, start int)
236239
for _, repoID := range repoIDs {
237240
repoQueriesP = append(repoQueriesP, numericEqualityQuery(repoID, "RepoID"))
238241
}
242+
index, _ := strconv.ParseInt(keyword, 10, 64)
239243
repoQueries := make([]query.Query, len(repoQueriesP))
240244
for i, v := range repoQueriesP {
241245
repoQueries[i] = query.Query(v)
@@ -244,6 +248,7 @@ func (b *BleveIndexer) Search(keyword string, repoIDs []int64, limit, start int)
244248
indexerQuery := bleve.NewConjunctionQuery(
245249
bleve.NewDisjunctionQuery(repoQueries...),
246250
bleve.NewDisjunctionQuery(
251+
numericEqualityQuery(index, "Index"),
247252
newMatchPhraseQuery(keyword, "Title", issueIndexerAnalyzer),
248253
newMatchPhraseQuery(keyword, "Content", issueIndexerAnalyzer),
249254
newMatchPhraseQuery(keyword, "Comments", issueIndexerAnalyzer),

modules/indexer/issues/bleve_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func TestBleveIndexAndSearch(t *testing.T) {
3939
"test1",
4040
"test2",
4141
},
42+
Index: 1,
4243
},
4344
{
4445
ID: 2,
@@ -49,6 +50,7 @@ func TestBleveIndexAndSearch(t *testing.T) {
4950
"LGTM",
5051
"Good idea",
5152
},
53+
Index: 14,
5254
},
5355
})
5456
assert.NoError(t, err)
@@ -82,6 +84,10 @@ func TestBleveIndexAndSearch(t *testing.T) {
8284
Keyword: "help",
8385
IDs: []int64{},
8486
},
87+
{
88+
Keyword: "14",
89+
IDs: []int64{2},
90+
},
8591
}
8692
)
8793

modules/indexer/issues/elastic_search.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ const (
8888
"type" : "text",
8989
"index": true
9090
}
91+
"index": {
92+
"type": "integer",
93+
"index": true
94+
},
9195
}
9296
}
9397
}`
@@ -132,6 +136,7 @@ func (b *ElasticSearchIndexer) Index(issues []*IndexerData) error {
132136
"title": issue.Title,
133137
"content": issue.Content,
134138
"comments": issue.Comments,
139+
"index": issue.Index,
135140
}).
136141
Do(context.Background())
137142
return err
@@ -149,6 +154,7 @@ func (b *ElasticSearchIndexer) Index(issues []*IndexerData) error {
149154
"title": issue.Title,
150155
"content": issue.Content,
151156
"comments": issue.Comments,
157+
"index": issue.Index,
152158
}),
153159
)
154160
}
@@ -191,7 +197,7 @@ func (b *ElasticSearchIndexer) Delete(ids ...int64) error {
191197
// Search searches for issues by given conditions.
192198
// Returns the matching issue IDs
193199
func (b *ElasticSearchIndexer) Search(keyword string, repoIDs []int64, limit, start int) (*SearchResult, error) {
194-
kwQuery := elastic.NewMultiMatchQuery(keyword, "title", "content", "comments")
200+
kwQuery := elastic.NewMultiMatchQuery(keyword, "title", "content", "comments", "index")
195201
query := elastic.NewBoolQuery()
196202
query = query.Must(kwQuery)
197203
if len(repoIDs) > 0 {

modules/indexer/issues/indexer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type IndexerData struct {
3030
Comments []string `json:"comments"`
3131
IsDelete bool `json:"is_delete"`
3232
IDs []int64 `json:"ids"`
33+
Index int64 `json:"index"`
3334
}
3435

3536
// Match represents on search result
@@ -303,6 +304,7 @@ func UpdateIssueIndexer(issue *models.Issue) {
303304
Title: issue.Title,
304305
Content: issue.Content,
305306
Comments: comments,
307+
Index: issue.Index,
306308
}
307309
log.Debug("Adding to channel: %v", indexerData)
308310
if err := issueIndexerQueue.Push(indexerData); err != nil {

0 commit comments

Comments
 (0)