Change the code search to sort results by relevance (#32134)

Resolves #32129

Signed-off-by: Bruno Sofiato <bruno.sofiato@gmail.com>
This commit is contained in:
Bruno Sofiato 2024-09-28 17:13:55 -03:00 committed by GitHub
parent ad749fbf25
commit 99d0510cb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View File

@ -284,6 +284,8 @@ func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int
searchRequest.AddFacet("languages", bleve.NewFacetRequest("Language", 10)) searchRequest.AddFacet("languages", bleve.NewFacetRequest("Language", 10))
} }
searchRequest.SortBy([]string{"-_score", "UpdatedAt"})
result, err := b.inner.Indexer.SearchInContext(ctx, searchRequest) result, err := b.inner.Indexer.SearchInContext(ctx, searchRequest)
if err != nil { if err != nil {
return 0, nil, nil, err return 0, nil, nil, err

View File

@ -318,7 +318,8 @@ func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int
NumOfFragments(0). // return all highting content on fragments NumOfFragments(0). // return all highting content on fragments
HighlighterType("fvh"), HighlighterType("fvh"),
). ).
Sort("repo_id", true). Sort("_score", false).
Sort("updated_at", true).
From(start).Size(pageSize). From(start).Size(pageSize).
Do(ctx) Do(ctx)
if err != nil { if err != nil {
@ -349,7 +350,8 @@ func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int
NumOfFragments(0). // return all highting content on fragments NumOfFragments(0). // return all highting content on fragments
HighlighterType("fvh"), HighlighterType("fvh"),
). ).
Sort("repo_id", true). Sort("_score", false).
Sort("updated_at", true).
From(start).Size(pageSize). From(start).Size(pageSize).
Do(ctx) Do(ctx)
if err != nil { if err != nil {