Commit e57b5ef5 authored by Stan Hu's avatar Stan Hu

Merge branch '228575-sort-by-relevance-not-updated-at' into 'master'

Always sort Elasticsearch searches by relevance not updated_at

See merge request gitlab-org/gitlab!36774
parents 40caa9d0 e2685352
---
title: Always sort Elasticsearch searches by relevance not updated_at
merge_request: 36774
author:
type: fixed
......@@ -71,11 +71,6 @@ module Elastic
}
end
query_hash[:sort] = [
{ updated_at: { order: :desc } },
:_score
]
query_hash[:highlight] = highlight_options(fields)
query_hash
......
......@@ -92,8 +92,6 @@ module Elastic
options[:order] = :default if options[:order].blank?
query_hash[:sort] = [:_score]
res = search(query_hash, options)
{
results: res.results,
......@@ -154,8 +152,6 @@ module Elastic
options[:order] = :default if options[:order].blank?
query_hash[:sort] = [:_score]
if options[:highlight]
query_hash[:highlight] = {
pre_tags: ["gitlabelasticsearch→"],
......
......@@ -16,11 +16,6 @@ module Elastic
query_hash = project_ids_filter(query_hash, options)
query_hash = confidentiality_filter(query_hash, options[:current_user])
query_hash[:sort] = [
{ updated_at: { order: :desc } },
:_score
]
query_hash[:highlight] = highlight_options(options[:in])
search(query_hash, options)
......
......@@ -42,8 +42,6 @@ module Elastic
query_hash[:query][:bool][:filter] = filters
query_hash[:sort] = [:_score]
search(query_hash, options)
end
end
......
......@@ -22,8 +22,11 @@ RSpec.describe Gitlab::Elastic::SnippetSearchResults, :elastic, :sidekiq_might_n
end
it 'returns the correct page of results' do
expect(results.objects('snippet_titles', page: 1, per_page: 1)).to eq([snippet2])
expect(results.objects('snippet_titles', page: 2, per_page: 1)).to eq([snippet])
# `snippet` is more relevant than `snippet2` (hence first in order) due
# to having a shorter title that exactly matches the query and also due
# to having a description that matches the query.
expect(results.objects('snippet_titles', page: 1, per_page: 1)).to eq([snippet])
expect(results.objects('snippet_titles', page: 2, per_page: 1)).to eq([snippet2])
end
it 'returns the correct number of results for one page' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment