mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-30 07:16:19 +01:00
Sort issue search results by revelance (#14353)
This commit is contained in:
parent
2db4733c7d
commit
0a3c3357f3
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user