aboutsummaryrefslogtreecommitdiffstats
path: root/modules/indexer
diff options
context:
space:
mode:
authorBruno Sofiato <bruno.sofiato@gmail.com>2024-09-28 17:13:55 -0300
committerGitHub <noreply@github.com>2024-09-28 20:13:55 +0000
commit99d0510cb69c3c53cee05ef0e83ed02389925a90 (patch)
treecea31f20ee9d8e34cf579c6dd34fc76030b0c43a /modules/indexer
parentad749fbf259fe66e11359e78e859ee305cc59465 (diff)
downloadgitea-99d0510cb69c3c53cee05ef0e83ed02389925a90.tar.gz
gitea-99d0510cb69c3c53cee05ef0e83ed02389925a90.zip
Change the code search to sort results by relevance (#32134)
Resolves #32129 Signed-off-by: Bruno Sofiato <bruno.sofiato@gmail.com>
Diffstat (limited to 'modules/indexer')
-rw-r--r--modules/indexer/code/bleve/bleve.go2
-rw-r--r--modules/indexer/code/elasticsearch/elasticsearch.go6
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 {