]> source.dussan.org Git - gitea.git/commitdiff
Change the code search to sort results by relevance (#32134)
authorBruno Sofiato <bruno.sofiato@gmail.com>
Sat, 28 Sep 2024 20:13:55 +0000 (17:13 -0300)
committerGitHub <noreply@github.com>
Sat, 28 Sep 2024 20:13:55 +0000 (20:13 +0000)
Resolves #32129

Signed-off-by: Bruno Sofiato <bruno.sofiato@gmail.com>
modules/indexer/code/bleve/bleve.go
modules/indexer/code/elasticsearch/elasticsearch.go

index 542bdfb50141ab2d194a105cb7854d92e60f47c4..c17f56d3cff5ab4708362f5bacedb60bd118b7a0 100644 (file)
@@ -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
index 0bda180fac9ce8267ebc4350107dedf9e50a00aa..d64d99433d989685fba2777845107e272611bb0d 100644 (file)
@@ -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 {