Skip to content

Commit

Permalink
Sort issue search results by revelance (#14353)
Browse files Browse the repository at this point in the history
  • Loading branch information
lafriks authored Jan 16, 2021
1 parent 2db4733 commit 0a3c335
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,7 @@ func SearchIssueIDsByKeyword(kw string, repoIDs []int64, limit, start int) (int6
)

var ids = make([]int64, 0, limit)
err := x.Distinct("id").Table("issue").Where(cond).Limit(limit, start).Find(&ids)
err := x.Distinct("id").Table("issue").Where(cond).OrderBy("`updated_unix` DESC").Limit(limit, start).Find(&ids)
if err != nil {
return 0, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion models/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func TestIssue_SearchIssueIDsByKeyword(t *testing.T) {
total, ids, err = SearchIssueIDsByKeyword("for", []int64{1}, 10, 0)
assert.NoError(t, err)
assert.EqualValues(t, 5, total)
assert.EqualValues(t, []int64{1, 2, 3, 5, 11}, ids)
assert.ElementsMatch(t, []int64{1, 2, 3, 5, 11}, ids)

// issue1's comment id 2
total, ids, err = SearchIssueIDsByKeyword("good", []int64{1}, 10, 0)
Expand Down
1 change: 1 addition & 0 deletions modules/indexer/issues/bleve.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ func (b *BleveIndexer) Search(keyword string, repoIDs []int64, limit, start int)
newMatchPhraseQuery(keyword, "Comments", issueIndexerAnalyzer),
))
search := bleve.NewSearchRequestOptions(indexerQuery, limit, start, false)
search.SortBy([]string{"-_score"})

result, err := b.indexer.Search(search)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion modules/indexer/issues/elastic_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (b *ElasticSearchIndexer) Search(keyword string, repoIDs []int64, limit, st
searchResult, err := b.client.Search().
Index(b.indexerName).
Query(query).
Sort("id", true).
Sort("_score", false).
From(start).Size(limit).
Do(context.Background())
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions modules/indexer/issues/indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestBleveSearchIssues(t *testing.T) {

ids, err = SearchIssuesByKeyword([]int64{1}, "for")
assert.NoError(t, err)
assert.EqualValues(t, []int64{1, 2, 3, 5, 11}, ids)
assert.ElementsMatch(t, []int64{1, 2, 3, 5, 11}, ids)

ids, err = SearchIssuesByKeyword([]int64{1}, "good")
assert.NoError(t, err)
Expand All @@ -89,7 +89,7 @@ func TestDBSearchIssues(t *testing.T) {

ids, err = SearchIssuesByKeyword([]int64{1}, "for")
assert.NoError(t, err)
assert.EqualValues(t, []int64{1, 2, 3, 5, 11}, ids)
assert.ElementsMatch(t, []int64{1, 2, 3, 5, 11}, ids)

ids, err = SearchIssuesByKeyword([]int64{1}, "good")
assert.NoError(t, err)
Expand Down

0 comments on commit 0a3c335

Please sign in to comment.