Skip to content

Commit 99d0510

Browse files
authored
Change the code search to sort results by relevance (#32134)
Resolves #32129 Signed-off-by: Bruno Sofiato <[email protected]>
1 parent ad749fb commit 99d0510

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

modules/indexer/code/bleve/bleve.go

+2
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int
284284
searchRequest.AddFacet("languages", bleve.NewFacetRequest("Language", 10))
285285
}
286286

287+
searchRequest.SortBy([]string{"-_score", "UpdatedAt"})
288+
287289
result, err := b.inner.Indexer.SearchInContext(ctx, searchRequest)
288290
if err != nil {
289291
return 0, nil, nil, err

modules/indexer/code/elasticsearch/elasticsearch.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int
318318
NumOfFragments(0). // return all highting content on fragments
319319
HighlighterType("fvh"),
320320
).
321-
Sort("repo_id", true).
321+
Sort("_score", false).
322+
Sort("updated_at", true).
322323
From(start).Size(pageSize).
323324
Do(ctx)
324325
if err != nil {
@@ -349,7 +350,8 @@ func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int
349350
NumOfFragments(0). // return all highting content on fragments
350351
HighlighterType("fvh"),
351352
).
352-
Sort("repo_id", true).
353+
Sort("_score", false).
354+
Sort("updated_at", true).
353355
From(start).Size(pageSize).
354356
Do(ctx)
355357
if err != nil {

0 commit comments

Comments
 (0)