From 99d0510cb69c3c53cee05ef0e83ed02389925a90 Mon Sep 17 00:00:00 2001 From: Bruno Sofiato Date: Sat, 28 Sep 2024 17:13:55 -0300 Subject: [PATCH] Change the code search to sort results by relevance (#32134) Resolves #32129 Signed-off-by: Bruno Sofiato --- modules/indexer/code/bleve/bleve.go | 2 ++ modules/indexer/code/elasticsearch/elasticsearch.go | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/indexer/code/bleve/bleve.go b/modules/indexer/code/bleve/bleve.go index 542bdfb501..c17f56d3cf 100644 --- a/modules/indexer/code/bleve/bleve.go +++ b/modules/indexer/code/bleve/bleve.go @@ -284,6 +284,8 @@ func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int searchRequest.AddFacet("languages", bleve.NewFacetRequest("Language", 10)) } + searchRequest.SortBy([]string{"-_score", "UpdatedAt"}) + result, err := b.inner.Indexer.SearchInContext(ctx, searchRequest) if err != nil { return 0, nil, nil, err diff --git a/modules/indexer/code/elasticsearch/elasticsearch.go b/modules/indexer/code/elasticsearch/elasticsearch.go index 0bda180fac..d64d99433d 100644 --- a/modules/indexer/code/elasticsearch/elasticsearch.go +++ b/modules/indexer/code/elasticsearch/elasticsearch.go @@ -318,7 +318,8 @@ func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int NumOfFragments(0). // return all highting content on fragments HighlighterType("fvh"), ). - Sort("repo_id", true). + Sort("_score", false). + Sort("updated_at", true). From(start).Size(pageSize). Do(ctx) 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 HighlighterType("fvh"), ). - Sort("repo_id", true). + Sort("_score", false). + Sort("updated_at", true). From(start).Size(pageSize). Do(ctx) if err != nil {