diff options
author | Lauris BH <lauris@nix.lv> | 2021-01-16 06:55:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-16 12:55:17 +0800 |
commit | 0a3c3357f388cc60d5f43a056ee2381e51586cff (patch) | |
tree | aff5abc553a1f417c943802c0f2e7d21aab8305f | |
parent | 2db4733c7d75b3ca3d1b2750f7b6ed53ac75303c (diff) | |
download | gitea-0a3c3357f388cc60d5f43a056ee2381e51586cff.tar.gz gitea-0a3c3357f388cc60d5f43a056ee2381e51586cff.zip |
Sort issue search results by revelance (#14353)
-rw-r--r-- | models/issue.go | 2 | ||||
-rw-r--r-- | models/issue_test.go | 2 | ||||
-rw-r--r-- | modules/indexer/issues/bleve.go | 1 | ||||
-rw-r--r-- | modules/indexer/issues/elastic_search.go | 2 | ||||
-rw-r--r-- | modules/indexer/issues/indexer_test.go | 4 |
5 files changed, 6 insertions, 5 deletions
diff --git a/models/issue.go b/models/issue.go index b517f334c4..7731a59ed0 100644 --- a/models/issue.go +++ b/models/issue.go @@ -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 } diff --git a/models/issue_test.go b/models/issue_test.go index 1f65cb433a..8fbc49a46d 100644 --- a/models/issue_test.go +++ b/models/issue_test.go @@ -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) diff --git a/modules/indexer/issues/bleve.go b/modules/indexer/issues/bleve.go index a1f51dba50..4a1e2bc51b 100644 --- a/modules/indexer/issues/bleve.go +++ b/modules/indexer/issues/bleve.go @@ -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 { diff --git a/modules/indexer/issues/elastic_search.go b/modules/indexer/issues/elastic_search.go index 4cdeff53dc..3af64ed30e 100644 --- a/modules/indexer/issues/elastic_search.go +++ b/modules/indexer/issues/elastic_search.go @@ -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 { diff --git a/modules/indexer/issues/indexer_test.go b/modules/indexer/issues/indexer_test.go index 95007d8faf..8c163f78d1 100644 --- a/modules/indexer/issues/indexer_test.go +++ b/modules/indexer/issues/indexer_test.go @@ -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) @@ -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) |